Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function Definition calling another with const reference fails to compile #1138

Open
BukeBeyond opened this issue Jun 19, 2023 · 3 comments
Open

Comments

@BukeBeyond
Copy link

BukeBeyond commented Jun 19, 2023

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.

@rjodinchr
Copy link
Collaborator

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.

@BukeBeyond
Copy link
Author

BukeBeyond commented Jun 20, 2023

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!

@rjodinchr
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants