Re: [PATCH] D13322: Add -f[no-]declspec to control recognition of __declspec as a keyword
compnerd closed this revision. compnerd added a comment. Committed as SVN r249279 (as per your request in the initial revision). http://reviews.llvm.org/D13322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13322: Add -f[no-]declspec to control recognition of __declspec as a keyword
wristow added inline comments. Comment at: lib/Driver/Tools.cpp:4663 @@ +4662,3 @@ + else if (Args.hasArg(options::OPT_fno_declspec)) +CmdArgs.push_back("-fno-declspec"); // Explicitly disabling __declspec. + But in the '-fno-declspec -fdeclspec' case, the 'if' clause "wins", and we never even reach the test of the 'else if' clause. As I said at the end of my previous comment, if -fno-declspec isn't the last one, we don't get to that line. That said, given the interaction with "implicit enabling" of declspec (via Microsoft, Borland, CUDA), it's a bit different than vanilla switch-handling. So I've updated the tests to explicitly have some checks for '-fno-declspec -fdeclspec' case (and the reverse, and for with and without -fms-extensions interacting). http://reviews.llvm.org/D13322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13322: Add -f[no-]declspec to control recognition of __declspec as a keyword
wristow updated this revision to Diff 36373. wristow added a comment. Added 4 new tests, the verify the last -fdeclspec/-fno-declspec wins, both in the context of -fms-extensions and without -fms-extensions. http://reviews.llvm.org/D13322 Files: include/clang/Basic/LangOptions.def include/clang/Basic/TokenKinds.def include/clang/Driver/Options.td include/clang/Parse/Parser.h lib/Basic/IdentifierTable.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp lib/Parse/ParseDecl.cpp test/Lexer/keywords_test.c test/Lexer/keywords_test.cpp Index: test/Lexer/keywords_test.cpp === --- test/Lexer/keywords_test.cpp +++ test/Lexer/keywords_test.cpp @@ -1,6 +1,19 @@ // RUN: %clang_cc1 -std=c++03 -fsyntax-only %s // RUN: %clang_cc1 -std=c++11 -DCXX11 -fsyntax-only %s // RUN: %clang_cc1 -std=c++14 -fconcepts-ts -DCXX11 -DCONCEPTS -fsyntax-only %s +// RUN: %clang_cc1 -std=c++03 -fdeclspec -DDECLSPEC -fsyntax-only %s +// RUN: %clang_cc1 -std=c++03 -fms-extensions -DDECLSPEC -fsyntax-only %s +// RUN: %clang_cc1 -std=c++03 -fborland-extensions -DDECLSPEC -fsyntax-only %s +// RUN: %clang_cc1 -std=c++03 -fms-extensions -fno-declspec -fsyntax-only %s +// RUN: %clang_cc1 -std=c++03 -fborland-extensions -fno-declspec -fsyntax-only %s +// RUN: %clang_cc1 -std=c++03 -fno-declspec -fdeclspec -DDECLSPEC -fsyntax-only %s +// RUN: %clang_cc1 -std=c++03 -fdeclspec -fno-declspec -fsyntax-only %s +// RUN: %clang_cc1 -std=c++03 -fms-extensions -fno-declspec -fdeclspec -DDECLSPEC -fsyntax-only %s +// RUN: %clang_cc1 -std=c++03 -fms-extensions -fdeclspec -fno-declspec -fsyntax-only %s +// RUN: %clang -std=c++03 -target i686-windows-msvc -DDECLSPEC -fsyntax-only %s +// RUN: %clang -std=c++03 -target x86_64-scei-ps4 -DDECLSPEC -fsyntax-only %s +// RUN: %clang -std=c++03 -target i686-windows-msvc -fno-declspec -fsyntax-only %s +// RUN: %clang -std=c++03 -target x86_64-scei-ps4 -fno-declspec -fsyntax-only %s #define IS_KEYWORD(NAME) _Static_assert(!__is_identifier(NAME), #NAME) #define NOT_KEYWORD(NAME) _Static_assert(__is_identifier(NAME), #NAME) @@ -12,6 +25,12 @@ #define CONCEPTS_KEYWORD(NAME) NOT_KEYWORD(NAME) #endif +#ifdef DECLSPEC +#define DECLSPEC_KEYWORD(NAME) IS_KEYWORD(NAME) +#else +#define DECLSPEC_KEYWORD(NAME) NOT_KEYWORD(NAME) +#endif + #ifdef CXX11 #define CXX11_KEYWORD(NAME) IS_KEYWORD(NAME) #define CXX11_TYPE(NAME) IS_TYPE(NAME) @@ -38,6 +57,9 @@ CONCEPTS_KEYWORD(concept); CONCEPTS_KEYWORD(requires); +// __declspec extension +DECLSPEC_KEYWORD(__declspec); + // Clang extension IS_KEYWORD(__char16_t); IS_TYPE(__char16_t); Index: test/Lexer/keywords_test.c === --- test/Lexer/keywords_test.c +++ test/Lexer/keywords_test.c @@ -9,6 +9,10 @@ // RUN: %clang_cc1 -std=c99 -fms-extensions -E %s -o - \ // RUN: | FileCheck --check-prefix=CHECK-MS-KEYWORDS %s +// RUN: %clang_cc1 -std=c99 -fdeclspec -E %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-DECLSPEC-KEYWORD %s +// RUN: %clang_cc1 -std=c99 -fms-extensions -fno-declspec -E %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-MS-KEYWORDS-WITHOUT-DECLSPEC %s void f() { // CHECK-NONE: int asm @@ -22,8 +26,19 @@ // CHECK-NONE: no_ms_wchar // CHECK-MS-KEYWORDS: has_ms_wchar +// CHECK-MS-KEYWORDS-WITHOUT-DECLSPEC: has_ms_wchar #if __is_identifier(__wchar_t) void no_ms_wchar(); #else void has_ms_wchar(); #endif + +// CHECK-NONE: no_declspec +// CHECK-MS-KEYWORDS: has_declspec +// CHECK-MS-KEYWORDS-WITHOUT-DECLSPEC: no_declspec +// CHECK-DECLSPEC-KEYWORD: has_declspec +#if __is_identifier(__declspec) +void no_declspec(); +#else +void has_declspec(); +#endif Index: lib/Parse/ParseDecl.cpp === --- lib/Parse/ParseDecl.cpp +++ lib/Parse/ParseDecl.cpp @@ -532,9 +532,7 @@ /// extended-decl-modifier extended-decl-modifier-seq void Parser::ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs, SourceLocation *End) { - assert((getLangOpts().MicrosoftExt || getLangOpts().Borland || - getLangOpts().CUDA) && - "Incorrect language options for parsing __declspec"); + assert(getLangOpts().DeclSpecKeyword && "__declspec keyword is not enabled"); assert(Tok.is(tok::kw___declspec) && "Not a declspec!"); while (Tok.is(tok::kw___declspec)) { Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -1630,6 +1630,17 @@ Opts.HalfArgsAndReturns = Args.hasArg(OPT_fallow_half_arguments_and_returns); Opts.GNUAsm = !Args.hasArg(OPT_fno_gnu_inline_asm); + // __declspec is enabled by default for the PS4 by the driver, and also + // enabled for Microsoft Extensions or Borland Extensions, here. + // + // FIXME: __declspec is al
Re: [PATCH] D13322: Add -f[no-]declspec to control recognition of __declspec as a keyword
compnerd added inline comments. Comment at: lib/Driver/Tools.cpp:4663 @@ +4662,3 @@ + else if (Args.hasArg(options::OPT_fno_declspec)) +CmdArgs.push_back("-fno-declspec"); // Explicitly disabling __declspec. + @rsmith, so they are. I misread something and was thinking they were under CC1Options.td. Comment at: lib/Driver/Tools.cpp:4663 @@ +4662,3 @@ + else if (Args.hasArg(options::OPT_fno_declspec)) +CmdArgs.push_back("-fno-declspec"); // Explicitly disabling __declspec. + compnerd wrote: > @rsmith, so they are. I misread something and was thinking they were under > CC1Options.td. Sure, but you are still giving -fno-declspec precedence over -fdeclspec. Consider -fno-declspec -fdeclspec. I think what you want is Args.getLastArg, not Args.hasArg. http://reviews.llvm.org/D13322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13322: Add -f[no-]declspec to control recognition of __declspec as a keyword
wristow updated this revision to Diff 36307. wristow added a comment. Updated patch to change the Group of the diagnostic from f_Group to f_clang_Group, and to change the string associated with the LANGOPT definition of the flag. Also fixed a minor typo in a comment. http://reviews.llvm.org/D13322 Files: include/clang/Basic/LangOptions.def include/clang/Basic/TokenKinds.def include/clang/Driver/Options.td include/clang/Parse/Parser.h lib/Basic/IdentifierTable.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp lib/Parse/ParseDecl.cpp test/Lexer/keywords_test.c test/Lexer/keywords_test.cpp Index: test/Lexer/keywords_test.cpp === --- test/Lexer/keywords_test.cpp +++ test/Lexer/keywords_test.cpp @@ -1,6 +1,15 @@ // RUN: %clang_cc1 -std=c++03 -fsyntax-only %s // RUN: %clang_cc1 -std=c++11 -DCXX11 -fsyntax-only %s // RUN: %clang_cc1 -std=c++14 -fconcepts-ts -DCXX11 -DCONCEPTS -fsyntax-only %s +// RUN: %clang_cc1 -std=c++03 -fdeclspec -DDECLSPEC -fsyntax-only %s +// RUN: %clang_cc1 -std=c++03 -fms-extensions -DDECLSPEC -fsyntax-only %s +// RUN: %clang_cc1 -std=c++03 -fborland-extensions -DDECLSPEC -fsyntax-only %s +// RUN: %clang_cc1 -std=c++03 -fms-extensions -fno-declspec -fsyntax-only %s +// RUN: %clang_cc1 -std=c++03 -fborland-extensions -fno-declspec -fsyntax-only %s +// RUN: %clang -std=c++03 -target i686-windows-msvc -DDECLSPEC -fsyntax-only %s +// RUN: %clang -std=c++03 -target x86_64-scei-ps4 -DDECLSPEC -fsyntax-only %s +// RUN: %clang -std=c++03 -target i686-windows-msvc -fno-declspec -fsyntax-only %s +// RUN: %clang -std=c++03 -target x86_64-scei-ps4 -fno-declspec -fsyntax-only %s #define IS_KEYWORD(NAME) _Static_assert(!__is_identifier(NAME), #NAME) #define NOT_KEYWORD(NAME) _Static_assert(__is_identifier(NAME), #NAME) @@ -12,6 +21,12 @@ #define CONCEPTS_KEYWORD(NAME) NOT_KEYWORD(NAME) #endif +#ifdef DECLSPEC +#define DECLSPEC_KEYWORD(NAME) IS_KEYWORD(NAME) +#else +#define DECLSPEC_KEYWORD(NAME) NOT_KEYWORD(NAME) +#endif + #ifdef CXX11 #define CXX11_KEYWORD(NAME) IS_KEYWORD(NAME) #define CXX11_TYPE(NAME) IS_TYPE(NAME) @@ -38,6 +53,9 @@ CONCEPTS_KEYWORD(concept); CONCEPTS_KEYWORD(requires); +// __declspec extension +DECLSPEC_KEYWORD(__declspec); + // Clang extension IS_KEYWORD(__char16_t); IS_TYPE(__char16_t); Index: test/Lexer/keywords_test.c === --- test/Lexer/keywords_test.c +++ test/Lexer/keywords_test.c @@ -9,6 +9,10 @@ // RUN: %clang_cc1 -std=c99 -fms-extensions -E %s -o - \ // RUN: | FileCheck --check-prefix=CHECK-MS-KEYWORDS %s +// RUN: %clang_cc1 -std=c99 -fdeclspec -E %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-DECLSPEC-KEYWORD %s +// RUN: %clang_cc1 -std=c99 -fms-extensions -fno-declspec -E %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-MS-KEYWORDS-WITHOUT-DECLSPEC %s void f() { // CHECK-NONE: int asm @@ -22,8 +26,19 @@ // CHECK-NONE: no_ms_wchar // CHECK-MS-KEYWORDS: has_ms_wchar +// CHECK-MS-KEYWORDS-WITHOUT-DECLSPEC: has_ms_wchar #if __is_identifier(__wchar_t) void no_ms_wchar(); #else void has_ms_wchar(); #endif + +// CHECK-NONE: no_declspec +// CHECK-MS-KEYWORDS: has_declspec +// CHECK-MS-KEYWORDS-WITHOUT-DECLSPEC: no_declspec +// CHECK-DECLSPEC-KEYWORD: has_declspec +#if __is_identifier(__declspec) +void no_declspec(); +#else +void has_declspec(); +#endif Index: lib/Parse/ParseDecl.cpp === --- lib/Parse/ParseDecl.cpp +++ lib/Parse/ParseDecl.cpp @@ -532,9 +532,7 @@ /// extended-decl-modifier extended-decl-modifier-seq void Parser::ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs, SourceLocation *End) { - assert((getLangOpts().MicrosoftExt || getLangOpts().Borland || - getLangOpts().CUDA) && - "Incorrect language options for parsing __declspec"); + assert(getLangOpts().DeclSpecKeyword && "__declspec keyword is not enabled"); assert(Tok.is(tok::kw___declspec) && "Not a declspec!"); while (Tok.is(tok::kw___declspec)) { Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -1630,6 +1630,17 @@ Opts.HalfArgsAndReturns = Args.hasArg(OPT_fallow_half_arguments_and_returns); Opts.GNUAsm = !Args.hasArg(OPT_fno_gnu_inline_asm); + // __declspec is enabled by default for the PS4 by the driver, and also + // enabled for Microsoft Extensions or Borland Extensions, here. + // + // FIXME: __declspec is also currently enabled for CUDA, but isn't really a + // CUDA extension, however it is required for supporting cuda_builtin_vars.h, + // which uses __declspec(property). Once that has been rewritten in terms of + // something more generic, remove the Opts.CUDA term here. + Opts.Dec
Re: [PATCH] D13322: Add -f[no-]declspec to control recognition of __declspec as a keyword
wristow added inline comments. Comment at: include/clang/Basic/LangOptions.def:93 @@ -92,2 +92,3 @@ LANGOPT(WChar , 1, CPlusPlus, "wchar_t keyword") +LANGOPT(DeclSpecKeyword , 1, 0, "Microsoft __declspec keyword support") BENIGN_LANGOPT(DollarIdents , 1, 1, "'$' in identifiers") rsmith wrote: > compnerd wrote: > > Im not sure I care for Microsoft here. This is an extension that is > > supported on more than one compiler suite. How about "Enable support for > > __declspec extension"? > These strings are used in a diagnostic of the form "support for %0 is not > enabled", so `"__declspec"` or `"__declspec keyword"` would be appropriate. I see. Then I'll change it to "__declspec keyword", to both remove the Microsoft reference and make it appropriate for the diagnostic formed from it. Comment at: include/clang/Driver/Options.td:520 @@ -519,1 +519,3 @@ +def fdeclspec : Flag<["-"], "fdeclspec">, Group, + HelpText<"Allow __declspec as a keyword">, Flags<[CC1Option]>; def fdollars_in_identifiers : Flag<["-"], "fdollars-in-identifiers">, Group, rsmith wrote: > compnerd wrote: > > Shouldn't these be DriverOptions, and CC1Options? > This should be in `f_clang_Group`, not `f_Group`. I'll upload an updated patch shortly that takes care of this. Comment at: lib/Driver/Tools.cpp:4663 @@ +4662,3 @@ + else if (Args.hasArg(options::OPT_fno_declspec)) +CmdArgs.push_back("-fno-declspec"); // Explicitly disabling __declspec. + rsmith wrote: > compnerd wrote: > > The Args.hasFlag will correctly give you the value (-fdeclspec > > -fno-declspec will be treated as -fno-declspec). In fact, doesn't your > > implementation make -fno-declspec take precedence? > > > > Plus, you marked these as cc1options above, not driver options. These > > aren't technically available here. > The options are in the driver's Options.td and marked as CC1Option, so > they're available in both the driver and cc1. OK, then I'll leave them marked as CC1Option. Comment at: lib/Driver/Tools.cpp:4663 @@ +4662,3 @@ + else if (Args.hasArg(options::OPT_fno_declspec)) +CmdArgs.push_back("-fno-declspec"); // Explicitly disabling __declspec. + wristow wrote: > rsmith wrote: > > compnerd wrote: > > > The Args.hasFlag will correctly give you the value (-fdeclspec > > > -fno-declspec will be treated as -fno-declspec). In fact, doesn't your > > > implementation make -fno-declspec take precedence? > > > > > > Plus, you marked these as cc1options above, not driver options. These > > > aren't technically available here. > > The options are in the driver's Options.td and marked as CC1Option, so > > they're available in both the driver and cc1. > OK, then I'll leave them marked as CC1Option. Regarding the -fno-declspec taking precedence question, I think I've got it right, but I could have misunderstood something. There is a complication with this declspec-keyword recognition, in that in addition to it being enabled by default for PS4, it's implicitly enabled by default with any of -fms-compatibility, -fms-extensions and -fborland-extensions (and temporarily also for CUDA). My goal of -fno-declspec is that it should over-ride any implicit enabling of declspec. The implicit enabling was handled in cc1 itself (by inspecting values that depend on -fms-compatibility, -fms-extensions, -fborland-extensions, and CUDA). I left that being handled in cc1, although I considered collecting that information here in the driver, and passing a more elaborate expression as the 'Default' arg to hasFlag(), in which case I wouldn't have needed to explicitly push_back("-fno-declspec"). Anyway, with implicit enabling of declspec happening in cc1, it was easy to over-ride it by explicitly passing -fno-declspec through, iff that was the last -fdeclspec/-fno-declspec arg passed by the user. So that's what I'm doing on the line with the "// Explicitly disabling __declspec." comment (unless I've misunderstood, if -fno-declspec isn't the last one, we don't get to that line). http://reviews.llvm.org/D13322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13322: Add -f[no-]declspec to control recognition of __declspec as a keyword
rsmith added a subscriber: rsmith. Comment at: include/clang/Basic/LangOptions.def:93 @@ -92,2 +92,3 @@ LANGOPT(WChar , 1, CPlusPlus, "wchar_t keyword") +LANGOPT(DeclSpecKeyword , 1, 0, "Microsoft __declspec keyword support") BENIGN_LANGOPT(DollarIdents , 1, 1, "'$' in identifiers") compnerd wrote: > Im not sure I care for Microsoft here. This is an extension that is > supported on more than one compiler suite. How about "Enable support for > __declspec extension"? These strings are used in a diagnostic of the form "support for %0 is not enabled", so `"__declspec"` or `"__declspec keyword"` would be appropriate. Comment at: include/clang/Driver/Options.td:520 @@ -519,1 +519,3 @@ +def fdeclspec : Flag<["-"], "fdeclspec">, Group, + HelpText<"Allow __declspec as a keyword">, Flags<[CC1Option]>; def fdollars_in_identifiers : Flag<["-"], "fdollars-in-identifiers">, Group, compnerd wrote: > Shouldn't these be DriverOptions, and CC1Options? This should be in `f_clang_Group`, not `f_Group`. Comment at: lib/Driver/Tools.cpp:4663 @@ +4662,3 @@ + else if (Args.hasArg(options::OPT_fno_declspec)) +CmdArgs.push_back("-fno-declspec"); // Explicitly disabling __declspec. + compnerd wrote: > The Args.hasFlag will correctly give you the value (-fdeclspec -fno-declspec > will be treated as -fno-declspec). In fact, doesn't your implementation make > -fno-declspec take precedence? > > Plus, you marked these as cc1options above, not driver options. These aren't > technically available here. The options are in the driver's Options.td and marked as CC1Option, so they're available in both the driver and cc1. http://reviews.llvm.org/D13322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13322: Add -f[no-]declspec to control recognition of __declspec as a keyword
compnerd added inline comments. Comment at: include/clang/Basic/LangOptions.def:93 @@ -92,2 +92,3 @@ LANGOPT(WChar , 1, CPlusPlus, "wchar_t keyword") +LANGOPT(DeclSpecKeyword , 1, 0, "Microsoft __declspec keyword support") BENIGN_LANGOPT(DollarIdents , 1, 1, "'$' in identifiers") Im not sure I care for Microsoft here. This is an extension that is supported on more than one compiler suite. How about "Enable support for __declspec extension"? Comment at: include/clang/Driver/Options.td:520 @@ -519,1 +519,3 @@ +def fdeclspec : Flag<["-"], "fdeclspec">, Group, + HelpText<"Allow __declspec as a keyword">, Flags<[CC1Option]>; def fdollars_in_identifiers : Flag<["-"], "fdollars-in-identifiers">, Group, Shouldn't these be DriverOptions, and CC1Options? Comment at: lib/Driver/Tools.cpp:4663 @@ +4662,3 @@ + else if (Args.hasArg(options::OPT_fno_declspec)) +CmdArgs.push_back("-fno-declspec"); // Explicitly disabling __declspec. + The Args.hasFlag will correctly give you the value (-fdeclspec -fno-declspec will be treated as -fno-declspec). In fact, doesn't your implementation make -fno-declspec take precedence? Plus, you marked these as cc1options above, not driver options. These aren't technically available here. http://reviews.llvm.org/D13322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits