llvm / clangir

A new (MLIR based) high-level IR for clang.
https://clangir.org
Other
386 stars 98 forks source link

Union Initializer Fails During CIRGen #1131

Open bruteforceboy opened 1 week ago

bruteforceboy commented 1 week ago

The following code snippet fails when generating CIR, and that didn't happen until PR#1007 was merged.

typedef struct {
  union {
    int a;
    long b;
  };
} S;

S s = { .a = 1 };

It seems there is some extra padding even after unpacking the union, and there is an error when computing the size?

I tried to fix it myself, but then it fails again when lowering to LLVM, because b is marked as inactive, and a is the "active" field, but when lowering to LLVM, the type converter uses the larger member of the union.

cc: @bcardosolopes and @ChuanqiXu9 since you authored the PR)

ChuanqiXu9 commented 1 week ago

Maybe we shouldn't go into https://github.com/llvm/clangir/blob/3aed38cf52e72cb51a907fad9dd53802f6505b81/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp#L410-L416 when we're making union in the above branch?

I'd like to look into the details a few days later.

bcardosolopes commented 3 days ago

cc @gitoleg

ChuanqiXu9 commented 1 day ago

Sent https://github.com/llvm/clangir/pull/1160