From: David Majnemer Date: Thu, 23 Apr 2015 05:21:20 +0000 (+0000) Subject: [MS ABI] Treat ConstantArrayType like IncompleteArrayType in args X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=24003c1df297a7aabc667f616e8d7e1481a305c0;p=clang [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235572 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index 3689102114..6c953421db 100644 --- a/lib/AST/MicrosoftMangle.cpp +++ b/lib/AST/MicrosoftMangle.cpp @@ -1377,17 +1377,27 @@ void MicrosoftCXXNameMangler::mangleArgumentType(QualType T, // e.g. // void (*x)(void) will not form a backreference with void x(void) void *TypePtr; - if (const DecayedType *DT = T->getAs()) { - TypePtr = DT->getOriginalType().getCanonicalType().getAsOpaquePtr(); + if (const auto *DT = T->getAs()) { + 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); diff --git a/test/CodeGenCXX/mangle-ms-arg-qualifiers.cpp b/test/CodeGenCXX/mangle-ms-arg-qualifiers.cpp index fae2e1ab2d..41aa89b61a 100644 --- a/test/CodeGenCXX/mangle-ms-arg-qualifiers.cpp +++ b/test/CodeGenCXX/mangle-ms-arg-qualifiers.cpp @@ -258,3 +258,8 @@ void mangle_yes_backref3(ptr_to_fun_type *const, void (**const)(void)) {} void mangle_yes_backref4(int *const __restrict, int *const __restrict) {} // CHECK: "\01?mangle_yes_backref4@@YAXQIAH0@Z" // X64: "\01?mangle_yes_backref4@@YAXQEIAH0@Z" + +struct S {}; +void pr23325(const S[1], const S[]) {} +// CHECK: "\01?pr23325@@YAXQBUS@@0@Z" +// X64: "\01?pr23325@@YAXQEBUS@@0@Z"