]> granicus.if.org Git - clang/commitdiff
[MS ABI] Rework .xdata HandlerType emission
authorDavid Majnemer <david.majnemer@gmail.com>
Sun, 29 Mar 2015 21:55:10 +0000 (21:55 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sun, 29 Mar 2015 21:55:10 +0000 (21:55 +0000)
Utilizing IMAGEREL relocations for synthetic IR constructs isn't
valuable, just clutter.  While we are here, simplify HandlerType names
by making the numeric value for the 'adjective' part of the mangled name
instead of appending '.const', etc.  The old scheme made for very long
global names and leads to wordy things like '.std_bad_alloc'

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233503 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Mangle.h
lib/AST/MicrosoftMangle.cpp
lib/CodeGen/CGCXXABI.h
lib/CodeGen/CGException.cpp
lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/CodeGenModule.h
lib/CodeGen/ItaniumCXXABI.cpp
lib/CodeGen/MicrosoftCXXABI.cpp
test/CodeGenCXX/microsoft-abi-try-throw.cpp

index 23dde6b3f927d1fafafe68705497ac1c1a5e35ea..e4bccedff9fd981238a1a522fe735856489579ad 100644 (file)
@@ -208,9 +208,8 @@ public:
                                       uint32_t NVOffset, int32_t VBPtrOffset,
                                       uint32_t VBIndex, raw_ostream &Out) = 0;
 
-  virtual void mangleCXXHandlerMapEntry(QualType T, bool IsConst,
-                                        bool IsVolatile, bool IsReference,
-                                        raw_ostream &Out) = 0;
+  virtual void mangleCXXCatchHandlerType(QualType T, uint32_t Flags,
+                                         raw_ostream &Out) = 0;
 
   virtual void mangleCXXRTTIBaseClassDescriptor(
       const CXXRecordDecl *Derived, uint32_t NVOffset, int32_t VBPtrOffset,
index 563ea7ffc866e50012bc7abdd20439a8ae0ef258..bf9d7a0118c849482cdcdfce70d4ff0297487d7a 100644 (file)
@@ -122,8 +122,8 @@ public:
                               CXXCtorType CT, uint32_t Size, uint32_t NVOffset,
                               int32_t VBPtrOffset, uint32_t VBIndex,
                               raw_ostream &Out) override;
-  void mangleCXXHandlerMapEntry(QualType T, bool IsConst, bool IsVolatile,
-                                bool IsReference, raw_ostream &Out) override;
+  void mangleCXXCatchHandlerType(QualType T, uint32_t Flags,
+                                 raw_ostream &Out) override;
   void mangleCXXRTTI(QualType T, raw_ostream &Out) override;
   void mangleCXXRTTIName(QualType T, raw_ostream &Out) override;
   void mangleCXXRTTIBaseClassDescriptor(const CXXRecordDecl *Derived,
@@ -2345,20 +2345,13 @@ void MicrosoftMangleContextImpl::mangleCXXRTTIName(QualType T,
   Mangler.mangleType(T, SourceRange(), MicrosoftCXXNameMangler::QMM_Result);
 }
 
-void MicrosoftMangleContextImpl::mangleCXXHandlerMapEntry(QualType T,
-                                                          bool IsConst,
-                                                          bool IsVolatile,
-                                                          bool IsReference,
-                                                          raw_ostream &Out) {
+void MicrosoftMangleContextImpl::mangleCXXCatchHandlerType(QualType T,
+                                                           uint32_t Flags,
+                                                           raw_ostream &Out) {
   MicrosoftCXXNameMangler Mangler(*this, Out);
-  Mangler.getStream() << "llvm.eh.handlermapentry.";
-  if (IsConst)
-    Mangler.getStream() << "const.";
-  if (IsVolatile)
-    Mangler.getStream() << "volatile.";
-  if (IsReference)
-    Mangler.getStream() << "reference.";
+  Mangler.getStream() << "llvm.eh.handlertype.";
   Mangler.mangleType(T, SourceRange(), MicrosoftCXXNameMangler::QMM_Result);
+  Mangler.getStream() << '.' << Flags;
 }
 
 void MicrosoftMangleContextImpl::mangleCXXThrowInfo(QualType T,
index b6a94f9082de541ed6d782fed7c7a0189a11e846..2c7392188f784f6435d4ce6f6c1698c4f803efdf 100644 (file)
@@ -226,7 +226,7 @@ public:
 
   virtual llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty) = 0;
   virtual llvm::Constant *
-  getAddrOfCXXHandlerMapEntry(QualType Ty, QualType CatchHandlerType) = 0;
+  getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType) = 0;
 
   virtual bool shouldTypeidBeNullChecked(bool IsDeref,
                                          QualType SrcRecordTy) = 0;
index 223b8f76d0d3679dacc364416b2a7f42d540ac9c..1925c57d1bdbad3fe70b251b4328adcccc5b2cc9 100644 (file)
@@ -568,7 +568,7 @@ void CodeGenFunction::EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock) {
         TypeInfo = CGM.getObjCRuntime().GetEHType(CaughtType);
       else
         TypeInfo =
-            CGM.getAddrOfCXXHandlerMapEntry(CaughtType, C->getCaughtType());
+            CGM.getAddrOfCXXCatchHandlerType(CaughtType, C->getCaughtType());
       CatchScope->setHandler(I, TypeInfo, Handler);
     } else {
       // No exception decl indicates '...', a catch-all.
index f4ae684179a7087620efbfe82caf364d33a62180..ae511ae4fe405f0d6144aa80e39cbe2e68276b26 100644 (file)
@@ -3638,9 +3638,9 @@ llvm::Constant *CodeGenModule::EmitUuidofInitializer(StringRef Uuid) {
 }
 
 llvm::Constant *
-CodeGenModule::getAddrOfCXXHandlerMapEntry(QualType Ty,
-                                           QualType CatchHandlerType) {
-  return getCXXABI().getAddrOfCXXHandlerMapEntry(Ty, CatchHandlerType);
+CodeGenModule::getAddrOfCXXCatchHandlerType(QualType Ty,
+                                            QualType CatchHandlerType) {
+  return getCXXABI().getAddrOfCXXCatchHandlerType(Ty, CatchHandlerType);
 }
 
 llvm::Constant *CodeGenModule::GetAddrOfRTTIDescriptor(QualType Ty,
index ce540e91dcb514f01e093c6fcb67710030d811ef..398aa5c9e172f56579db2a67145949d7e1465c7e 100644 (file)
@@ -719,8 +719,8 @@ public:
   /// Get the address of the RTTI descriptor for the given type.
   llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
 
-  llvm::Constant *getAddrOfCXXHandlerMapEntry(QualType Ty,
-                                              QualType CatchHandlerType);
+  llvm::Constant *getAddrOfCXXCatchHandlerType(QualType Ty,
+                                               QualType CatchHandlerType);
 
   /// Get the address of a uuid descriptor .
   llvm::Constant *GetAddrOfUuidDescriptor(const CXXUuidofExpr* E);
index f23cd9f9481ef39d1d8ea7a2dc0f48380e6285c5..62f1293ff66753f32671eeee4b0334bbd13cbb35 100644 (file)
@@ -127,7 +127,8 @@ public:
   void EmitFundamentalRTTIDescriptors();
   llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty) override;
   llvm::Constant *
-  getAddrOfCXXHandlerMapEntry(QualType Ty, QualType CatchHandlerType) override {
+  getAddrOfCXXCatchHandlerType(QualType Ty,
+                               QualType CatchHandlerType) override {
     return getAddrOfRTTIDescriptor(Ty);
   }
 
index f8f784567a3042b4a8c55bffe2f72ac0bb94db78..b8089edd704f95ac7c7a99a6c1357af2d4b2cf27 100644 (file)
@@ -45,7 +45,7 @@ public:
       : CGCXXABI(CGM), BaseClassDescriptorType(nullptr),
         ClassHierarchyDescriptorType(nullptr),
         CompleteObjectLocatorType(nullptr), CatchableTypeType(nullptr),
-        ThrowInfoType(nullptr), HandlerMapEntryType(nullptr) {}
+        ThrowInfoType(nullptr), CatchHandlerTypeType(nullptr) {}
 
   bool HasThisReturn(GlobalDecl GD) const override;
   bool hasMostDerivedReturn(GlobalDecl GD) const override;
@@ -85,7 +85,7 @@ public:
 
   llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty) override;
   llvm::Constant *
-  getAddrOfCXXHandlerMapEntry(QualType Ty, QualType CatchHandlerType) override;
+  getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType) override;
 
   bool shouldTypeidBeNullChecked(bool IsDeref, QualType SrcRecordTy) override;
   void EmitBadTypeidCall(CodeGenFunction &CGF) override;
@@ -573,16 +573,16 @@ public:
 
   void emitCXXStructor(const CXXMethodDecl *MD, StructorType Type) override;
 
-  llvm::StructType *getHandlerMapEntryType() {
-    if (!HandlerMapEntryType) {
+  llvm::StructType *getCatchHandlerTypeType() {
+    if (!CatchHandlerTypeType) {
       llvm::Type *FieldTypes[] = {
-        CGM.IntTy,                           // Flags
-        getImageRelativeType(CGM.Int8PtrTy), // TypeDescriptor
+          CGM.IntTy,     // Flags
+          CGM.Int8PtrTy, // TypeDescriptor
       };
-      HandlerMapEntryType = llvm::StructType::create(
-          CGM.getLLVMContext(), FieldTypes, "eh.HandlerMapEntry");
+      CatchHandlerTypeType = llvm::StructType::create(
+          CGM.getLLVMContext(), FieldTypes, "eh.CatchHandlerType");
     }
-    return HandlerMapEntryType;
+    return CatchHandlerTypeType;
   }
 
   llvm::StructType *getCatchableTypeType() {
@@ -698,7 +698,7 @@ private:
   llvm::StructType *CatchableTypeType;
   llvm::DenseMap<uint32_t, llvm::StructType *> CatchableTypeArrayTypeMap;
   llvm::StructType *ThrowInfoType;
-  llvm::StructType *HandlerMapEntryType;
+  llvm::StructType *CatchHandlerTypeType;
 };
 
 }
@@ -3193,8 +3193,8 @@ static QualType decomposeTypeForEH(ASTContext &Context, QualType T,
 }
 
 llvm::Constant *
-MicrosoftCXXABI::getAddrOfCXXHandlerMapEntry(QualType Type,
-                                             QualType CatchHandlerType) {
+MicrosoftCXXABI::getAddrOfCXXCatchHandlerType(QualType Type,
+                                              QualType CatchHandlerType) {
   // TypeDescriptors for exceptions never have qualified pointer types,
   // qualifiers are stored seperately in order to support qualification
   // conversions.
@@ -3203,16 +3203,6 @@ MicrosoftCXXABI::getAddrOfCXXHandlerMapEntry(QualType Type,
 
   bool IsReference = CatchHandlerType->isReferenceType();
 
-  SmallString<256> MangledName;
-  {
-    llvm::raw_svector_ostream Out(MangledName);
-    getMangleContext().mangleCXXHandlerMapEntry(Type, IsConst, IsVolatile,
-                                                IsReference, Out);
-  }
-
-  if (llvm::GlobalVariable *GV = CGM.getModule().getNamedGlobal(MangledName))
-    return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy);
-
   uint32_t Flags = 0;
   if (IsConst)
     Flags |= 1;
@@ -3221,15 +3211,24 @@ MicrosoftCXXABI::getAddrOfCXXHandlerMapEntry(QualType Type,
   if (IsReference)
     Flags |= 8;
 
+  SmallString<256> MangledName;
+  {
+    llvm::raw_svector_ostream Out(MangledName);
+    getMangleContext().mangleCXXCatchHandlerType(Type, Flags, Out);
+  }
+
+  if (llvm::GlobalVariable *GV = CGM.getModule().getNamedGlobal(MangledName))
+    return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy);
+
   llvm::Constant *Fields[] = {
-      llvm::ConstantInt::get(CGM.IntTy, Flags),                // Flags
-      getImageRelativeConstant(getAddrOfRTTIDescriptor(Type)), // TypeDescriptor
+      llvm::ConstantInt::get(CGM.IntTy, Flags), // Flags
+      getAddrOfRTTIDescriptor(Type),            // TypeDescriptor
   };
-  llvm::StructType *HandlerMapEntryType = getHandlerMapEntryType();
+  llvm::StructType *CatchHandlerTypeType = getCatchHandlerTypeType();
   auto *Var = new llvm::GlobalVariable(
-      CGM.getModule(), HandlerMapEntryType, /*Constant=*/true,
+      CGM.getModule(), CatchHandlerTypeType, /*Constant=*/true,
       llvm::GlobalValue::PrivateLinkage,
-      llvm::ConstantStruct::get(HandlerMapEntryType, Fields),
+      llvm::ConstantStruct::get(CatchHandlerTypeType, Fields),
       StringRef(MangledName));
   Var->setUnnamedAddr(true);
   Var->setSection("llvm.metadata");
index c7bbcf28888589c19e11385a0f085d8c76766c24..a3a45a5468594fa8c2a010a519895649bd13d503 100644 (file)
@@ -6,7 +6,7 @@
 // THROW-DAG: @_CTA1H = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.1 { i32 1, [1 x %eh.CatchableType*] [%eh.CatchableType* @"_CT??_R0H@84"] }, section ".xdata", comdat
 // THROW-DAG: @_TI1H = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 0, i8* null, i8* null, i8* bitcast (%eh.CatchableTypeArray.1* @_CTA1H to i8*) }, section ".xdata", comdat
 
-// TRY-DAG: @llvm.eh.handlermapentry.const.PAH = private unnamed_addr constant %eh.HandlerMapEntry { i32 1, i8* bitcast (%rtti.TypeDescriptor4* @"\01??_R0PAH@8" to i8*) }, section "llvm.metadata"
+// TRY-DAG: @llvm.eh.handlertype.PAH.1 = private unnamed_addr constant %eh.CatchHandlerType { i32 1, i8* bitcast (%rtti.TypeDescriptor4* @"\01??_R0PAH@8" to i8*) }, section "llvm.metadata"
 
 void external();
 
@@ -41,7 +41,7 @@ void qual_catch() {
     external();
   } catch (const int *) {
   }
-  // TRY: catch %eh.HandlerMapEntry* @llvm.eh.handlermapentry.const.PAH
-  // TRY: call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry.const.PAH to i8*))
+  // TRY: catch %eh.CatchHandlerType* @llvm.eh.handlertype.PAH.1
+  // TRY: call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.PAH.1 to i8*))
 }
 #endif