r211078 - MS static locals mangling: don't count enum scopes

Hans Wennborg hans at hanshq.net
Mon Jun 16 17:00:19 PDT 2014


Author: hans
Date: Mon Jun 16 19:00:18 2014
New Revision: 211078

URL: http://llvm.org/viewvc/llvm-project?rev=211078&view=rev
Log:
MS static locals mangling: don't count enum scopes

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

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

Modified: cfe/trunk/include/clang/Sema/Scope.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Scope.h?rev=211078&r1=211077&r2=211078&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Scope.h (original)
+++ cfe/trunk/include/clang/Sema/Scope.h Mon Jun 16 19:00:18 2014
@@ -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

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=211078&r1=211077&r2=211078&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Jun 16 19:00:18 2014
@@ -3780,7 +3780,7 @@ void Parser::ParseEnumSpecifier(SourceLo
 ///
 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);

Modified: cfe/trunk/lib/Sema/Scope.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Scope.cpp?rev=211078&r1=211077&r2=211078&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Scope.cpp (original)
+++ cfe/trunk/lib/Sema/Scope.cpp Mon Jun 16 19:00:18 2014
@@ -67,6 +67,7 @@ void Scope::Init(Scope *parent, unsigned
 
   // 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
       ; // 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();
   }

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=211078&r1=211077&r2=211078&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:00:18 2014
@@ -143,10 +143,31 @@ inline S &getS() {
 //   init.end:
 // CHECK: ret %struct.S* @"\01?TheS@?1??getS@@YAAAUS@@XZ at 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 at 4W4e@?1??1 at YAHXZ@A"
+  static int y;
+  // CHECK: @"\01?y@?1??enum_in_function@@YAHXZ at 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 at T@@QAEHXZ"
+    static int x;
+    // CHECK: @"\01?x@?1??enum_in_struct at T@@QAEHXZ at 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 at H@@2VA@@A at YAXXZ"()





More information about the cfe-commits mailing list