r220429 - Parse: Ignore "long" and "short" in #pragma section

David Majnemer david.majnemer at gmail.com
Wed Oct 22 14:08:43 PDT 2014


Author: majnemer
Date: Wed Oct 22 16:08:43 2014
New Revision: 220429

URL: http://llvm.org/viewvc/llvm-project?rev=220429&view=rev
Log:
Parse: Ignore "long" and "short" in #pragma section

This fixes PR21337.

Modified:
    cfe/trunk/lib/Parse/ParsePragma.cpp
    cfe/trunk/test/CodeGenCXX/sections.cpp

Modified: cfe/trunk/lib/Parse/ParsePragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=220429&r1=220428&r2=220429&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParsePragma.cpp (original)
+++ cfe/trunk/lib/Parse/ParsePragma.cpp Wed Oct 22 16:08:43 2014
@@ -532,9 +532,18 @@ bool Parser::HandlePragmaMSSection(Strin
         << PragmaName;
     return false;
   }
-  int SectionFlags = 0;
+  int SectionFlags = ASTContext::PSF_Read;
+  bool SectionFlagsAreDefault = true;
   while (Tok.is(tok::comma)) {
     PP.Lex(Tok); // ,
+    // Ignore "long" and "short".
+    // They are undocumented, but widely used, section attributes which appear
+    // to do nothing.
+    if (Tok.is(tok::kw_long) || Tok.is(tok::kw_short)) {
+      PP.Lex(Tok); // long/short
+      continue;
+    }
+
     if (!Tok.isAnyIdentifier()) {
       PP.Diag(PragmaLocation, diag::warn_pragma_expected_action_or_r_paren)
           << PragmaName;
@@ -560,8 +569,13 @@ bool Parser::HandlePragmaMSSection(Strin
       return false;
     }
     SectionFlags |= Flag;
+    SectionFlagsAreDefault = false;
     PP.Lex(Tok); // Identifier
   }
+  // If no section attributes are specified, the section will be marked as
+  // read/write.
+  if (SectionFlagsAreDefault)
+    SectionFlags |= ASTContext::PSF_Write;
   if (Tok.isNot(tok::r_paren)) {
     PP.Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
     return false;

Modified: cfe/trunk/test/CodeGenCXX/sections.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/sections.cpp?rev=220429&r1=220428&r2=220429&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/sections.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/sections.cpp Wed Oct 22 16:08:43 2014
@@ -38,6 +38,17 @@ __declspec(allocate("read_flag_section")
 extern __declspec(allocate("read_flag_section")) int referenced = 42;
 int *user() { return &referenced; }
 
+#pragma section("no_section_attributes")
+// A pragma section with no section attributes is read/write.
+__declspec(allocate("no_section_attributes")) int implicitly_read_write = 42;
+
+#pragma section("long_section", long)
+// Pragma section ignores "long".
+__declspec(allocate("long_section")) long long_var = 42;
+
+#pragma section("short_section", short)
+// Pragma section ignores "short".
+__declspec(allocate("short_section")) short short_var = 42;
 }
 
 //CHECK: @D = global i32 1
@@ -54,5 +65,8 @@ int *user() { return &referenced; }
 //CHECK: @TEST2 = global i32 0, section ".bss1"
 //CHECK: @unreferenced = constant i32 0, section "read_flag_section"
 //CHECK: @referenced = constant i32 42, section "read_flag_section"
+//CHECK: @implicitly_read_write = global i32 42, section "no_section_attributes"
+//CHECK: @long_var = global i32 42, section "long_section"
+//CHECK: @short_var = global i16 42, section "short_section"
 //CHECK: define void @g()
 //CHECK: define void @h() {{.*}} section ".my_code"





More information about the cfe-commits mailing list