[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-04-22 Thread via cfe-commits

zibi2 wrote:

> Actually, a trailing comma in the macro invocation might work too. It’s been 
> a while since I last had to deal w/ this.

Yes, it does and I think it's cleaner than my proposal. Thank you.

https://github.com/llvm/llvm-project/pull/84520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-04-22 Thread via cfe-commits

zibi2 wrote:

I agree the code is not C++17 compliant. An alternative fix would be to compile 
this file with `-Wno-c++20-extensions`.

https://github.com/llvm/llvm-project/pull/84520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-04-19 Thread via cfe-commits

Sirraide wrote:

Actually, a trailing comma in the macro invocation might work too. It’s been a 
while since I last had to deal w/ this.

https://github.com/llvm/llvm-project/pull/84520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-04-19 Thread via cfe-commits

Sirraide wrote:

> @Sirraide, I noticed the following build issue when new compiler with this 
> change (bootstrap compiler) is being used to build one of the files for 
> `clangd`:
> 
> ```
> .../clang-tools-extra/clangd/unittests/FindTargetTests.cpp:430:29: error: 
> passing no argument for the '...' parameter of a variadic macro is a C++20 
> extension [-Werror,-Wc++20-extensions]
>   430 |   EXPECT_DECLS("AutoTypeLoc");
>   | ^
> .../clang-tools-extra/clangd/unittests/FindTargetTests.cpp:98:9: note: macro 
> 'EXPECT_DECLS' defined here
>98 | #define EXPECT_DECLS(NodeType, ...)   
>  \
>   | ^
> ```
> 
> Do you have suggestion how to fix it or even better provie the fix? Thank 
> you, Zibi

I mean, from what I can tell, this isn’t a Clang issue but rather just a result 
of this code here not being standards-compliant C++17. Before C++20, afaik the 
‘fix’ for this is to have two different macros: one variadic, one not variadic. 
It’s not pretty, but that’s why that got changed in C++20.

https://github.com/llvm/llvm-project/pull/84520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-04-19 Thread via cfe-commits

zibi2 wrote:

@Sirraide, I noticed the following build issue when new compiler with this 
change (bootstrap compiler)  is being used to build one of the files for 
`clangd`:

```
.../clang-tools-extra/clangd/unittests/FindTargetTests.cpp:430:29: error: 
passing no argument for the '...' parameter of a variadic macro is a C++20 
extension [-Werror,-Wc++20-extensions]
  430 |   EXPECT_DECLS("AutoTypeLoc");
  | ^
.../clang-tools-extra/clangd/unittests/FindTargetTests.cpp:98:9: note: macro 
'EXPECT_DECLS' defined here
   98 | #define EXPECT_DECLS(NodeType, ...) 
   \
  | ^
```

Do you have suggestion how to fix it or even better provie the fix?
Thank you,
Zibi

https://github.com/llvm/llvm-project/pull/84520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-03-20 Thread via cfe-commits

https://github.com/Sirraide closed 
https://github.com/llvm/llvm-project/pull/84520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-03-20 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/84520

>From 502692869e3105bb2c55955bc4baff63b1475770 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Fri, 8 Mar 2024 18:15:07 +0100
Subject: [PATCH 1/3] [Clang] Update missing varargs arg extension warnings

---
 clang/docs/ReleaseNotes.rst|  3 +++
 .../include/clang/Basic/DiagnosticLexKinds.td  | 13 ++---
 clang/lib/Lex/PPMacroExpansion.cpp | 13 ++---
 clang/test/C/C2x/n2975.c   |  4 ++--
 clang/test/Lexer/gnu-flags.c   |  2 --
 clang/test/Preprocessor/empty_va_arg.cpp   | 18 +++---
 clang/test/Preprocessor/macro_fn.c |  4 ++--
 7 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0ff4a93b15ea8f..ffc88e79961ce6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -212,6 +212,9 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses lambda function expressions being implicitly cast to 
boolean values, under ``-Wpointer-bool-conversion``.
   Fixes #GH82512.
 
+- Clang now correctly diagnoses no arguments to a variadic macro parameter as 
a C23/C++20 extension.
+  Fixes #GH84495.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index d7c172e6546351..ad6bacfb118d49 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -465,9 +465,16 @@ def err_embedded_directive : Error<
 def ext_embedded_directive : Extension<
   "embedding a directive within macro arguments has undefined behavior">,
   InGroup>;
-def ext_missing_varargs_arg : Extension<
-  "must specify at least one argument for '...' parameter of variadic macro">,
-  InGroup;
+def ext_c_missing_varargs_arg : Extension<
+  "passing no argument for the '...' parameter of a variadic macro is "
+  "a C23 extension">, InGroup;
+def ext_cxx_missing_varargs_arg : Extension<
+  "passing no argument for the '...' parameter of a variadic macro is "
+  "a C++20 extension">, InGroup;
+def warn_c17_compat_missing_varargs_arg : Warning<
+  "passing no argument for the '...' parameter of a variadic macro is "
+  "incompatible with C standards before C23">,
+  InGroup, DefaultIgnore;
 def warn_cxx17_compat_missing_varargs_arg : Warning<
   "passing no argument for the '...' parameter of a variadic macro is "
   "incompatible with C++ standards before C++20">,
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 3017461dc66e86..3cde001e84760e 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -995,9 +995,16 @@ MacroArgs *Preprocessor::ReadMacroCallArgumentList(Token 
&MacroName,
   if (!MI->hasCommaPasting()) {
 // C++20 allows this construct, but standards before C++20 and all C
 // standards do not allow the construct (we allow it as an extension).
-Diag(Tok, getLangOpts().CPlusPlus20
-  ? diag::warn_cxx17_compat_missing_varargs_arg
-  : diag::ext_missing_varargs_arg);
+unsigned ID;
+if (getLangOpts().CPlusPlus20)
+  ID = diag::warn_cxx17_compat_missing_varargs_arg;
+else if (getLangOpts().CPlusPlus)
+  ID = diag::ext_cxx_missing_varargs_arg;
+else if (getLangOpts().C23)
+  ID = diag::warn_c17_compat_missing_varargs_arg;
+else
+  ID = diag::ext_c_missing_varargs_arg;
+Diag(Tok, ID);
 Diag(MI->getDefinitionLoc(), diag::note_macro_here)
   << MacroName.getIdentifierInfo();
   }
diff --git a/clang/test/C/C2x/n2975.c b/clang/test/C/C2x/n2975.c
index 5fc641dd66e781..2269400fe47c34 100644
--- a/clang/test/C/C2x/n2975.c
+++ b/clang/test/C/C2x/n2975.c
@@ -11,7 +11,7 @@
 void func(...) { // expected-warning {{'...' as the only parameter of a 
function is incompatible with C standards before C23}}
   // Show that va_start doesn't require the second argument in C23 mode.
   va_list list;
-  va_start(list); // FIXME: it would be nice to issue a portability warning to 
C17 and earlier here.
+  va_start(list); // expected-warning {{passing no argument for the '...' 
parameter of a variadic macro is incompatible with C standards before C23}} 
expected-note@* {{macro 'va_start' defined here}}
   va_end(list);
 
   // Show that va_start doesn't expand or evaluate the second argument.
@@ -26,7 +26,7 @@ void func(...) { // expected-warning {{'...' as the only 
parameter of a function
   __builtin_va_start(list); // expected-error {{too few arguments to function 
call, expected 2, have 1}}
 
   // Verify that the return type of a call to va_start is 'void'.
-  _Static_assert(__builtin_types_compatible_p(__typeof__(va_start(list)), 
void), "");
+  _Static_

[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-03-20 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/84520

>From 502692869e3105bb2c55955bc4baff63b1475770 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Fri, 8 Mar 2024 18:15:07 +0100
Subject: [PATCH 1/3] [Clang] Update missing varargs arg extension warnings

---
 clang/docs/ReleaseNotes.rst|  3 +++
 .../include/clang/Basic/DiagnosticLexKinds.td  | 13 ++---
 clang/lib/Lex/PPMacroExpansion.cpp | 13 ++---
 clang/test/C/C2x/n2975.c   |  4 ++--
 clang/test/Lexer/gnu-flags.c   |  2 --
 clang/test/Preprocessor/empty_va_arg.cpp   | 18 +++---
 clang/test/Preprocessor/macro_fn.c |  4 ++--
 7 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0ff4a93b15ea8f..ffc88e79961ce6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -212,6 +212,9 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses lambda function expressions being implicitly cast to 
boolean values, under ``-Wpointer-bool-conversion``.
   Fixes #GH82512.
 
+- Clang now correctly diagnoses no arguments to a variadic macro parameter as 
a C23/C++20 extension.
+  Fixes #GH84495.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index d7c172e6546351..ad6bacfb118d49 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -465,9 +465,16 @@ def err_embedded_directive : Error<
 def ext_embedded_directive : Extension<
   "embedding a directive within macro arguments has undefined behavior">,
   InGroup>;
-def ext_missing_varargs_arg : Extension<
-  "must specify at least one argument for '...' parameter of variadic macro">,
-  InGroup;
+def ext_c_missing_varargs_arg : Extension<
+  "passing no argument for the '...' parameter of a variadic macro is "
+  "a C23 extension">, InGroup;
+def ext_cxx_missing_varargs_arg : Extension<
+  "passing no argument for the '...' parameter of a variadic macro is "
+  "a C++20 extension">, InGroup;
+def warn_c17_compat_missing_varargs_arg : Warning<
+  "passing no argument for the '...' parameter of a variadic macro is "
+  "incompatible with C standards before C23">,
+  InGroup, DefaultIgnore;
 def warn_cxx17_compat_missing_varargs_arg : Warning<
   "passing no argument for the '...' parameter of a variadic macro is "
   "incompatible with C++ standards before C++20">,
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 3017461dc66e86..3cde001e84760e 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -995,9 +995,16 @@ MacroArgs *Preprocessor::ReadMacroCallArgumentList(Token 
&MacroName,
   if (!MI->hasCommaPasting()) {
 // C++20 allows this construct, but standards before C++20 and all C
 // standards do not allow the construct (we allow it as an extension).
-Diag(Tok, getLangOpts().CPlusPlus20
-  ? diag::warn_cxx17_compat_missing_varargs_arg
-  : diag::ext_missing_varargs_arg);
+unsigned ID;
+if (getLangOpts().CPlusPlus20)
+  ID = diag::warn_cxx17_compat_missing_varargs_arg;
+else if (getLangOpts().CPlusPlus)
+  ID = diag::ext_cxx_missing_varargs_arg;
+else if (getLangOpts().C23)
+  ID = diag::warn_c17_compat_missing_varargs_arg;
+else
+  ID = diag::ext_c_missing_varargs_arg;
+Diag(Tok, ID);
 Diag(MI->getDefinitionLoc(), diag::note_macro_here)
   << MacroName.getIdentifierInfo();
   }
diff --git a/clang/test/C/C2x/n2975.c b/clang/test/C/C2x/n2975.c
index 5fc641dd66e781..2269400fe47c34 100644
--- a/clang/test/C/C2x/n2975.c
+++ b/clang/test/C/C2x/n2975.c
@@ -11,7 +11,7 @@
 void func(...) { // expected-warning {{'...' as the only parameter of a 
function is incompatible with C standards before C23}}
   // Show that va_start doesn't require the second argument in C23 mode.
   va_list list;
-  va_start(list); // FIXME: it would be nice to issue a portability warning to 
C17 and earlier here.
+  va_start(list); // expected-warning {{passing no argument for the '...' 
parameter of a variadic macro is incompatible with C standards before C23}} 
expected-note@* {{macro 'va_start' defined here}}
   va_end(list);
 
   // Show that va_start doesn't expand or evaluate the second argument.
@@ -26,7 +26,7 @@ void func(...) { // expected-warning {{'...' as the only 
parameter of a function
   __builtin_va_start(list); // expected-error {{too few arguments to function 
call, expected 2, have 1}}
 
   // Verify that the return type of a call to va_start is 'void'.
-  _Static_assert(__builtin_types_compatible_p(__typeof__(va_start(list)), 
void), "");
+  _Static_

[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-03-20 Thread via cfe-commits


@@ -993,11 +993,18 @@ MacroArgs *Preprocessor::ReadMacroCallArgumentList(Token 
&MacroName,
   // If the macro contains the comma pasting extension, the diagnostic
   // is suppressed; we know we'll get another diagnostic later.
   if (!MI->hasCommaPasting()) {
-// C++20 allows this construct, but standards before C++20 and all C
-// standards do not allow the construct (we allow it as an extension).
-Diag(Tok, getLangOpts().CPlusPlus20
-  ? diag::warn_cxx17_compat_missing_varargs_arg
-  : diag::ext_missing_varargs_arg);
+// C++20 and C23 allow this construct, but standards before that
+// do not (we allow it as an extension).

Sirraide wrote:

Sure, will do.

https://github.com/llvm/llvm-project/pull/84520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-03-20 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

LGTM aside from a comment request

https://github.com/llvm/llvm-project/pull/84520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-03-20 Thread Aaron Ballman via cfe-commits


@@ -993,11 +993,18 @@ MacroArgs *Preprocessor::ReadMacroCallArgumentList(Token 
&MacroName,
   // If the macro contains the comma pasting extension, the diagnostic
   // is suppressed; we know we'll get another diagnostic later.
   if (!MI->hasCommaPasting()) {
-// C++20 allows this construct, but standards before C++20 and all C
-// standards do not allow the construct (we allow it as an extension).
-Diag(Tok, getLangOpts().CPlusPlus20
-  ? diag::warn_cxx17_compat_missing_varargs_arg
-  : diag::ext_missing_varargs_arg);
+// C++20 and C23 allow this construct, but standards before that
+// do not (we allow it as an extension).

AaronBallman wrote:

I think it's worth adding the standards citation just the same, even if we 
don't copy the text from the standard. e.g.,
```
// C++20 [cpp.replace]p15, C23 6.10.5p12
```


https://github.com/llvm/llvm-project/pull/84520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-03-20 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman edited 
https://github.com/llvm/llvm-project/pull/84520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-03-08 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik edited https://github.com/llvm/llvm-project/pull/84520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-03-08 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

Just a nit here.

https://github.com/llvm/llvm-project/pull/84520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-03-08 Thread Shafik Yaghmour via cfe-commits


@@ -993,11 +993,18 @@ MacroArgs *Preprocessor::ReadMacroCallArgumentList(Token 
&MacroName,
   // If the macro contains the comma pasting extension, the diagnostic
   // is suppressed; we know we'll get another diagnostic later.
   if (!MI->hasCommaPasting()) {
-// C++20 allows this construct, but standards before C++20 and all C
-// standards do not allow the construct (we allow it as an extension).
-Diag(Tok, getLangOpts().CPlusPlus20
-  ? diag::warn_cxx17_compat_missing_varargs_arg
-  : diag::ext_missing_varargs_arg);
+// C++20 and C23 allow this construct, but standards before that
+// do not (we allow it as an extension).

shafik wrote:

CC @AaronBallman should we add a standard quote like we normally do for C++? It 
looks like it should be 6.10.5 p12. It took me a but to remember in C they are 
referred to as *variable arguments* and not variadic like in C++. 

https://github.com/llvm/llvm-project/pull/84520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-03-08 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/84520

>From 502692869e3105bb2c55955bc4baff63b1475770 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Fri, 8 Mar 2024 18:15:07 +0100
Subject: [PATCH 1/2] [Clang] Update missing varargs arg extension warnings

---
 clang/docs/ReleaseNotes.rst|  3 +++
 .../include/clang/Basic/DiagnosticLexKinds.td  | 13 ++---
 clang/lib/Lex/PPMacroExpansion.cpp | 13 ++---
 clang/test/C/C2x/n2975.c   |  4 ++--
 clang/test/Lexer/gnu-flags.c   |  2 --
 clang/test/Preprocessor/empty_va_arg.cpp   | 18 +++---
 clang/test/Preprocessor/macro_fn.c |  4 ++--
 7 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0ff4a93b15ea8f..ffc88e79961ce6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -212,6 +212,9 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses lambda function expressions being implicitly cast to 
boolean values, under ``-Wpointer-bool-conversion``.
   Fixes #GH82512.
 
+- Clang now correctly diagnoses no arguments to a variadic macro parameter as 
a C23/C++20 extension.
+  Fixes #GH84495.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index d7c172e6546351..ad6bacfb118d49 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -465,9 +465,16 @@ def err_embedded_directive : Error<
 def ext_embedded_directive : Extension<
   "embedding a directive within macro arguments has undefined behavior">,
   InGroup>;
-def ext_missing_varargs_arg : Extension<
-  "must specify at least one argument for '...' parameter of variadic macro">,
-  InGroup;
+def ext_c_missing_varargs_arg : Extension<
+  "passing no argument for the '...' parameter of a variadic macro is "
+  "a C23 extension">, InGroup;
+def ext_cxx_missing_varargs_arg : Extension<
+  "passing no argument for the '...' parameter of a variadic macro is "
+  "a C++20 extension">, InGroup;
+def warn_c17_compat_missing_varargs_arg : Warning<
+  "passing no argument for the '...' parameter of a variadic macro is "
+  "incompatible with C standards before C23">,
+  InGroup, DefaultIgnore;
 def warn_cxx17_compat_missing_varargs_arg : Warning<
   "passing no argument for the '...' parameter of a variadic macro is "
   "incompatible with C++ standards before C++20">,
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 3017461dc66e86..3cde001e84760e 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -995,9 +995,16 @@ MacroArgs *Preprocessor::ReadMacroCallArgumentList(Token 
&MacroName,
   if (!MI->hasCommaPasting()) {
 // C++20 allows this construct, but standards before C++20 and all C
 // standards do not allow the construct (we allow it as an extension).
-Diag(Tok, getLangOpts().CPlusPlus20
-  ? diag::warn_cxx17_compat_missing_varargs_arg
-  : diag::ext_missing_varargs_arg);
+unsigned ID;
+if (getLangOpts().CPlusPlus20)
+  ID = diag::warn_cxx17_compat_missing_varargs_arg;
+else if (getLangOpts().CPlusPlus)
+  ID = diag::ext_cxx_missing_varargs_arg;
+else if (getLangOpts().C23)
+  ID = diag::warn_c17_compat_missing_varargs_arg;
+else
+  ID = diag::ext_c_missing_varargs_arg;
+Diag(Tok, ID);
 Diag(MI->getDefinitionLoc(), diag::note_macro_here)
   << MacroName.getIdentifierInfo();
   }
diff --git a/clang/test/C/C2x/n2975.c b/clang/test/C/C2x/n2975.c
index 5fc641dd66e781..2269400fe47c34 100644
--- a/clang/test/C/C2x/n2975.c
+++ b/clang/test/C/C2x/n2975.c
@@ -11,7 +11,7 @@
 void func(...) { // expected-warning {{'...' as the only parameter of a 
function is incompatible with C standards before C23}}
   // Show that va_start doesn't require the second argument in C23 mode.
   va_list list;
-  va_start(list); // FIXME: it would be nice to issue a portability warning to 
C17 and earlier here.
+  va_start(list); // expected-warning {{passing no argument for the '...' 
parameter of a variadic macro is incompatible with C standards before C23}} 
expected-note@* {{macro 'va_start' defined here}}
   va_end(list);
 
   // Show that va_start doesn't expand or evaluate the second argument.
@@ -26,7 +26,7 @@ void func(...) { // expected-warning {{'...' as the only 
parameter of a function
   __builtin_va_start(list); // expected-error {{too few arguments to function 
call, expected 2, have 1}}
 
   // Verify that the return type of a call to va_start is 'void'.
-  _Static_assert(__builtin_types_compatible_p(__typeof__(va_start(list)), 
void), "");
+  _Static_

[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-03-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Sirraide)


Changes

This updates a few warnings that were diagnosing no arguments for a `...` 
variadic macro parameter as a GNU extension when it actually is a C++20/C23 
extension now.

This fixes #84495.

---
Full diff: https://github.com/llvm/llvm-project/pull/84520.diff


7 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/Basic/DiagnosticLexKinds.td (+10-3) 
- (modified) clang/lib/Lex/PPMacroExpansion.cpp (+10-3) 
- (modified) clang/test/C/C2x/n2975.c (+2-2) 
- (modified) clang/test/Lexer/gnu-flags.c (-2) 
- (modified) clang/test/Preprocessor/empty_va_arg.cpp (+11-7) 
- (modified) clang/test/Preprocessor/macro_fn.c (+2-2) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0ff4a93b15ea8f..ffc88e79961ce6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -212,6 +212,9 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses lambda function expressions being implicitly cast to 
boolean values, under ``-Wpointer-bool-conversion``.
   Fixes #GH82512.
 
+- Clang now correctly diagnoses no arguments to a variadic macro parameter as 
a C23/C++20 extension.
+  Fixes #GH84495.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index d7c172e6546351..ad6bacfb118d49 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -465,9 +465,16 @@ def err_embedded_directive : Error<
 def ext_embedded_directive : Extension<
   "embedding a directive within macro arguments has undefined behavior">,
   InGroup>;
-def ext_missing_varargs_arg : Extension<
-  "must specify at least one argument for '...' parameter of variadic macro">,
-  InGroup;
+def ext_c_missing_varargs_arg : Extension<
+  "passing no argument for the '...' parameter of a variadic macro is "
+  "a C23 extension">, InGroup;
+def ext_cxx_missing_varargs_arg : Extension<
+  "passing no argument for the '...' parameter of a variadic macro is "
+  "a C++20 extension">, InGroup;
+def warn_c17_compat_missing_varargs_arg : Warning<
+  "passing no argument for the '...' parameter of a variadic macro is "
+  "incompatible with C standards before C23">,
+  InGroup, DefaultIgnore;
 def warn_cxx17_compat_missing_varargs_arg : Warning<
   "passing no argument for the '...' parameter of a variadic macro is "
   "incompatible with C++ standards before C++20">,
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 3017461dc66e86..3cde001e84760e 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -995,9 +995,16 @@ MacroArgs *Preprocessor::ReadMacroCallArgumentList(Token 
&MacroName,
   if (!MI->hasCommaPasting()) {
 // C++20 allows this construct, but standards before C++20 and all C
 // standards do not allow the construct (we allow it as an extension).
-Diag(Tok, getLangOpts().CPlusPlus20
-  ? diag::warn_cxx17_compat_missing_varargs_arg
-  : diag::ext_missing_varargs_arg);
+unsigned ID;
+if (getLangOpts().CPlusPlus20)
+  ID = diag::warn_cxx17_compat_missing_varargs_arg;
+else if (getLangOpts().CPlusPlus)
+  ID = diag::ext_cxx_missing_varargs_arg;
+else if (getLangOpts().C23)
+  ID = diag::warn_c17_compat_missing_varargs_arg;
+else
+  ID = diag::ext_c_missing_varargs_arg;
+Diag(Tok, ID);
 Diag(MI->getDefinitionLoc(), diag::note_macro_here)
   << MacroName.getIdentifierInfo();
   }
diff --git a/clang/test/C/C2x/n2975.c b/clang/test/C/C2x/n2975.c
index 5fc641dd66e781..2269400fe47c34 100644
--- a/clang/test/C/C2x/n2975.c
+++ b/clang/test/C/C2x/n2975.c
@@ -11,7 +11,7 @@
 void func(...) { // expected-warning {{'...' as the only parameter of a 
function is incompatible with C standards before C23}}
   // Show that va_start doesn't require the second argument in C23 mode.
   va_list list;
-  va_start(list); // FIXME: it would be nice to issue a portability warning to 
C17 and earlier here.
+  va_start(list); // expected-warning {{passing no argument for the '...' 
parameter of a variadic macro is incompatible with C standards before C23}} 
expected-note@* {{macro 'va_start' defined here}}
   va_end(list);
 
   // Show that va_start doesn't expand or evaluate the second argument.
@@ -26,7 +26,7 @@ void func(...) { // expected-warning {{'...' as the only 
parameter of a function
   __builtin_va_start(list); // expected-error {{too few arguments to function 
call, expected 2, have 1}}
 
   // Verify that the return type of a call to va_start is 'void'.
-  _Static_assert(__builtin_types_compatible_p(__typeof__(va_start(list)), 
void), "");
+  _Static_assert(__builtin

[clang] [Clang] Update missing varargs arg extension warnings (PR #84520)

2024-03-08 Thread via cfe-commits

https://github.com/Sirraide created 
https://github.com/llvm/llvm-project/pull/84520

This updates a few warnings that were diagnosing no arguments for a `...` 
variadic macro parameter as a GNU extension when it actually is a C++20/C23 
extension now.

This fixes #84495.

>From 502692869e3105bb2c55955bc4baff63b1475770 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Fri, 8 Mar 2024 18:15:07 +0100
Subject: [PATCH] [Clang] Update missing varargs arg extension warnings

---
 clang/docs/ReleaseNotes.rst|  3 +++
 .../include/clang/Basic/DiagnosticLexKinds.td  | 13 ++---
 clang/lib/Lex/PPMacroExpansion.cpp | 13 ++---
 clang/test/C/C2x/n2975.c   |  4 ++--
 clang/test/Lexer/gnu-flags.c   |  2 --
 clang/test/Preprocessor/empty_va_arg.cpp   | 18 +++---
 clang/test/Preprocessor/macro_fn.c |  4 ++--
 7 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0ff4a93b15ea8f..ffc88e79961ce6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -212,6 +212,9 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses lambda function expressions being implicitly cast to 
boolean values, under ``-Wpointer-bool-conversion``.
   Fixes #GH82512.
 
+- Clang now correctly diagnoses no arguments to a variadic macro parameter as 
a C23/C++20 extension.
+  Fixes #GH84495.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index d7c172e6546351..ad6bacfb118d49 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -465,9 +465,16 @@ def err_embedded_directive : Error<
 def ext_embedded_directive : Extension<
   "embedding a directive within macro arguments has undefined behavior">,
   InGroup>;
-def ext_missing_varargs_arg : Extension<
-  "must specify at least one argument for '...' parameter of variadic macro">,
-  InGroup;
+def ext_c_missing_varargs_arg : Extension<
+  "passing no argument for the '...' parameter of a variadic macro is "
+  "a C23 extension">, InGroup;
+def ext_cxx_missing_varargs_arg : Extension<
+  "passing no argument for the '...' parameter of a variadic macro is "
+  "a C++20 extension">, InGroup;
+def warn_c17_compat_missing_varargs_arg : Warning<
+  "passing no argument for the '...' parameter of a variadic macro is "
+  "incompatible with C standards before C23">,
+  InGroup, DefaultIgnore;
 def warn_cxx17_compat_missing_varargs_arg : Warning<
   "passing no argument for the '...' parameter of a variadic macro is "
   "incompatible with C++ standards before C++20">,
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 3017461dc66e86..3cde001e84760e 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -995,9 +995,16 @@ MacroArgs *Preprocessor::ReadMacroCallArgumentList(Token 
&MacroName,
   if (!MI->hasCommaPasting()) {
 // C++20 allows this construct, but standards before C++20 and all C
 // standards do not allow the construct (we allow it as an extension).
-Diag(Tok, getLangOpts().CPlusPlus20
-  ? diag::warn_cxx17_compat_missing_varargs_arg
-  : diag::ext_missing_varargs_arg);
+unsigned ID;
+if (getLangOpts().CPlusPlus20)
+  ID = diag::warn_cxx17_compat_missing_varargs_arg;
+else if (getLangOpts().CPlusPlus)
+  ID = diag::ext_cxx_missing_varargs_arg;
+else if (getLangOpts().C23)
+  ID = diag::warn_c17_compat_missing_varargs_arg;
+else
+  ID = diag::ext_c_missing_varargs_arg;
+Diag(Tok, ID);
 Diag(MI->getDefinitionLoc(), diag::note_macro_here)
   << MacroName.getIdentifierInfo();
   }
diff --git a/clang/test/C/C2x/n2975.c b/clang/test/C/C2x/n2975.c
index 5fc641dd66e781..2269400fe47c34 100644
--- a/clang/test/C/C2x/n2975.c
+++ b/clang/test/C/C2x/n2975.c
@@ -11,7 +11,7 @@
 void func(...) { // expected-warning {{'...' as the only parameter of a 
function is incompatible with C standards before C23}}
   // Show that va_start doesn't require the second argument in C23 mode.
   va_list list;
-  va_start(list); // FIXME: it would be nice to issue a portability warning to 
C17 and earlier here.
+  va_start(list); // expected-warning {{passing no argument for the '...' 
parameter of a variadic macro is incompatible with C standards before C23}} 
expected-note@* {{macro 'va_start' defined here}}
   va_end(list);
 
   // Show that va_start doesn't expand or evaluate the second argument.
@@ -26,7 +26,7 @@ void func(...) { // expected-warning {{'...' as the only 
parameter of a function
   __builtin_va_start(list); // expected-error {{too few arguments to function 
call, expec