[clang] [llvm] [PowerPC] Fix codegen for transparent_union function params (PR #101738)
Lei Huang via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 6 09:33:12 PDT 2024
lei137 wrote:
I was thinking it would make the code cleaner if we can do something like this instead:
```
// For transparent union types, return the type of the first element.
-// Set TU to true if Ty given was a transparent union and to false otherwise.
+// and set CTy the integer type of the first union element. CTy defaults to nullptr.
-QualType CodeGen::useFirstFieldIfTransparentUnion(QualType Ty, bool &TU) {
+QualType CodeGen::useFirstFieldIfTransparentUnion(QualType Ty,
+ llvm::Type *CTy) {
if (const RecordType *UT = Ty->getAsUnionType()) {
const RecordDecl *UD = UT->getDecl();
if (UD->hasAttr<TransparentUnionAttr>()) {
assert(!UD->field_empty() && "sema created an empty transparent union");
- TU = true;
- return UD->field_begin()->getType();
+ QualType UTy = UD->field_begin()->getType();
+ *CTy = llvm::IntegerType::get(getVMContext(),
+ getContext().getTypeSize(UTy));
+ return UTy;
}
}
- TU = false;
return Ty;
}
```
Then we can just call `getExtend(Ty, Cty)` by default. But I think I would need to put this function into `DefaultABIInfo` class to access the `getVMContext()`? Not sure that's the right thing to do though..
https://github.com/llvm/llvm-project/pull/101738
More information about the cfe-commits
mailing list