r235572 - [MS ABI] Treat ConstantArrayType like IncompleteArrayType in args

David Majnemer david.majnemer at gmail.com
Wed Apr 22 22:21:20 PDT 2015


Author: majnemer
Date: Thu Apr 23 00:21:20 2015
New Revision: 235572

URL: http://llvm.org/viewvc/llvm-project?rev=235572&view=rev
Log:
[MS ABI] Treat ConstantArrayType like IncompleteArrayType in args

Type backreferences for arguments use the DecayedType's original type.
Because of this, arguments with the same canonical type with the same
mangling would not backreference each other if one was a
ConstantArrayType while the other was an IncompleteArrayType.  Solve
this by canonicalizing the ConstantArrayType to a suitable
IncompleteArrayType.

This fixes PR23325.

Modified:
    cfe/trunk/lib/AST/MicrosoftMangle.cpp
    cfe/trunk/test/CodeGenCXX/mangle-ms-arg-qualifiers.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=235572&r1=235571&r2=235572&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Thu Apr 23 00:21:20 2015
@@ -1377,17 +1377,27 @@ void MicrosoftCXXNameMangler::mangleArgu
   // e.g.
   // void (*x)(void) will not form a backreference with void x(void)
   void *TypePtr;
-  if (const DecayedType *DT = T->getAs<DecayedType>()) {
-    TypePtr = DT->getOriginalType().getCanonicalType().getAsOpaquePtr();
+  if (const auto *DT = T->getAs<DecayedType>()) {
+    QualType OriginalType = DT->getOriginalType();
+    // Decayed ConstantArrayType should be treated identically to decayed
+    // IncompleteArrayType.
+    if (const auto *CAT =
+            getASTContext().getAsConstantArrayType(OriginalType))
+      OriginalType = getASTContext().getIncompleteArrayType(
+          CAT->getElementType(), CAT->getSizeModifier(),
+          CAT->getIndexTypeCVRQualifiers());
+
+    TypePtr = OriginalType.getCanonicalType().getAsOpaquePtr();
     // If the original parameter was textually written as an array,
     // instead treat the decayed parameter like it's const.
     //
     // e.g.
     // int [] -> int * const
-    if (DT->getOriginalType()->isArrayType())
+    if (OriginalType->isArrayType())
       T = T.withConst();
-  } else
+  } else {
     TypePtr = T.getCanonicalType().getAsOpaquePtr();
+  }
 
   ArgBackRefMap::iterator Found = TypeBackReferences.find(TypePtr);
 

Modified: cfe/trunk/test/CodeGenCXX/mangle-ms-arg-qualifiers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-arg-qualifiers.cpp?rev=235572&r1=235571&r2=235572&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms-arg-qualifiers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms-arg-qualifiers.cpp Thu Apr 23 00:21:20 2015
@@ -258,3 +258,8 @@ void mangle_yes_backref3(ptr_to_fun_type
 void mangle_yes_backref4(int *const __restrict, int *const __restrict) {}
 // CHECK: "\01?mangle_yes_backref4@@YAXQIAH0 at Z"
 // X64:   "\01?mangle_yes_backref4@@YAXQEIAH0 at Z"
+
+struct S {};
+void pr23325(const S[1], const S[]) {}
+// CHECK: "\01?pr23325@@YAXQBUS@@0 at Z"
+// X64:   "\01?pr23325@@YAXQEBUS@@0 at Z"





More information about the cfe-commits mailing list