Skip to content

Commit 07f8e51

Browse files
ahatanakahatanaka
authored andcommitted
Define a diagnostic group for missing variadic macro arguments (llvm#116855)
Make the new diagnostic group a subgroup of the following diagnostic groups: -Wpre-c23-compat -Wgnu-zero-variadic-macro-arguments -Wc++20-extensions -Wc23-extensions This change is needed as 5231005 made it impossible to use -Wno-gnu-zero-variadic-macro-argumentsis to silence the warning. rdar://139234984 (cherry picked from commit c8b7ec2)
1 parent 7362728 commit 07f8e51

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,13 @@ def : DiagGroup<"c++1z-compat-mangling", [CXX17CompatMangling]>;
291291
// Name of this warning in GCC.
292292
def NoexceptType : DiagGroup<"noexcept-type", [CXX17CompatMangling]>;
293293

294+
def VariadicMacroArgumentsOmitted : DiagGroup<"variadic-macro-arguments-omitted">;
295+
294296
// Warnings for C code which is not compatible with previous C standards.
295297
def CPre11Compat : DiagGroup<"pre-c11-compat">;
296298
def CPre11CompatPedantic : DiagGroup<"pre-c11-compat-pedantic",
297299
[CPre11Compat]>;
298-
def CPre23Compat : DiagGroup<"pre-c23-compat">;
300+
def CPre23Compat : DiagGroup<"pre-c23-compat", [VariadicMacroArgumentsOmitted]>;
299301
def CPre23CompatPedantic : DiagGroup<"pre-c23-compat-pedantic",
300302
[CPre23Compat]>;
301303
def : DiagGroup<"pre-c2x-compat", [CPre23Compat]>;
@@ -900,7 +902,7 @@ def VolatileRegisterVar : DiagGroup<"volatile-register-var">;
900902
def Visibility : DiagGroup<"visibility">;
901903
def ZeroLengthArray : DiagGroup<"zero-length-array">;
902904
def GNUZeroLineDirective : DiagGroup<"gnu-zero-line-directive">;
903-
def GNUZeroVariadicMacroArguments : DiagGroup<"gnu-zero-variadic-macro-arguments">;
905+
def GNUZeroVariadicMacroArguments : DiagGroup<"gnu-zero-variadic-macro-arguments", [VariadicMacroArgumentsOmitted]>;
904906
def MisleadingIndentation : DiagGroup<"misleading-indentation">;
905907
def PtrAuthNullPointers : DiagGroup<"ptrauth-null-pointers">;
906908

@@ -1193,7 +1195,7 @@ def CXX17 : DiagGroup<"c++17-extensions", [CXX17Attrs]>;
11931195

11941196
// A warning group for warnings about using C++20 features as extensions in
11951197
// earlier C++ versions.
1196-
def CXX20 : DiagGroup<"c++20-extensions", [CXX20Designator, CXX20Attrs]>;
1198+
def CXX20 : DiagGroup<"c++20-extensions", [CXX20Designator, CXX20Attrs, VariadicMacroArgumentsOmitted]>;
11971199

11981200
// A warning group for warnings about using C++23 features as extensions in
11991201
// earlier C++ versions.
@@ -1220,7 +1222,7 @@ def C11 : DiagGroup<"c11-extensions">;
12201222
def C99 : DiagGroup<"c99-extensions", [C99Designator]>;
12211223

12221224
// A warning group for warnings about using C23 features as extensions.
1223-
def C23 : DiagGroup<"c23-extensions">;
1225+
def C23 : DiagGroup<"c23-extensions", [VariadicMacroArgumentsOmitted]>;
12241226

12251227
def : DiagGroup<"c2x-extensions", [C23]>;
12261228

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,14 @@ def ext_embedded_directive : Extension<
483483
InGroup<DiagGroup<"embedded-directive">>;
484484
def ext_c_missing_varargs_arg : Extension<
485485
"passing no argument for the '...' parameter of a variadic macro is "
486-
"a C23 extension">, InGroup<C23>;
486+
"a C23 extension">, InGroup<VariadicMacroArgumentsOmitted>;
487487
def ext_cxx_missing_varargs_arg : Extension<
488488
"passing no argument for the '...' parameter of a variadic macro is "
489-
"a C++20 extension">, InGroup<CXX20>;
489+
"a C++20 extension">, InGroup<VariadicMacroArgumentsOmitted>;
490490
def warn_c17_compat_missing_varargs_arg : Warning<
491491
"passing no argument for the '...' parameter of a variadic macro is "
492492
"incompatible with C standards before C23">,
493-
InGroup<CPre23Compat>, DefaultIgnore;
493+
InGroup<VariadicMacroArgumentsOmitted>, DefaultIgnore;
494494
def warn_cxx17_compat_missing_varargs_arg : Warning<
495495
"passing no argument for the '...' parameter of a variadic macro is "
496496
"incompatible with C++ standards before C++20">,

clang/test/Lexer/gnu-flags.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818

1919
#if ALL || ZEROARGS
20+
// expected-warning@+9 {{passing no argument for the '...' parameter of a variadic macro is a C23 extension}}
21+
// expected-note@+4 {{macro 'efoo' defined here}}
2022
// expected-warning@+3 {{token pasting of ',' and __VA_ARGS__ is a GNU extension}}
2123
#endif
2224

clang/test/Preprocessor/macro_fn.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
/* RUN: %clang_cc1 %s -Eonly -std=c89 -pedantic -verify
22
*/
3+
// RUN: %clang_cc1 %s -Eonly -std=c89 -pedantic -Wno-gnu-zero-variadic-macro-arguments -verify -DOMIT_VARIADIC_MACRO_ARGS -DVARIADIC_MACRO_ARGS_REMOVE_COMMA
4+
// RUN: %clang_cc1 %s -Eonly -std=c89 -pedantic -Wno-variadic-macro-arguments-omitted -verify -DOMIT_VARIADIC_MACRO_ARGS
35
/* PR3937 */
46
#define zero() 0 /* expected-note 2 {{defined here}} */
57
#define one(x) 0 /* expected-note 2 {{defined here}} */
68
#define two(x, y) 0 /* expected-note 4 {{defined here}} */
79
#define zero_dot(...) 0 /* expected-warning {{variadic macros are a C99 feature}} */
8-
#define one_dot(x, ...) 0 /* expected-warning {{variadic macros are a C99 feature}} expected-note 2{{macro 'one_dot' defined here}} */
10+
#define one_dot(x, ...) 0 /* expected-warning {{variadic macros are a C99 feature}} */
11+
12+
#ifndef OMIT_VARIADIC_MACRO_ARGS
13+
/* expected-note@-3 2{{macro 'one_dot' defined here}} */
14+
#endif
915

1016
zero()
1117
zero(1); /* expected-error {{too many arguments provided to function-like macro invocation}} */
@@ -37,16 +43,24 @@ e(x)
3743
e()
3844

3945
zero_dot()
40-
one_dot(x) /* empty ... argument: expected-warning {{passing no argument for the '...' parameter of a variadic macro is a C23 extension}} */
41-
one_dot() /* empty first argument, elided ...: expected-warning {{passing no argument for the '...' parameter of a variadic macro is a C23 extension}} */
46+
one_dot(x) /* empty ... argument */
47+
one_dot() /* empty first argument, elided ... */
4248

49+
#ifndef OMIT_VARIADIC_MACRO_ARGS
50+
/* expected-warning@-4 {{passing no argument for the '...' parameter of a variadic macro is a C23 extension}} */
51+
/* expected-warning@-4 {{passing no argument for the '...' parameter of a variadic macro is a C23 extension}} */
52+
#endif
4353

4454
/* Crash with function-like macro test at end of directive. */
4555
#define E() (i == 0)
4656
#if E
4757
#endif
4858

49-
5059
#define NSAssert(condition, desc, ...) /* expected-warning {{variadic macros are a C99 feature}} */ \
51-
SomeComplicatedStuff((desc), ##__VA_ARGS__) /* expected-warning {{token pasting of ',' and __VA_ARGS__ is a GNU extension}} */
60+
SomeComplicatedStuff((desc), ##__VA_ARGS__)
61+
62+
#ifndef VARIADIC_MACRO_ARGS_REMOVE_COMMA
63+
/* expected-warning@-3 {{token pasting of ',' and __VA_ARGS__ is a GNU extension}} */
64+
#endif
65+
5266
NSAssert(somecond, somedesc)

0 commit comments

Comments
 (0)