[PATCH] Add more specific lexer flags for misc GNU extensions

Peter N Lewis peter at stairways.com.au
Wed Aug 21 06:10:27 PDT 2013


Here is batch two of the specific gnu flags.  This patch adds the following flags:

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

I'm not overly convinced on the exact naming of the flags, but they were the best I could come up with. I'd be happy to hear any thoughts.

The patch includes a test with four invocations, and another five disabled by default.


Index: test/Lexer/gnu-flags.c
===================================================================
--- test/Lexer/gnu-flags.c	(revision 0)
+++ test/Lexer/gnu-flags.c	(revision 0)
@@ -0,0 +1,58 @@
+// 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 -Wgnu-token-pasting-comma \
+// RUN:   -Wgnu-imaginary-constant -Wgnu-binary-literal -Wgnu-line-zero-directive
+// RUN: %clang_cc1 -fsyntax-only -verify %s -DNONE -Wgnu \
+// RUN:   -Wno-gnu-zero-variadic-macro-arguments -Wno-gnu-token-pasting-comma \
+// RUN:   -Wno-gnu-imaginary-constant -Wno-gnu-binary-literal -Wno-gnu-line-zero-directive
+// RUNNOT: %clang_cc1 -fsyntax-only -verify %s -DZEROARGS -Wgnu-zero-variadic-macro-arguments
+// RUNNOT: %clang_cc1 -fsyntax-only -verify %s -DTOKENPASTING -Wgnu-token-pasting-comma
+// RUNNOT: %clang_cc1 -fsyntax-only -verify %s -DIMAGINARYCONST -Wgnu-imaginary-constant
+// RUNNOT: %clang_cc1 -fsyntax-only -verify %s -DBINARYLITERAL -Wgnu-binary-literal
+// RUNNOT: %clang_cc1 -fsyntax-only -verify %s -DLINE0 -Wgnu-line-zero-directive
+
+#if NONE
+// expected-no-diagnostics
+#endif
+
+
+#if ALL || ZEROARGS
+// expected-warning at +11 {{must specify at least one argument for '...' parameter of variadic macro}}
+// expected-note at +6 {{macro 'efoo' defined here}}
+#endif
+#if ALL || TOKENPASTING
+// 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
Index: include/clang/Basic/DiagnosticGroups.td
===================================================================
--- include/clang/Basic/DiagnosticGroups.td	(revision 188870)
+++ include/clang/Basic/DiagnosticGroups.td	(working copy)
@@ -28,6 +28,7 @@
 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 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 
@@ -168,6 +170,7 @@
 def : DiagGroup<"inline">;
 def : DiagGroup<"invalid-pch">;
 def GNULabelsAsValue : DiagGroup<"gnu-label-as-value">;
+def GNULineZeroDirective : DiagGroup<"gnu-line-zero-directive">;
 def LiteralRange : DiagGroup<"literal-range">;
 def LocalTypeTemplateArgs : DiagGroup<"local-type-template-args",
                                       [CXX98CompatLocalTypeTemplateArgs]>;
@@ -260,6 +263,7 @@
 def TautologicalOutOfRangeCompare : DiagGroup<"tautological-constant-out-of-range-compare">;
 def TautologicalCompare : DiagGroup<"tautological-compare",
                                     [TautologicalOutOfRangeCompare]>;
+def GNUTokenPastingComma : DiagGroup<"gnu-token-pasting-comma">;
 def HeaderHygiene : DiagGroup<"header-hygiene">;
 def DuplicateDeclSpecifier : DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
@@ -368,6 +372,7 @@
 def VolatileRegisterVar : DiagGroup<"volatile-register-var">;
 def Visibility : DiagGroup<"visibility">;
 def ZeroLengthArray : DiagGroup<"zero-length-array">;
+def GNUZeroVariadicMacroArguments : DiagGroup<"gnu-zero-variadic-macro-arguments">;
 
 // GCC calls -Wdeprecated-writable-strings -Wwrite-strings.
 def GCCWriteStrings : DiagGroup<"write-strings" , [DeprecatedWritableStr]>;
@@ -534,14 +539,15 @@
 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,
-                            GNUStatementExpression, GNUStaticFloatInit,
-                            ZeroLengthArray]>;
+                            GNUImaginaryConstant, GNULabelsAsValue,
+                            GNULineZeroDirective, GNUStatementExpression,
+                            GNUStaticFloatInit, GNUTokenPastingComma,
+                            ZeroLengthArray, GNUZeroVariadicMacroArguments]>;
 // A warning group for warnings about code that clang accepts but gcc doesn't.
 def GccCompat : DiagGroup<"gcc-compat">;
 
Index: include/clang/Basic/DiagnosticLexKinds.td
===================================================================
--- include/clang/Basic/DiagnosticLexKinds.td	(revision 188870)
+++ include/clang/Basic/DiagnosticLexKinds.td	(working copy)
@@ -165,7 +165,7 @@
   "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<
@@ -173,7 +173,7 @@
 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<
@@ -320,7 +320,7 @@
   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<
@@ -455,7 +455,7 @@
   "'##' 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<GNUTokenPastingComma>;
 def err_unterm_macro_invoc : Error<
   "unterminated function-like macro invocation">;
 def err_too_many_args_in_macro_invoc : Error<
@@ -480,7 +480,7 @@
   "#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<GNULineZeroDirective>;
 def err_pp_line_invalid_filename : Error<
   "invalid filename for #line directive">;
 def warn_pp_line_decimal : Warning<

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gnu-lex-flags.diff
Type: application/octet-stream
Size: 8175 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130821/8f979c87/attachment.obj>
-------------- next part --------------


-- 
Keyboard Maestro 6.1 now out - set web checkboxes & radio buttons, exit from loops, and more.

Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/>           <http://download.keyboardmaestro.com/>



More information about the cfe-commits mailing list