r211079 - MS static locals mangling: don't double-increment mangling number for switches

Hans Wennborg hans at hanshq.net
Mon Jun 16 17:09:06 PDT 2014


Author: hans
Date: Mon Jun 16 19:09:05 2014
New Revision: 211079

URL: http://llvm.org/viewvc/llvm-project?rev=211079&view=rev
Log:
MS static locals mangling: don't double-increment mangling number for switches

Differential Revision: http://reviews.llvm.org/D4165

Modified:
    cfe/trunk/lib/Parse/ParseStmt.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp

Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=211079&r1=211078&r2=211079&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Mon Jun 16 19:09:05 2014
@@ -1233,6 +1233,11 @@ StmtResult Parser::ParseSwitchStatement(
   getCurScope()->AddFlags(Scope::BreakScope);
   ParseScope InnerScope(this, Scope::DeclScope, C99orCXX, Tok.is(tok::l_brace));
 
+  // We have incremented the mangling number for the SwitchScope and the
+  // InnerScope, which is one too many.
+  if (C99orCXX)
+    getCurScope()->decrementMSLocalManglingNumber();
+
   // Read the body statement.
   StmtResult Body(ParseStatement(TrailingElseLoc));
 

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp?rev=211079&r1=211078&r2=211079&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp Mon Jun 16 19:09:05 2014
@@ -162,12 +162,41 @@ struct T {
   }
 };
 
+inline int switch_test(int x) {
+  // CHECK-LABEL: define linkonce_odr i32 @"\01?switch_test@@YAHH at Z"(i32 %x)
+  switch (x) {
+    static int a;
+    // CHECK: @"\01?a@?3??switch_test@@YAHH at Z@4HA"
+    case 0:
+      a++;
+      return 1;
+    case 1:
+      static int b;
+      // CHECK: @"\01?b@?3??switch_test@@YAHH at Z@4HA"
+      return b++;
+    case 2: {
+      static int c;
+      // CHECK: @"\01?c@?4??switch_test@@YAHH at Z@4HA"
+      return b + c++;
+    }
+  };
+}
+
+int f();
+inline void switch_test2() {
+  // CHECK-LABEL: define linkonce_odr void @"\01?switch_test2@@YAXXZ"()
+  // CHECK: @"\01?x@?2??switch_test2@@YAXXZ at 4HA"
+  switch (1) default: static int x = f();
+}
+
 void force_usage() {
   UnreachableStatic();
   getS();
   (void)B<int>::foo;  // (void) - force usage
   enum_in_function();
   (void)&T::enum_in_struct;
+  switch_test(1);
+  switch_test2();
 }
 
 // CHECK: define linkonce_odr void @"\01??__Efoo@?$B at H@@2VA@@A at YAXXZ"()





More information about the cfe-commits mailing list