[PATCH] D124534: Add a diagnostic for line directive of a gnu extension
Ken Matsui via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 28 15:28:20 PDT 2022
ken-matsui updated this revision to Diff 425916.
ken-matsui added a comment.
Add a diagnostic for line directive of a gnu extension
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124534/new/
https://reviews.llvm.org/D124534
Files:
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/PPDirectives.cpp
clang/test/Misc/warning-flags.c
clang/test/Preprocessor/line-directive.c
Index: clang/test/Preprocessor/line-directive.c
===================================================================
--- clang/test/Preprocessor/line-directive.c
+++ clang/test/Preprocessor/line-directive.c
@@ -9,7 +9,7 @@
# 20 "" 2
// a push/pop before any other line control
-# 10 "enter-0" 1
+# 10 "enter-0" 1 // expected-warning {{this style of line directive is a GNU extension}}
# 11 "" 2 // pop to main file
#error MAIN7
// expected-error at -1{{MAIN7}}
@@ -30,7 +30,7 @@
# 42 // expected-warning {{this style of line directive is a GNU extension}}
# 42 "foo" // expected-warning {{this style of line directive is a GNU extension}}
# 42 "foo" 2 // expected-error {{invalid line marker flag '2': cannot pop empty include stack}}
-# 42 "foo" 1 3 // enter
+# 42 "foo" 1 3 // enter expected-warning {{this style of line directive is a GNU extension}}
# 42 "foo" 2 3 // exit
# 42 "foo" 2 3 4 // expected-error {{invalid line marker flag '2': cannot pop empty include stack}}
# 42 "foo" 3 4
@@ -116,8 +116,8 @@
undefined t; // expected-error {{unknown type name 'undefined'}}
# 115 "main" // expected-warning {{this style of line directive is a GNU extension}}
-# 116 "enter-1" 1
-# 117 "enter-2" 1
+# 116 "enter-1" 1 // expected-warning {{this style of line directive is a GNU extension}}
+# 117 "enter-2" 1 // expected-warning {{this style of line directive is a GNU extension}}
# 118 "" 2 // pop to enter-1
#error ENTER1
// expected-error at -1{{ENTER1}}
Index: clang/test/Misc/warning-flags.c
===================================================================
--- clang/test/Misc/warning-flags.c
+++ clang/test/Misc/warning-flags.c
@@ -90,4 +90,4 @@
The list of warnings in -Wpedantic should NEVER grow.
-CHECK: Number in -Wpedantic (not covered by other -W flags): 28
+CHECK: Number in -Wpedantic (not covered by other -W flags): 27
Index: clang/lib/Lex/PPDirectives.cpp
===================================================================
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -1346,9 +1346,14 @@
IsFileEntry = true;
PP.Lex(FlagTok);
- if (FlagTok.is(tok::eod)) return false;
+ if (FlagTok.is(tok::eod)) {
+ PP.Diag(FlagTok, diag::ext_pp_gnu_line_directive);
+ return false;
+ }
if (GetLineValue(FlagTok, FlagVal, diag::err_pp_linemarker_invalid_flag,PP))
return true;
+
+ PP.Diag(FlagTok, diag::ext_pp_gnu_line_directive);
} else if (FlagVal == 2) {
IsFileExit = true;
Index: clang/include/clang/Basic/DiagnosticLexKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticLexKinds.td
+++ clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -428,7 +428,8 @@
"variadic macros are a Clang extension in OpenCL">;
def ext_pp_gnu_line_directive : Extension<
- "this style of line directive is a GNU extension">;
+ "this style of line directive is a GNU extension">,
+ InGroup<GNULineMarker>;
def err_pp_invalid_directive : Error<"invalid preprocessing directive">;
def err_pp_directive_required : Error<
Index: clang/include/clang/Basic/DiagnosticGroups.td
===================================================================
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -450,6 +450,7 @@
def : DiagGroup<"inline">;
def : DiagGroup<"invalid-pch">;
def GNULabelsAsValue : DiagGroup<"gnu-label-as-value">;
+def GNULineMarker : DiagGroup<"gnu-line-marker">;
def LiteralRange : DiagGroup<"literal-range">;
def LocalTypeTemplateArgs : DiagGroup<"local-type-template-args",
[CXX98CompatLocalTypeTemplateArgs]>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124534.425916.patch
Type: text/x-patch
Size: 3691 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220428/cbf6ac9b/attachment.bin>
More information about the cfe-commits
mailing list