clspv
clspv copied to clipboard
Function Definition calling another with const reference fails to compile
clspv.exe -cl-std=CLC++ -inline-entry-points -cl-kernel-arg-info
Note the function is not even called. Just defining it fails.
Fails: 'Invalid bitcast' ' %0 = bitcast ptr %ref.tmp1 to ptr addrspace(4)' 'LLVM ERROR: Broken module found, compilation aborted!'
Source:
struct XY
{
float x, y;
XY() {}
XY(const float& n) : x(n), y(n) {} // Fails
// XY(float n) : x(n), y(n) {} // OK, fixes below
};
XY One()
{
XY v; v = 1; // Fails
// XY v = 1; // OK
return v;
}
// OK:
// static
// XY One()
// {
// XY v; v = 1;
// return v;
// }
kernel
void BeamMeUp(global float* In, global float* Out, write_only image2d_t ImageOut)
{
XY v = 0; // OK
// v = 0; // Fails
}
This one fails to produce IR, but when avoiding the bug triggers, the IR is curiously large.
What IR did you look at?
The end IR is quite small (clspv source.cl -cl-std=CLC++ -inline-entry-points -cl-kernel-arg-info --show-producer-ir
)
I guess you have been looking at the one with --output-format=bc
, which is a non-optimized one just after the frontend. It is normal to have something large there.
Looking at the debugger it feels like it fails in llvm before really running clspv
passes, which lead me to think it is a bug in llvm
/clang
, not clspv
.
Above also Fails with an older Clspv from May 22, using LLVM 15, while my previous bug report compiles OK with that older Clspv.
It also compiles OK with Clang release 16, using:
clang -x cl -cl-std=CLC++ -S -emit-llvm
I do not have the latest Clang 17 ready, but my instinct is that it is quite unlikely that such basic language bug triggers would go unnoticed at the LLVM project.
Thank you for teaching me about the "--show-producer-ir" , it is not in the --help!
And thank you for your time!
basically if you compile with --output-format=bc
and it fails, it means that the issue is in llvm/clang as we did not do anything else than calling llvm/clang with this option.