clangir icon indicating copy to clipboard operation
clangir copied to clipboard

[CIR][CodeGen] Replace uses of global with alias

Open tommymcm opened this issue 4 months ago • 3 comments

Minimized test case:

class A {
public:
  A();
} A;
A::A() {}

Failed assertion: https://github.com/llvm/clangir/blob/aeac352c9de907fcbb7adde22bbe4a7cfa3105be/clang/lib/CIR/CodeGen/CIRGenModule.cpp#L2479

Flags: -fclangir -O2

tommymcm avatar Aug 13 '25 21:08 tommymcm

hi Tommy, would love to work on this but i'm not sure I understand what "replace uses of global with alias" do in this case. Functionally I know I can just follow the TODO by some replaceAllUsesWith but i'm not sure how can I interpret the new change that would come with the PR

badumbatish avatar Sep 12 '25 09:09 badumbatish

there is some funky stuff going on with the ordering of the test case and the function generation with the test case in the issue, replacing the op with the alias like the comment said with error out because the call to the function is placed behind the decl of A:

 error: 'llvm.call' op '_ZN1AC1Ev' does not reference a valid LLVM function or IFunc
fatal error: error in backend: The pass manager failed to lower CIR to LLVMIR dialect!

if we change the test case to

class A {
public:
  A();
};
A::A() {}

A;

then it'd compile and emit llvm

badumbatish avatar Sep 12 '25 09:09 badumbatish

Yes we're trying to test the case from the issue, which has been minimized from a benchmark. The compiler needs to resolve a global declaraction using a class whose methods have been declared but not defined yet. The failing assertion needs to be implemented.

tommymcm avatar Sep 12 '25 15:09 tommymcm