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

David Majnemer david.majnemer at gmail.com
Thu Aug 14 12:12:08 PDT 2014


On Thu, Aug 14, 2014 at 11:47 AM, Reid Kleckner <rnk at google.com> wrote:

> Two things:
>
> 1. I would check Triple::isOSBinFormatCOFF() instead of the MSVC-ness of
> the environment. I think both Cygwin and MinGW probably use the .CRT$XCU
> section for initializers.
>

Nope, neither do:
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectFileInfo.cpp?revision=214538&view=markup#l629


>
> 2. Should we parse the pragma for well-formedness before ignoring it in
> Sema::ActOnPragmaInitSeg?
>

Eh, we could but it's not likely to do anything helpful.


>
>
> On Thu, Aug 14, 2014 at 12:58 AM, David Majnemer <david.majnemer at gmail.com
> > wrote:
>
>> Should this get merged in for the next release?
>>
>>
>> On Wed, Aug 13, 2014 at 11:35 PM, David Majnemer <
>> david.majnemer at gmail.com> wrote:
>>
>>> Author: majnemer
>>> Date: Thu Aug 14 01:35:08 2014
>>> New Revision: 215618
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=215618&view=rev
>>> Log:
>>> 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.
>>>
>>> Modified:
>>>     cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
>>>     cfe/trunk/lib/Parse/ParsePragma.cpp
>>>     cfe/trunk/test/SemaCXX/pragma-init_seg.cpp
>>>
>>> Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=215618&r1=215617&r2=215618&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
>>> +++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Thu Aug 14
>>> 01:35:08 2014
>>> @@ -867,6 +867,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 "
>>>
>>> Modified: cfe/trunk/lib/Parse/ParsePragma.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=215618&r1=215617&r2=215618&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/Parse/ParsePragma.cpp (original)
>>> +++ cfe/trunk/lib/Parse/ParsePragma.cpp Thu Aug 14 01:35:08 2014
>>> @@ -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"
>>> @@ -661,6 +662,11 @@ bool Parser::HandlePragmaMSSegment(Strin
>>>  // #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;
>>>
>>> Modified: cfe/trunk/test/SemaCXX/pragma-init_seg.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/pragma-init_seg.cpp?rev=215618&r1=215617&r2=215618&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/test/SemaCXX/pragma-init_seg.cpp (original)
>>> +++ cfe/trunk/test/SemaCXX/pragma-init_seg.cpp Thu Aug 14 01:35:08 2014
>>> @@ -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 '('}}
>>> @@ -10,6 +12,10 @@
>>>  #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}}
>>>
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140814/661caa41/attachment.html>


More information about the cfe-commits mailing list