]> granicus.if.org Git - clang/commitdiff
MS static locals mangling: don't count enum scopes
authorHans Wennborg <hans@hanshq.net>
Tue, 17 Jun 2014 00:00:18 +0000 (00:00 +0000)
committerHans Wennborg <hans@hanshq.net>
Tue, 17 Jun 2014 00:00:18 +0000 (00:00 +0000)
We may not have the mangling for static locals vs. enums completely figured out,
but at least for my simple test cases, enums should not increment the mangling
number.

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

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

include/clang/Sema/Scope.h
lib/Parse/ParseDecl.cpp
lib/Sema/Scope.cpp
test/CodeGenCXX/microsoft-abi-static-initializers.cpp

index 35488450ac346b68dcbc3b46294fdf8f785631d7..5d2eab98b6304182b294cd99ec3008d2656353f5 100644 (file)
@@ -110,7 +110,10 @@ public:
     /// \brief This is the scope of some OpenMP simd directive.
     /// For example, it is used for 'omp simd', 'omp for simd'.
     /// This flag is propagated to children scopes.
-    OpenMPSimdDirectiveScope = 0x20000
+    OpenMPSimdDirectiveScope = 0x20000,
+
+    /// This scope corresponds to an enum.
+    EnumScope = 0x40000,
   };
 private:
   /// The parent scope for this scope.  This is null for the translation-unit
index 92a13659ea38febb52996b4ff073c38171b7df21..0b59fef2f8f3706fa120cc70b95fad7b809974c2 100644 (file)
@@ -3780,7 +3780,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
 ///
 void Parser::ParseEnumBody(SourceLocation StartLoc, Decl *EnumDecl) {
   // Enter the scope of the enum body and start the definition.
-  ParseScope EnumScope(this, Scope::DeclScope);
+  ParseScope EnumScope(this, Scope::DeclScope | Scope::EnumScope);
   Actions.ActOnTagStartDefinition(getCurScope(), EnumDecl);
 
   BalancedDelimiterTracker T(*this, tok::l_brace);
index 860b7c66ec60838997c05cd21a50053ff3e25921..c49133d47275dcb2c7e20f4f23bef04a202d1c79 100644 (file)
@@ -67,6 +67,7 @@ void Scope::Init(Scope *parent, unsigned flags) {
 
   // If this is a prototype scope, record that.
   if (flags & FunctionPrototypeScope) PrototypeDepth++;
+
   if (flags & DeclScope) {
     if (flags & FunctionPrototypeScope)
       ; // Prototype scopes are uninteresting.
@@ -74,6 +75,8 @@ void Scope::Init(Scope *parent, unsigned flags) {
       ; // Nested class scopes aren't ambiguous.
     else if ((flags & ClassScope) && getParent()->getFlags() == DeclScope)
       ; // Classes inside of namespaces aren't ambiguous.
+    else if ((flags & EnumScope))
+      ; // Don't increment for enum scopes.
     else
       incrementMSLocalManglingNumber();
   }
index 5666553f3a269bc86670542e262b617edd5635ea..e96a5edd65409a3ad47943ed48be306ea61bc700 100644 (file)
@@ -143,10 +143,31 @@ inline S &getS() {
 //   init.end:
 // CHECK: ret %struct.S* @"\01?TheS@?1??getS@@YAAAUS@@XZ@4U2@A"
 
+inline int enum_in_function() {
+  // CHECK-LABEL: define linkonce_odr i32 @"\01?enum_in_function@@YAHXZ"()
+  static enum e { foo, bar, baz } x;
+  // CHECK: @"\01?x@?1??enum_in_function@@YAHXZ@4W4e@?1??1@YAHXZ@A"
+  static int y;
+  // CHECK: @"\01?y@?1??enum_in_function@@YAHXZ@4HA"
+  return x + y;
+};
+
+struct T {
+  enum e { foo, bar, baz };
+  int enum_in_struct() {
+    // CHECK-LABEL: define linkonce_odr x86_thiscallcc i32 @"\01?enum_in_struct@T@@QAEHXZ"
+    static int x;
+    // CHECK: @"\01?x@?1??enum_in_struct@T@@QAEHXZ@4HA"
+    return x++;
+  }
+};
+
 void force_usage() {
   UnreachableStatic();
   getS();
   (void)B<int>::foo;  // (void) - force usage
+  enum_in_function();
+  (void)&T::enum_in_struct;
 }
 
 // CHECK: define linkonce_odr void @"\01??__Efoo@?$B@H@@2VA@@A@YAXXZ"()