Skip to content

__builtin_printf not diagnosed but results in invalid SPIR-V #11733

Closed
KhronosGroup/SPIRV-Tools
#5677
@hvdijk

Description

@hvdijk

Describe the bug

Kernels are not permitted to call printf (see issue #487). This gets diagnosed correctly for regular calls, but calls to __builtin_printf go undiagnosed and result in invalid SPIR-V.

To Reproduce
Please describe the steps to reproduce the behavior:

  1. Include code snippet as short as possible
#include <sycl/sycl.hpp>
int main() {
  sycl::queue queue;
  queue.submit([&](sycl::handler &cgh) {
    cgh.single_task([] {
      __builtin_printf("%s, %s!\n", "Hello", "world");
    });
  });
}
  1. Specify the command which should be used to compile the program
clang++ -save-temps -fsycl sycl.cc -o sycl
for f in $(cat sycl-sycl-spir64-unknown-unknown-*.txt); do spirv-val $f; done
  1. Specify the comment which should be used to launch the program

N/A

  1. Indicate what is wrong and what was expected

This program should have either been rejected by the frontend as it would have been if __builtin_printf had been avoided and printf had been used instead:

sycl.cc:6:43: error: SYCL kernel cannot call a variadic function
    6 |       printf("%s, %s!\n", "Hello", "world");
      |                                           ^

Instead, SPIR-V is generated that declares printf as a function taking only a format string, but nonetheless calls it with three arguments, resulting in

error: line 169: OpFunctionCall Function <id>'s parameter count does not match the argument count.
  %call_i = OpFunctionCall %uint %printf %47 %49 %50

The precise results of actually running it depend on the driver used, but generally, it just does not work and cannot be expected to work.

Environment (please complete the following information):

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions