r190017 - Add specific warning flags for GNU ext in lexer.

Eli Friedman eli.friedman at gmail.com
Wed Sep 4 17:02:30 PDT 2013


Author: efriedma
Date: Wed Sep  4 19:02:30 2013
New Revision: 190017

URL: http://llvm.org/viewvc/llvm-project?rev=190017&view=rev
Log:
Add specific warning flags for GNU ext in lexer.

This patch adds the following flags covering existing warnings:

-Wgnu-zero-variadic-macro-arguments
-Wgnu-imaginary-constant
-Wgnu-binary-literal
-Wgnu-zero-line-directive

Patch by Peter Lewis.

Added:
    cfe/trunk/test/Lexer/gnu-flags.c
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td
    cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=190017&r1=190016&r2=190017&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Wed Sep  4 19:02:30 2013
@@ -28,6 +28,7 @@ def ArrayBoundsPointerArithmetic : DiagG
 def Availability : DiagGroup<"availability">;
 def Section : DiagGroup<"section">;
 def AutoImport : DiagGroup<"auto-import">;
+def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
 def BitFieldConstantConversion : DiagGroup<"bitfield-constant-conversion">;
 def ConstantConversion :
   DiagGroup<"constant-conversion", [ BitFieldConstantConversion ] >;
@@ -152,6 +153,7 @@ def OverloadedShiftOpParentheses: DiagGr
 def DanglingElse: DiagGroup<"dangling-else">;
 def DanglingField : DiagGroup<"dangling-field">;
 def DistributedObjectModifiers : DiagGroup<"distributed-object-modifiers">;
+def GNUImaginaryConstant : DiagGroup<"gnu-imaginary-constant">;
 def IgnoredQualifiers : DiagGroup<"ignored-qualifiers">;
 def : DiagGroup<"import">;
 def IncompatiblePointerTypesDiscardsQualifiers 
@@ -369,6 +371,8 @@ def VLAExtension : DiagGroup<"vla-extens
 def VolatileRegisterVar : DiagGroup<"volatile-register-var">;
 def Visibility : DiagGroup<"visibility">;
 def ZeroLengthArray : DiagGroup<"zero-length-array">;
+def GNUZeroLineDirective : DiagGroup<"gnu-zero-line-directive">;
+def GNUZeroVariadicMacroArguments : DiagGroup<"gnu-zero-variadic-macro-arguments">;
 
 // GCC calls -Wdeprecated-writable-strings -Wwrite-strings.
 def GCCWriteStrings : DiagGroup<"write-strings" , [DeprecatedWritableStr]>;
@@ -535,14 +539,15 @@ def C11 : DiagGroup<"c11-extensions">;
 def C99 : DiagGroup<"c99-extensions">;
 
 // A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUCaseRange,
-                            GNUComplexInteger,
+def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUBinaryLiteral,
+                            GNUCaseRange, GNUComplexInteger,
                             GNUConditionalOmittedOperand,
                             GNUDesignator, GNUEmptyInitializer,
                             VLAExtension,
-                            GNULabelsAsValue,
+                            GNUImaginaryConstant, GNULabelsAsValue,
                             GNUStatementExpression, GNUStaticFloatInit,
-                            ZeroLengthArray]>;
+                            ZeroLengthArray,
+                            GNUZeroLineDirective, GNUZeroVariadicMacroArguments]>;
 // A warning group for warnings about code that clang accepts but gcc doesn't.
 def GccCompat : DiagGroup<"gcc-compat">;
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=190017&r1=190016&r2=190017&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Wed Sep  4 19:02:30 2013
@@ -167,7 +167,7 @@ def err_multichar_utf_character_literal
   "Unicode character literals may not contain multiple characters">;
 def err_exponent_has_no_digits : Error<"exponent has no digits">;
 def ext_imaginary_constant : Extension<
-  "imaginary constants are a GNU extension">, InGroup<GNU>;
+  "imaginary constants are a GNU extension">, InGroup<GNUImaginaryConstant>;
 def err_hexconstant_requires_exponent : Error<
   "hexadecimal floating constants require an exponent">;
 def err_hexconstant_requires_digits : Error<
@@ -175,7 +175,7 @@ def err_hexconstant_requires_digits : Er
 def ext_hexconstant_invalid : Extension<
   "hexadecimal floating constants are a C99 feature">, InGroup<C99>;
 def ext_binary_literal : Extension<
-  "binary integer literals are a GNU extension">, InGroup<GNU>;
+  "binary integer literals are a GNU extension">, InGroup<GNUBinaryLiteral>;
 def ext_binary_literal_cxx1y : Extension<
   "binary integer literals are a C++1y extension">, InGroup<CXX1y>;
 def warn_cxx11_compat_binary_literal : Warning<
@@ -322,7 +322,7 @@ def ext_embedded_directive : Extension<
   InGroup<DiagGroup<"embedded-directive">>;
 def ext_missing_varargs_arg : Extension<
   "must specify at least one argument for '...' parameter of variadic macro">,
-  InGroup<GNU>;
+  InGroup<GNUZeroVariadicMacroArguments>;
 def ext_empty_fnmacro_arg : Extension<
   "empty macro arguments are a C99 feature">, InGroup<C99>;
 def warn_cxx98_compat_empty_fnmacro_arg : Warning<
@@ -457,7 +457,7 @@ def err_paste_at_start : Error<
   "'##' cannot appear at start of macro expansion">;
 def err_paste_at_end : Error<"'##' cannot appear at end of macro expansion">;
 def ext_paste_comma : Extension<
-  "token pasting of ',' and __VA_ARGS__ is a GNU extension">, InGroup<GNU>;
+  "token pasting of ',' and __VA_ARGS__ is a GNU extension">, InGroup<GNUZeroVariadicMacroArguments>;
 def err_unterm_macro_invoc : Error<
   "unterminated function-like macro invocation">;
 def err_too_many_args_in_macro_invoc : Error<
@@ -482,7 +482,7 @@ def err_pp_line_requires_integer : Error
   "#line directive requires a positive integer argument">;
 def ext_pp_line_zero : Extension<
   "#line directive with zero argument is a GNU extension">, 
-  InGroup<GNU>;
+  InGroup<GNUZeroLineDirective>;
 def err_pp_line_invalid_filename : Error<
   "invalid filename for #line directive">;
 def warn_pp_line_decimal : Warning<

Added: cfe/trunk/test/Lexer/gnu-flags.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/gnu-flags.c?rev=190017&view=auto
==============================================================================
--- cfe/trunk/test/Lexer/gnu-flags.c (added)
+++ cfe/trunk/test/Lexer/gnu-flags.c Wed Sep  4 19:02:30 2013
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -DNONE
+// RUN: %clang_cc1 -fsyntax-only -verify %s -DALL -Wgnu 
+// RUN: %clang_cc1 -fsyntax-only -verify %s -DALL \
+// RUN:   -Wgnu-zero-variadic-macro-arguments \
+// RUN:   -Wgnu-imaginary-constant -Wgnu-binary-literal -Wgnu-zero-line-directive
+// RUN: %clang_cc1 -fsyntax-only -verify %s -DNONE -Wgnu \
+// RUN:   -Wno-gnu-zero-variadic-macro-arguments \
+// RUN:   -Wno-gnu-imaginary-constant -Wno-gnu-binary-literal -Wno-gnu-zero-line-directive
+// Additional disabled tests:
+// %clang_cc1 -fsyntax-only -verify %s -DZEROARGS -Wgnu-zero-variadic-macro-arguments
+// %clang_cc1 -fsyntax-only -verify %s -DIMAGINARYCONST -Wgnu-imaginary-constant
+// %clang_cc1 -fsyntax-only -verify %s -DBINARYLITERAL -Wgnu-binary-literal
+// %clang_cc1 -fsyntax-only -verify %s -DLINE0 -Wgnu-zero-line-directive
+
+#if NONE
+// expected-no-diagnostics
+#endif
+
+
+#if ALL || ZEROARGS
+// expected-warning at +9 {{must specify at least one argument for '...' parameter of variadic macro}}
+// expected-note at +4 {{macro 'efoo' defined here}}
+// expected-warning at +3 {{token pasting of ',' and __VA_ARGS__ is a GNU extension}}
+#endif
+
+#define efoo(format, args...) foo(format , ##args)
+
+void foo( const char* c )
+{
+  efoo("6");
+}
+
+
+#if ALL || IMAGINARYCONST
+// expected-warning at +3 {{imaginary constants are a GNU extension}}
+#endif
+
+float _Complex c = 1.if;
+
+
+#if ALL || BINARYLITERAL
+// expected-warning at +3 {{binary integer literals are a GNU extension}}
+#endif
+
+int b = 0b0101;
+
+
+// This case is handled differently because lit has a bug whereby #line 0 is reported to be on line 4294967295
+// http://llvm.org/bugs/show_bug.cgi?id=16952
+#if ALL || LINE0
+#line 0 // expected-warning {{#line directive with zero argument is a GNU extension}}
+#else
+#line 0
+#endif
+
+// WARNING: Do not add more tests after the #line 0 line!  Add them before the LINE0 test





More information about the cfe-commits mailing list