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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to