r231533 - MS ABI: Correctly generate throw-info for pointer to const qual types

David Majnemer david.majnemer at gmail.com
Fri Mar 6 15:45:20 PST 2015


Author: majnemer
Date: Fri Mar  6 17:45:20 2015
New Revision: 231533

URL: http://llvm.org/viewvc/llvm-project?rev=231533&view=rev
Log:
MS ABI: Correctly generate throw-info for pointer to const qual types

We didn't create type info based on the unqualified pointee type,
causing RTTI mismatches.

Modified:
    cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-throw.cpp

Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=231533&r1=231532&r2=231533&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Fri Mar  6 17:45:20 2015
@@ -3367,7 +3367,7 @@ llvm::GlobalVariable *MicrosoftCXXABI::g
   //         - a standard pointer conversion (4.10) not involving conversions to
   //           pointers to private or protected or ambiguous classes
   //
-  // All pointers are convertible to void so ensure that it is in the
+  // All pointers are convertible to pointer-to-void so ensure that it is in the
   // CatchableTypeArray.
   if (IsPointer)
     CatchableTypes.insert(getCatchableType(getContext().VoidPtrTy));
@@ -3398,6 +3398,8 @@ llvm::GlobalVariable *MicrosoftCXXABI::g
 }
 
 llvm::GlobalVariable *MicrosoftCXXABI::getThrowInfo(QualType T) {
+  T = getContext().getExceptionObjectType(T);
+
   // C++14 [except.handle]p3:
   //   A handler is a match for an exception object of type E if [...]
   //     - the handler is of type cv T or const T& where T is a pointer type and
@@ -3409,7 +3411,17 @@ llvm::GlobalVariable *MicrosoftCXXABI::g
     IsConst = PointeeType.isConstQualified();
     IsVolatile = PointeeType.isVolatileQualified();
   }
-  T = getContext().getExceptionObjectType(T);
+
+  // Member pointer types like "const int A::*" are represented by having RTTI
+  // for "int A::*" and separately storing the const qualifier.
+  if (const auto *MPTy = T->getAs<MemberPointerType>())
+    T = getContext().getMemberPointerType(PointeeType.getUnqualifiedType(),
+                                          MPTy->getClass());
+
+  // Pointer types like "const int * const *" are represented by having RTTI
+  // for "const int **" and separately storing the const qualifier.
+  if (T->isPointerType())
+    T = getContext().getPointerType(PointeeType.getUnqualifiedType());
 
   // The CatchableTypeArray enumerates the various (CV-unqualified) types that
   // the exception object may be caught as.

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=231533&r1=231532&r2=231533&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Mar  6 17:45:20 2015
@@ -787,10 +787,9 @@ ExprResult Sema::CheckCXXThrowOperand(So
     getUnambiguousPublicSubobjects(RD, UnambiguousPublicSubobjects);
     for (CXXRecordDecl *Subobject : UnambiguousPublicSubobjects) {
       if (CXXConstructorDecl *CD = LookupCopyingConstructor(Subobject, 0)) {
-        if (CD->isTrivial())
-          continue;
         MarkFunctionReferenced(E->getExprLoc(), CD);
-        Context.addCopyConstructorForExceptionObject(Subobject, CD);
+        if (!CD->isTrivial())
+          Context.addCopyConstructorForExceptionObject(Subobject, CD);
       }
     }
   }

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-throw.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-throw.cpp?rev=231533&r1=231532&r2=231533&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-throw.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-throw.cpp Fri Mar  6 17:45:20 2015
@@ -26,6 +26,12 @@ void f(const Y &y) {
   // CHECK-LABEL: @"\01?f@@YAXABUY@@@Z"
   // CHECK: call x86_thiscallcc %struct.Y* @"\01??0Y@@QAE at ABU0@@Z"(%struct.Y* %[[mem:.*]], %struct.Y*
   // CHECK: %[[cast:.*]] = bitcast %struct.Y* %[[mem]] to i8*
-  // CHECK: call void @_CxxThrowException(i8* %[[cast]], %eh.ThrowInfo* @"_TI5?AUY@@") #4
+  // CHECK: call void @_CxxThrowException(i8* %[[cast]], %eh.ThrowInfo* @"_TI5?AUY@@")
+  throw y;
+}
+
+void g(const int *const *y) {
+  // CHECK-LABEL: @"\01?g@@YAXPBQBH at Z"
+  // CHECK: call void @_CxxThrowException(i8* %{{.*}}, %eh.ThrowInfo* @_TIC2PAPBH)
   throw y;
 }





More information about the cfe-commits mailing list