]> granicus.if.org Git - clang/commitdiff
When mangling a synthetic function declaration, we might not have
authorJohn McCall <rjmccall@apple.com>
Tue, 1 May 2012 02:33:44 +0000 (02:33 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 1 May 2012 02:33:44 +0000 (02:33 +0000)
type-source information for its parameters.  Don't crash when
mangling them in the MS C++ ABI.  Patch by Timur Iskhodzhanov!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155879 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/MicrosoftMangle.cpp
test/CodeGenCXX/mangle-ms.cpp

index ba9856a8432f994df98cabaebd751729bbb88dfa..6250f61198682dc43f175bef9f1a66b8f633c220 100644 (file)
@@ -763,12 +763,16 @@ void MicrosoftCXXNameMangler::mangleType(const FunctionType *T,
     Out << 'X';
   } else {
     if (D) {
-      // If we got a decl, use the "types-as-written" to make sure arrays
-      // get mangled right.
+      // If we got a decl, use the type-as-written to make sure arrays
+      // get mangled right.  Note that we can't rely on the TSI
+      // existing if (for example) the parameter was synthesized.
       for (FunctionDecl::param_const_iterator Parm = D->param_begin(),
-           ParmEnd = D->param_end();
-           Parm != ParmEnd; ++Parm)
-        mangleType((*Parm)->getTypeSourceInfo()->getType());
+             ParmEnd = D->param_end(); Parm != ParmEnd; ++Parm) {
+        if (TypeSourceInfo *typeAsWritten = (*Parm)->getTypeSourceInfo())
+          mangleType(typeAsWritten->getType());
+        else
+          mangleType((*Parm)->getType());
+      }
     } else {
       for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(),
            ArgEnd = Proto->arg_type_end();
index fe5fde1a1b3bfc72d4182165219e49b660612ef9..ceaa669f199cd5c6c62378d65362ec43cff78b1a 100644 (file)
@@ -103,3 +103,17 @@ void epsilon(int a[][10][20]) {}
 void zeta(int (^)(int, int)) {}
 // CHECK: @"\01?zeta@@YAXP_EAHHH@Z@Z"
 
+void operator_new_delete() {
+  char *ptr = new char;
+// CHECK: @"\01??2@YAPAXI@Z"
+
+  delete ptr;
+// CHECK: @"\01??3@YAXPAX@Z"
+
+  char *array = new char[42];
+// CHECK: @"\01??_U@YAPAXI@Z"
+
+  // FIXME: enable once PR12333 is fixed
+  // delete [] array;
+// Should be: @"\01??_V@YAXPAX@Z"
+}