[PATCH] D131683: Diagnosing the Future Keywords

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 17 09:18:02 PDT 2022


aaron.ballman added a comment.

Precommit CI is failing with a failure that looks like it's relevant:

  ******************** TEST 'Clang :: Parser/static_assert.c' FAILED ********************
  Script:
  --
  : 'RUN: at line 1';   c:\ws\w9\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w9\llvm-project\premerge-checks\build\lib\clang\16.0.0\include -nostdsysteminc -fsyntax-only -std=c2x -DTEST_SPELLING -verify=c2x C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c
  : 'RUN: at line 2';   c:\ws\w9\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w9\llvm-project\premerge-checks\build\lib\clang\16.0.0\include -nostdsysteminc -fsyntax-only -std=c2x -DTEST_SPELLING -fms-compatibility -verify=c2x-ms C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c
  : 'RUN: at line 3';   c:\ws\w9\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w9\llvm-project\premerge-checks\build\lib\clang\16.0.0\include -nostdsysteminc -fsyntax-only -std=c2x -Wpre-c2x-compat -verify=c2x-compat C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c
  : 'RUN: at line 4';   c:\ws\w9\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w9\llvm-project\premerge-checks\build\lib\clang\16.0.0\include -nostdsysteminc -fsyntax-only -std=c99 -verify=c99 C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c
  : 'RUN: at line 5';   c:\ws\w9\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w9\llvm-project\premerge-checks\build\lib\clang\16.0.0\include -nostdsysteminc -fsyntax-only -std=c99 -pedantic -verify=c99-pedantic C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c
  : 'RUN: at line 6';   c:\ws\w9\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w9\llvm-project\premerge-checks\build\lib\clang\16.0.0\include -nostdsysteminc -fsyntax-only -std=c++17 -verify=cxx17 -x c++ C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c
  : 'RUN: at line 7';   c:\ws\w9\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w9\llvm-project\premerge-checks\build\lib\clang\16.0.0\include -nostdsysteminc -fsyntax-only -std=c++17 -pedantic -verify=cxx17-pedantic -x c++ C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c
  : 'RUN: at line 8';   c:\ws\w9\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w9\llvm-project\premerge-checks\build\lib\clang\16.0.0\include -nostdsysteminc -fsyntax-only -std=c++98 -verify=cxx98 -x c++ C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c
  : 'RUN: at line 9';   c:\ws\w9\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w9\llvm-project\premerge-checks\build\lib\clang\16.0.0\include -nostdsysteminc -fsyntax-only -std=c++98 -pedantic -verify=cxx98-pedantic -x c++ C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c
  : 'RUN: at line 10';   c:\ws\w9\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w9\llvm-project\premerge-checks\build\lib\clang\16.0.0\include -nostdsysteminc -fsyntax-only -std=c++17 -Wpre-c++17-compat -verify=cxx17-compat -x c++ C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c
  --
  Exit Code: 1
  
  Command Output (stdout):
  --
  $ ":" "RUN: at line 1"
  $ "c:\ws\w9\llvm-project\premerge-checks\build\bin\clang.exe" "-cc1" "-internal-isystem" "c:\ws\w9\llvm-project\premerge-checks\build\lib\clang\16.0.0\include" "-nostdsysteminc" "-fsyntax-only" "-std=c2x" "-DTEST_SPELLING" "-verify=c2x" "C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c"
  # command stderr:
  error: 'error' diagnostics expected but not seen: 
    File C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c Line 18: expected parameter declarator
    File C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c Line 18: expected ')'
    File C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c Line 18: a type specifier is required for all declarations
  error: 'warning' diagnostics seen but not expected: 
    File C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c Line 18: use of 'static_assert' without inclusion of <assert.h> is a Microsoft extension
  error: 'note' diagnostics expected but not seen: 
    File C:\ws\w9\llvm-project\premerge-checks\clang\test\Parser\static_assert.c Line 18: to match this '('
  5 errors generated.
  
  error: command failed with exit status: 1
  
  --
  
  ********************

I think this is coming from the fact that you're marking a bunch of keywords as being C2x keywords. That's correct insomuch as they are C2x keywords. But it's incorrect because we haven't actually implemented those features yet in the rest of the compiler. I think we should continue to treat the C2x keywords as we did previously. For the C2x keywords in the test file, you can put a `FIXME` comment above the ones that should get a warning whenever we finish the support for that keyword. WDYT @erichkeane?



================
Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:86
+def warn_c23_keyword : Warning<"'%0' is a keyword in C23">,
+  InGroup<CPre2xCompat>, DefaultIgnore;
 
----------------
I think the diagnostic group here is incorrect -- this grouping is used for things which are not compatible with standards before C2x. I think you need to add a new group for `C2xCompat` to DiagnosticGroups.td and use it here.


================
Comment at: clang/include/clang/Basic/IdentifierTable.h:672-674
+
+  diag::kind getFutureCompatDiagKind(const IdentifierInfo &II,
+                                     const LangOptions &LangOpts);
----------------



================
Comment at: clang/include/clang/Basic/TokenKinds.def:85-86
+#endif
+#ifndef C23_KEYWORD
+#define C23_KEYWORD(X,Y) KEYWORD(X,KEYC23|(Y))
+#endif
----------------
I think this should be `C2X_KEYWORD` and `KEYC2X` for the moment (C23 isn't published yet so we're sticking with its placeholder name elsewhere in the code base).


================
Comment at: clang/include/clang/Basic/TokenKinds.def:384
+C23_KEYWORD(true                        , BOOLSUPPORT)
+C23_KEYWORD(remove_quals                , 0)
+
----------------
This should be `KEYC23`.


================
Comment at: clang/lib/Basic/IdentifierTable.cpp:96
     KEYOPENCLC    = 0x200,
     KEYC11        = 0x400,
     KEYNOMS18     = 0x800,
----------------
It's worth noting that there are no C11 keywords that we handle only in C11+ mode, so we could probably repurpose this value for a different language mode.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131683/new/

https://reviews.llvm.org/D131683



More information about the cfe-commits mailing list