[MS ABI] Add support for mangling VLA types
authorDavid Majnemer <david.majnemer@gmail.com>
Thu, 23 Apr 2015 07:42:08 +0000 (07:42 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Thu, 23 Apr 2015 07:42:08 +0000 (07:42 +0000)
Treat a VLA type like an incomplete array type.

llvm-svn: 235575

clang/lib/AST/MicrosoftMangle.cpp
clang/test/CodeGenCXX/mangle-ms-arg-qualifiers.cpp

index 6c95342..613f2c5 100644 (file)
@@ -1877,19 +1877,21 @@ void MicrosoftCXXNameMangler::mangleArrayType(const ArrayType *T) {
   QualType ElementTy(T, 0);
   SmallVector<llvm::APInt, 3> Dimensions;
   for (;;) {
-    if (const ConstantArrayType *CAT =
-            getASTContext().getAsConstantArrayType(ElementTy)) {
+    if (ElementTy->isConstantArrayType()) {
+      const ConstantArrayType *CAT =
+          getASTContext().getAsConstantArrayType(ElementTy);
       Dimensions.push_back(CAT->getSize());
       ElementTy = CAT->getElementType();
+    } else if (ElementTy->isIncompleteArrayType()) {
+      const IncompleteArrayType *IAT =
+          getASTContext().getAsIncompleteArrayType(ElementTy);
+      Dimensions.push_back(llvm::APInt(32, 0));
+      ElementTy = IAT->getElementType();
     } else if (ElementTy->isVariableArrayType()) {
       const VariableArrayType *VAT =
         getASTContext().getAsVariableArrayType(ElementTy);
-      DiagnosticsEngine &Diags = Context.getDiags();
-      unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
-        "cannot mangle this variable-length array yet");
-      Diags.Report(VAT->getSizeExpr()->getExprLoc(), DiagID)
-        << VAT->getBracketsRange();
-      return;
+      Dimensions.push_back(llvm::APInt(32, 0));
+      ElementTy = VAT->getElementType();
     } else if (ElementTy->isDependentSizedArrayType()) {
       // The dependent expression has to be folded into a constant (TODO).
       const DependentSizedArrayType *DSAT =
@@ -1900,12 +1902,9 @@ void MicrosoftCXXNameMangler::mangleArrayType(const ArrayType *T) {
       Diags.Report(DSAT->getSizeExpr()->getExprLoc(), DiagID)
         << DSAT->getBracketsRange();
       return;
-    } else if (const IncompleteArrayType *IAT =
-                   getASTContext().getAsIncompleteArrayType(ElementTy)) {
-      Dimensions.push_back(llvm::APInt(32, 0));
-      ElementTy = IAT->getElementType();
+    } else {
+      break;
     }
-    else break;
   }
   Out << 'Y';
   // <dimension-count> ::= <number> # number of extra dimensions
index 41aa89b..ad0299e 100644 (file)
@@ -263,3 +263,7 @@ struct S {};
 void pr23325(const S[1], const S[]) {}
 // CHECK: "\01?pr23325@@YAXQBUS@@0@Z"
 // X64:   "\01?pr23325@@YAXQEBUS@@0@Z"
+
+void vla_arg(int i, int a[][i]) {}
+// CHECK: "\01?vla_arg@@YAXHQAY0A@H@Z"
+// X64:   "\01?vla_arg@@YAXHQEAY0A@H@Z"