Description
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:
- 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");
});
});
}
- 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
- Specify the comment which should be used to launch the program
N/A
- 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):
- OS: Linux
- Target device and vendor: N/A
- DPC++ version: clang version 18.0.0 (https://github.com/intel/llvm 34a0635)
- Dependencies version: N/A
Additional context
Add any other context about the problem here.