r213593 - -fms-extensions: Implement half of #pragma init_seg

Reid Kleckner reid at kleckner.net
Mon Jul 21 17:53:05 PDT 2014


Author: rnk
Date: Mon Jul 21 19:53:05 2014
New Revision: 213593

URL: http://llvm.org/viewvc/llvm-project?rev=213593&view=rev
Log:
-fms-extensions: Implement half of #pragma init_seg

Summary:
This pragma is very rare.  We could *hypothetically* lower some uses of
it down to @llvm.global_ctors, but given that GlobalOpt isn't able to
optimize prioritized global ctors today, there's really no point.

If we wanted to do this in the future, I would check if the section used
in the pragma started with ".CRT$XC" and had up to two characters after
it.  Those two characters could form the 16-bit initialization priority
that we support in @llvm.global_ctors.  We would have to teach LLVM to
lower prioritized global ctors on COFF as well.

This should let us compile some silly uses of this pragma in WebKit /
Blink.

Reviewers: rsmith, majnemer

Subscribers: cfe-commits

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

Added:
    cfe/trunk/test/SemaCXX/pragma-init_seg.cpp
Modified:
    cfe/trunk/include/clang/Basic/Attr.td
    cfe/trunk/include/clang/Basic/AttrDocs.td
    cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h
    cfe/trunk/lib/Parse/ParsePragma.cpp
    cfe/trunk/lib/Parse/Parser.cpp
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/lib/Sema/SemaAttr.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CodeGenCXX/pragma-init_seg.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=213593&r1=213592&r2=213593&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Mon Jul 21 19:53:05 2014
@@ -1767,6 +1767,18 @@ def MSVtorDisp : InheritableAttr {
   let Documentation = [Undocumented];
 }
 
+def InitSeg : Attr {
+  let Spellings = [Pragma<"", "init_seg">];
+  let Args = [StringArgument<"Section">];
+  let SemaHandler = 0;
+  let Documentation = [InitSegDocs];
+  let AdditionalMembers = [{
+  void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
+    OS << '(' << getSection() << ')';
+  }
+  }];
+}
+
 def Unaligned : IgnoredAttr {
   let Spellings = [Keyword<"__unaligned">];
 }

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=213593&r1=213592&r2=213593&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Mon Jul 21 19:53:05 2014
@@ -36,6 +36,22 @@ global variable or function should be in
   let Heading = "section (gnu::section, __declspec(allocate))";
 }
 
+def InitSegDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+The attribute applied by ``pragma init_seg()`` controls the section into
+which global initialization function pointers are emitted.  It is only
+available with ``-fms-extensions``.  Typically, this function pointer is
+emitted into ``.CRT$XCU`` on Windows.  The user can change the order of
+initialization by using a different section name with the same
+``.CRT$XC`` prefix and a suffix that sorts lexicographically before or
+after the standard ``.CRT$XCU`` sections.  See the init_seg_
+documentation on MSDN for more information.
+
+.. _init_seg: http://msdn.microsoft.com/en-us/library/7977wcck(v=vs.110).aspx
+  }];
+}
+
 def TLSModelDocs : Documentation {
   let Category = DocCatVariable;
   let Content = [{

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=213593&r1=213592&r2=213593&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Mon Jul 21 19:53:05 2014
@@ -800,6 +800,9 @@ def warn_pragma_expected_section_push_po
 def warn_pragma_expected_section_label_or_name : Warning<
   "expected a stack label or a string literal for the section name in '#pragma %0' - ignored">,
   InGroup<IgnoredPragmas>;
+def warn_pragma_expected_init_seg : Warning<
+  "expected 'compiler', 'lib', 'user', or a string literal for the section name in '#pragma %0' - ignored">,
+  InGroup<IgnoredPragmas>;
 def warn_pragma_expected_integer : Warning<
   "expected integer between %0 and %1 inclusive in '#pragma %2' - ignored">,
   InGroup<IgnoredPragmas>;

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=213593&r1=213592&r2=213593&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Jul 21 19:53:05 2014
@@ -725,7 +725,7 @@ private:
   /// returned.
   bool ExpectAndConsume(tok::TokenKind ExpectedTok,
                         unsigned Diag = diag::err_expected,
-                        const char *DiagMsg = "");
+                        StringRef DiagMsg = "");
 
   /// \brief The parser expects a semicolon and, if present, will consume it.
   ///

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=213593&r1=213592&r2=213593&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Jul 21 19:53:05 2014
@@ -330,6 +330,10 @@ public:
   PragmaStack<StringLiteral *> ConstSegStack;
   PragmaStack<StringLiteral *> CodeSegStack;
 
+  /// Last section used with #pragma init_seg.
+  StringLiteral *CurInitSeg;
+  SourceLocation CurInitSegLoc;
+
   /// VisContext - Manages the stack for \#pragma GCC visibility.
   void *VisContext; // Really a "PragmaVisStack*"
 
@@ -7179,6 +7183,10 @@ public:
   void ActOnPragmaMSSection(SourceLocation PragmaLocation,
                             int SectionFlags, StringLiteral *SegmentName);
 
+  /// \brief Called on well-formed \#pragma init_seg().
+  void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation,
+                            StringLiteral *SegmentName);
+
   /// ActOnPragmaDetectMismatch - Call on well-formed \#pragma detect_mismatch
   void ActOnPragmaDetectMismatch(StringRef Name, StringRef Value);
 

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=213593&r1=213592&r2=213593&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Mon Jul 21 19:53:05 2014
@@ -257,6 +257,32 @@ CreateGlobalInitOrDestructFunction(CodeG
   return Fn;
 }
 
+/// Create a global pointer to a function that will initialize a global
+/// variable.  The user has requested that this pointer be emitted in a specific
+/// section.
+void CodeGenModule::EmitPointerToInitFunc(const VarDecl *D,
+                                          llvm::GlobalVariable *GV,
+                                          llvm::Function *InitFunc,
+                                          InitSegAttr *ISA) {
+  llvm::GlobalVariable *PtrArray = new llvm::GlobalVariable(
+      TheModule, InitFunc->getType(), /*isConstant=*/true,
+      llvm::GlobalValue::PrivateLinkage, InitFunc, "__cxx_init_fn_ptr");
+  PtrArray->setSection(ISA->getSection());
+  addUsedGlobal(PtrArray);
+
+  // If the GV is already in a comdat group, then we have to join it.
+  llvm::Comdat *C = GV->getComdat();
+
+  // LinkOnce and Weak linkage are lowered down to a single-member comdat group.
+  // Make an explicit group so we can join it.
+  if (!C && (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage())) {
+    C = TheModule.getOrInsertComdat(GV->getName());
+    GV->setComdat(C);
+  }
+  if (C)
+    PtrArray->setComdat(C);
+}
+
 void
 CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
                                             llvm::GlobalVariable *Addr,
@@ -272,9 +298,9 @@ CodeGenModule::EmitCXXGlobalVarDeclInitF
   llvm::Function *Fn =
       CreateGlobalInitOrDestructFunction(*this, FTy, FnName.str());
 
+  auto *ISA = D->getAttr<InitSegAttr>();
   CodeGenFunction(*this).GenerateCXXGlobalVarDeclInitFunc(Fn, D, Addr,
                                                           PerformInit);
-
   if (D->getTLSKind()) {
     // FIXME: Should we support init_priority for thread_local?
     // FIXME: Ideally, initialization of instantiated thread_local static data
@@ -283,7 +309,10 @@ CodeGenModule::EmitCXXGlobalVarDeclInitF
     // FIXME: We only need to register one __cxa_thread_atexit function for the
     // entire TU.
     CXXThreadLocalInits.push_back(Fn);
-  } else if (const InitPriorityAttr *IPA = D->getAttr<InitPriorityAttr>()) {
+  } else if (PerformInit && ISA) {
+    EmitPointerToInitFunc(D, Addr, Fn, ISA);
+    DelayedCXXInitPosition.erase(D);
+  } else if (auto *IPA = D->getAttr<InitPriorityAttr>()) {
     OrderGlobalInits Key(IPA->getPriority(), PrioritizedCXXGlobalInits.size());
     PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
     DelayedCXXInitPosition.erase(D);

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=213593&r1=213592&r2=213593&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon Jul 21 19:53:05 2014
@@ -1103,6 +1103,9 @@ private:
                                     llvm::GlobalVariable *Addr,
                                     bool PerformInit);
 
+  void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr,
+                             llvm::Function *InitFunc, InitSegAttr *ISA);
+
   // FIXME: Hardcoding priority here is gross.
   void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
                      llvm::Constant *AssociatedData = 0);

Modified: cfe/trunk/lib/Parse/ParsePragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=213593&r1=213592&r2=213593&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParsePragma.cpp (original)
+++ cfe/trunk/lib/Parse/ParsePragma.cpp Mon Jul 21 19:53:05 2014
@@ -652,12 +652,61 @@ bool Parser::HandlePragmaMSSegment(Strin
   return true;
 }
 
+// #pragma init_seg({ compiler | lib | user | "section-name" [, func-name]} )
 bool Parser::HandlePragmaMSInitSeg(StringRef PragmaName,
                                    SourceLocation PragmaLocation) {
-  PP.Diag(PragmaLocation,
-          PP.getDiagnostics().getCustomDiagID(
-              DiagnosticsEngine::Error, "'#pragma init_seg' not implemented."));
-  return false;
+  if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
+                       PragmaName))
+    return false;
+
+  // Parse either the known section names or the string section name.
+  StringLiteral *SegmentName = nullptr;
+  if (Tok.isAnyIdentifier()) {
+    auto *II = Tok.getIdentifierInfo();
+    StringRef Section = llvm::StringSwitch<StringRef>(II->getName())
+                            .Case("compiler", "\".CRT$XCC\"")
+                            .Case("lib", "\".CRT$XCL\"")
+                            .Case("user", "\".CRT$XCU\"")
+                            .Default("");
+
+    if (!Section.empty()) {
+      // Pretend the user wrote the appropriate string literal here.
+      Token Toks[1];
+      Toks[0].startToken();
+      Toks[0].setKind(tok::string_literal);
+      Toks[0].setLocation(Tok.getLocation());
+      Toks[0].setLiteralData(Section.data());
+      Toks[0].setLength(Section.size());
+      SegmentName =
+          cast<StringLiteral>(Actions.ActOnStringLiteral(Toks, nullptr).get());
+      PP.Lex(Tok);
+    }
+  } else if (Tok.is(tok::string_literal)) {
+    ExprResult StringResult = ParseStringLiteralExpression();
+    if (StringResult.isInvalid())
+      return false;
+    SegmentName = cast<StringLiteral>(StringResult.get());
+    if (SegmentName->getCharByteWidth() != 1) {
+      PP.Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
+          << PragmaName;
+      return false;
+    }
+    // FIXME: Add support for the '[, func-name]' part of the pragma.
+  }
+
+  if (!SegmentName) {
+    PP.Diag(PragmaLocation, diag::warn_pragma_expected_init_seg) << PragmaName;
+    return false;
+  }
+
+  if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
+                       PragmaName) ||
+      ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
+                       PragmaName))
+    return false;
+
+  Actions.ActOnPragmaMSInitSeg(PragmaLocation, SegmentName);
+  return true;
 }
 
 struct PragmaLoopHintInfo {

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=213593&r1=213592&r2=213593&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Mon Jul 21 19:53:05 2014
@@ -109,7 +109,7 @@ static bool IsCommonTypo(tok::TokenKind
 }
 
 bool Parser::ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned DiagID,
-                              const char *Msg) {
+                              StringRef Msg) {
   if (Tok.is(ExpectedTok) || Tok.is(tok::code_completion)) {
     ConsumeAnyToken();
     return false;

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=213593&r1=213592&r2=213593&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Mon Jul 21 19:53:05 2014
@@ -87,7 +87,7 @@ Sema::Sema(Preprocessor &pp, ASTContext
         LangOpts.getMSPointerToMemberRepresentationMethod()),
     VtorDispModeStack(1, MSVtorDispAttr::Mode(LangOpts.VtorDispMode)),
     DataSegStack(nullptr), BSSSegStack(nullptr), ConstSegStack(nullptr),
-    CodeSegStack(nullptr), VisContext(nullptr),
+    CodeSegStack(nullptr), CurInitSeg(nullptr), VisContext(nullptr),
     IsBuildingRecoveryCallExpr(false),
     ExprNeedsCleanups(false), LateTemplateParser(nullptr),
     OpaqueParser(nullptr), IdResolver(pp), StdInitializerList(nullptr),

Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=213593&r1=213592&r2=213593&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAttr.cpp Mon Jul 21 19:53:05 2014
@@ -431,6 +431,15 @@ void Sema::ActOnPragmaMSSection(SourceLo
   UnifySection(SegmentName->getString(), SectionFlags, PragmaLocation);
 }
 
+void Sema::ActOnPragmaMSInitSeg(SourceLocation PragmaLocation,
+                                StringLiteral *SegmentName) {
+  // There's no stack to maintain, so we just have a current section.  When we
+  // see the default section, reset our current section back to null so we stop
+  // tacking on unnecessary attributes.
+  CurInitSeg = SegmentName->getString() == ".CRT$XCU" ? nullptr : SegmentName;
+  CurInitSegLoc = PragmaLocation;
+}
+
 void Sema::ActOnPragmaUnused(const Token &IdTok, Scope *curScope,
                              SourceLocation PragmaLoc) {
 

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=213593&r1=213592&r2=213593&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jul 21 19:53:05 2014
@@ -9125,6 +9125,13 @@ void Sema::CheckCompleteVariableDeclarat
     if (const SectionAttr *SA = var->getAttr<SectionAttr>())
       if (UnifySection(SA->getName(), SectionFlags, var))
         var->dropAttr<SectionAttr>();
+
+    // Apply the init_seg attribute if this has an initializer.  If the
+    // initializer turns out to not be dynamic, we'll end up ignoring this
+    // attribute.
+    if (CurInitSeg && var->getInit())
+      var->addAttr(InitSegAttr::CreateImplicit(Context, CurInitSeg->getString(),
+                                               CurInitSegLoc));
   }
 
   // All the following checks are C++ only.

Modified: cfe/trunk/test/CodeGenCXX/pragma-init_seg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/pragma-init_seg.cpp?rev=213593&r1=213592&r2=213593&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/pragma-init_seg.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/pragma-init_seg.cpp Mon Jul 21 19:53:05 2014
@@ -1,16 +1,72 @@
-// RUN: not %clang_cc1 %s -triple=i686-pc-win32 -fms-extensions -emit-llvm-only 2>&1 | FileCheck %s
+// RUN: %clang_cc1 %s -triple=i686-pc-win32 -fms-extensions -emit-llvm -o - | FileCheck %s
 
-// Reduced from WebKit.
+int f();
 
-// FIXME: Implement this pragma and test the codegen.  We probably want to
-// completely skip @llvm.global_ctors and just create global function pointers
-// to the initializer with the right section.
-
-// CHECK: '#pragma init_seg' not implemented
-#pragma init_seg(".unwantedstaticinits")
-struct A {
-  A();
-  ~A();
-  int a;
-};
-A a;
+// CHECK: $"\01?x at selectany_init@@3HA" = comdat any
+// CHECK: $"\01?x@?$A at H@explicit_template_instantiation@@2HB" = comdat any
+// CHECK: $"\01?x@?$A at H@implicit_template_instantiation@@2HB" = comdat any
+
+namespace simple_init {
+#pragma init_seg(compiler)
+int x = f();
+// CHECK: @"\01?x at simple_init@@3HA" = global i32 0, align 4
+// CHECK: @__cxx_init_fn_ptr = private constant void ()* @"\01??__Ex at simple_init@@YAXXZ", section ".CRT$XCC"
+
+#pragma init_seg(lib)
+int y = f();
+// CHECK: @"\01?y at simple_init@@3HA" = global i32 0, align 4
+// CHECK: @__cxx_init_fn_ptr1 = private constant void ()* @"\01??__Ey at simple_init@@YAXXZ", section ".CRT$XCL"
+
+#pragma init_seg(user)
+int z = f();
+// CHECK: @"\01?z at simple_init@@3HA" = global i32 0, align 4
+// No function pointer!  This one goes on @llvm.global_ctors.
+}
+
+#pragma init_seg(".asdf")
+
+namespace internal_init {
+namespace {
+int x = f();
+// CHECK: @"\01?x@?A at internal_init@@3HA" = internal global i32 0, align 4
+// CHECK: @__cxx_init_fn_ptr2 = private constant void ()* @"\01??__Ex@?A at internal_init@@YAXXZ", section ".asdf"
+}
+}
+
+namespace selectany_init {
+int __declspec(selectany) x = f();
+// CHECK: @"\01?x at selectany_init@@3HA" = weak_odr global i32 0, comdat $"\01?x at selectany_init@@3HA", align 4
+// CHECK: @__cxx_init_fn_ptr3 = private constant void ()* @"\01??__Ex at selectany_init@@YAXXZ", section ".asdf", comdat $"\01?x at selectany_init@@3HA"
+}
+
+namespace explicit_template_instantiation {
+template <typename T> struct A { static const int x; };
+template <typename T> const int A<T>::x = f();
+template struct A<int>;
+// CHECK: @"\01?x@?$A at H@explicit_template_instantiation@@2HB" = weak_odr global i32 0, comdat $"\01?x@?$A at H@explicit_template_instantiation@@2HB", align 4
+// CHECK: @__cxx_init_fn_ptr4 = private constant void ()* @"\01??__Ex@?$A at H@explicit_template_instantiation@@2HB at YAXXZ", section ".asdf", comdat $"\01?x@?$A at H@explicit_template_instantiation@@2HB"
+}
+
+namespace implicit_template_instantiation {
+template <typename T> struct A { static const int x; };
+template <typename T> const int A<T>::x = f();
+int g() { return A<int>::x; }
+// CHECK: @"\01?x@?$A at H@implicit_template_instantiation@@2HB" = linkonce_odr global i32 0, comdat $"\01?x@?$A at H@implicit_template_instantiation@@2HB", align 4
+// CHECK: @__cxx_init_fn_ptr5 = private constant void ()* @"\01??__Ex@?$A at H@implicit_template_instantiation@@2HB at YAXXZ", section ".asdf", comdat $"\01?x@?$A at H@implicit_template_instantiation@@2HB"
+}
+
+// ... and here's where we emitted user level ctors.
+// CHECK: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }]
+// CHECK: [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_pragma_init_seg.cpp, i8* null }]
+
+// We have to mark everything used so we can survive globalopt, even through
+// LTO.  There's no way LLVM could really understand if data in the .asdf
+// section is really used or dead.
+//
+// CHECK: @llvm.used = appending global [6 x i8*]
+// CHECK: [i8* bitcast (void ()** @__cxx_init_fn_ptr to i8*),
+// CHECK: i8* bitcast (void ()** @__cxx_init_fn_ptr1 to i8*),
+// CHECK: i8* bitcast (void ()** @__cxx_init_fn_ptr2 to i8*),
+// CHECK: i8* bitcast (void ()** @__cxx_init_fn_ptr3 to i8*),
+// CHECK: i8* bitcast (void ()** @__cxx_init_fn_ptr4 to i8*),
+// CHECK: i8* bitcast (void ()** @__cxx_init_fn_ptr5 to i8*)], section "llvm.metadata"

Added: cfe/trunk/test/SemaCXX/pragma-init_seg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/pragma-init_seg.cpp?rev=213593&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/pragma-init_seg.cpp (added)
+++ cfe/trunk/test/SemaCXX/pragma-init_seg.cpp Mon Jul 21 19:53:05 2014
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s -triple x86_64-pc-win32
+
+#pragma init_seg(L".my_seg") // expected-warning {{expected 'compiler', 'lib', 'user', or a string literal}}
+#pragma init_seg( // expected-warning {{expected 'compiler', 'lib', 'user', or a string literal}}
+#pragma init_seg asdf // expected-warning {{missing '('}}
+#pragma init_seg) // expected-warning {{missing '('}}
+#pragma init_seg("a" "b") // no warning
+#pragma init_seg("a", "b") // expected-warning {{missing ')'}}
+#pragma init_seg("a") asdf // expected-warning {{extra tokens at end of '#pragma init_seg'}}
+#pragma init_seg("\x") // expected-error {{\x used with no following hex digits}}
+#pragma init_seg("a" L"b") // expected-warning {{expected non-wide string literal in '#pragma init_seg'}}
+
+int f();
+#pragma init_seg(compiler)
+int __declspec(thread) x = f(); // expected-error {{initializer for thread-local variable must be a constant expression}}





More information about the cfe-commits mailing list