]> granicus.if.org Git - clang/commitdiff
Merging r215618:
authorBill Wendling <isanbard@gmail.com>
Mon, 18 Aug 2014 05:18:12 +0000 (05:18 +0000)
committerBill Wendling <isanbard@gmail.com>
Mon, 18 Aug 2014 05:18:12 +0000 (05:18 +0000)
------------------------------------------------------------------------
r215618 | majnemer | 2014-08-13 23:35:08 -0700 (Wed, 13 Aug 2014) | 7 lines

Parse: Don't attempt to act on #pragma init_seg when not targeting MSVC

It doesn't really make sense to try and do stuff with #pragma init_seg
when targeting non-Microsoft platforms; notions like library vs user
initializers don't exist for other targets.

This fixes PR20639.
------------------------------------------------------------------------

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

include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParsePragma.cpp
test/SemaCXX/pragma-init_seg.cpp

index 35ed795c9fd7e6f8b344653442e4edfee1421197..b1305e182f0ba7306f4812171fa7b7f951789374 100644 (file)
@@ -849,6 +849,11 @@ def warn_pragma_pack_malformed : Warning<
 def warn_pragma_unused_expected_var : Warning<
   "expected '#pragma unused' argument to be a variable name">,
   InGroup<IgnoredPragmas>;
+// - #pragma init_seg
+def warn_pragma_init_seg_unsupported_target : Warning<
+  "'#pragma init_seg' is only supported when targeting a "
+  "Microsoft environment">,
+  InGroup<IgnoredPragmas>;
 // - #pragma fp_contract
 def err_pragma_fp_contract_scope : Error<
   "'#pragma fp_contract' can only appear at file scope or at the start of a "
index b94c4bc9448ab2f016b2492e9be88d993ca16692..d3777f3ea4a09af3e1ec5354afc8b5369399385a 100644 (file)
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "RAIIObjectsForParser.h"
+#include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Parse/ParseDiagnostic.h"
 #include "clang/Parse/Parser.h"
@@ -655,6 +656,11 @@ bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
 // #pragma init_seg({ compiler | lib | user | "section-name" [, func-name]} )
 bool Parser::HandlePragmaMSInitSeg(StringRef PragmaName,
                                    SourceLocation PragmaLocation) {
+  if (getTargetInfo().getTriple().getEnvironment() != llvm::Triple::MSVC) {
+    PP.Diag(PragmaLocation, diag::warn_pragma_init_seg_unsupported_target);
+    return false;
+  }
+
   if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
                        PragmaName))
     return false;
index 38520b0c2eff18fe385b1db64eb09bc262e6e962..e18d0e6814afc2b05d0528f75f4a45d3f2516c12 100644 (file)
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s -triple x86_64-pc-win32
+// RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s -triple i386-apple-darwin13.3.0
 
+#ifndef __APPLE__
 #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("\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)
+#else
+#pragma init_seg(compiler) // expected-warning {{'#pragma init_seg' is only supported when targeting a Microsoft environment}}
+#endif
+
+int f();
 int __declspec(thread) x = f(); // expected-error {{initializer for thread-local variable must be a constant expression}}