Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2969,6 +2969,8 @@ static void prepareTypeConverter(mlir::LLVMTypeConverter &converter,
break;
// Unions are lowered as only the largest member.
case cir::RecordType::Union:
if (type.getMembers().empty())
break;
if (auto largestMember = type.getLargestMember(dataLayout))
llvmMembers.push_back(
convertTypeForMemory(converter, dataLayout, largestMember));
Expand Down
10 changes: 10 additions & 0 deletions clang/test/CIR/Lowering/union.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: cir-opt %s --cir-to-llvm | FileCheck %s

!u_empty = !cir.record<union {}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a check for the LLVM IR type here? I think we're probably generating the wrong thing. In the incubator, we generate this:

%union.U = type {}

Whereas classic codegen generates this:

%union.U = type { [4 x i8] }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me amend what I said above. I didn't realize the classic codegen I was referring to was using the Windows C ABI. Classic codegen does generate %union.U = type {} for C and %union.U = type { i8 } for C++ (which the incubator also does).

So, I guess my question is whether we identify these padded forms as "empty".


module {
cir.func @empty_union(%u: !u_empty) {
// CHECK-LABEL: llvm.func @empty_union
cir.return
}
}