clspv icon indicating copy to clipboard operation
clspv copied to clipboard

Function Definition calling another with const reference fails to compile

Open BukeBeyond opened this issue 1 year ago • 3 comments

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.

BukeBeyond avatar Jun 19 '23 20:06 BukeBeyond

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.

rjodinchr avatar Jun 20 '23 05:06 rjodinchr

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!

BukeBeyond avatar Jun 20 '23 17:06 BukeBeyond

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.

rjodinchr avatar Jun 20 '23 18:06 rjodinchr