r247188 - [MS ABI] Don't crash on references to pointers to members in args

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 9 13:57:59 PDT 2015


Author: majnemer
Date: Wed Sep  9 15:57:59 2015
New Revision: 247188

URL: http://llvm.org/viewvc/llvm-project?rev=247188&view=rev
Log:
[MS ABI] Don't crash on references to pointers to members in args

We know that a reference can always be dereferenced.  However, we don't
always know the number of bytes if the reference's pointee type is
incomplete.  This case was correctly handled but we didn't consider the
case where the type is complete but we cannot calculate its size for ABI
specific reasons.  In this specific case, a member pointer's size is
available only under certain conditions.

This fixes PR24703.

Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-member-pointers.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=247188&r1=247187&r2=247188&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Sep  9 15:57:59 2015
@@ -1586,7 +1586,7 @@ void CodeGenModule::ConstructAttributeLi
 
   if (const auto *RefTy = RetTy->getAs<ReferenceType>()) {
     QualType PTy = RefTy->getPointeeType();
-    if (!PTy->isIncompleteType() && PTy->isConstantSizeType())
+    if (getCXXABI().isTypeInfoCalculable(PTy) && PTy->isConstantSizeType())
       RetAttrs.addDereferenceableAttr(getContext().getTypeSizeInChars(PTy)
                                         .getQuantity());
     else if (getContext().getTargetAddressSpace(PTy) == 0)
@@ -1698,7 +1698,7 @@ void CodeGenModule::ConstructAttributeLi
 
     if (const auto *RefTy = ParamType->getAs<ReferenceType>()) {
       QualType PTy = RefTy->getPointeeType();
-      if (!PTy->isIncompleteType() && PTy->isConstantSizeType())
+      if (getCXXABI().isTypeInfoCalculable(PTy) && PTy->isConstantSizeType())
         Attrs.addDereferenceableAttr(getContext().getTypeSizeInChars(PTy)
                                        .getQuantity());
       else if (getContext().getTargetAddressSpace(PTy) == 0)

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-member-pointers.cpp?rev=247188&r1=247187&r2=247188&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-member-pointers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-member-pointers.cpp Wed Sep  9 15:57:59 2015
@@ -745,4 +745,10 @@ void foo_fun() {
   // CHECK: store i8* bitcast (void (%class.CA*)* @"\01?OnHelp at CA@@QAEXXZ" to i8*), i8**
   f func = (f)&CA::OnHelp;
 }
+namespace PR24703 {
+struct S;
+
+void f(int S::*&p) {}
+// CHECK-LABEL: define void @"\01?f at PR24703@@YAXAAPQS at 1@H at Z"(
+}
 




More information about the cfe-commits mailing list