aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-17 23:37:49 +0000
committerChris Lattner <sabre@nondot.org>2009-04-17 23:37:49 +0000
commit58e91d57510a5ce4fd424fe7fd1cdfa86701ef35 (patch)
tree732b1fd8e5c9492b61bd5f6b960013a93cd224c9
parentab82f41b217ce588a9456c0b4411f219d3ed0df8 (diff)
implement PR3940: #line numbers not fully checked
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69403 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticLexKinds.td2
-rw-r--r--lib/Lex/PPDirectives.cpp5
-rw-r--r--test/Preprocessor/line-directive.c2
3 files changed, 9 insertions, 0 deletions
diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td
index 77406f5652..92e134963d 100644
--- a/include/clang/Basic/DiagnosticLexKinds.td
+++ b/include/clang/Basic/DiagnosticLexKinds.td
@@ -223,6 +223,8 @@ def err_pp_line_requires_integer : Error<
"#line directive requires a positive integer argument">;
def err_pp_line_invalid_filename : Error<
"invalid filename for #line directive">;
+def warn_pp_line_decimal : Warning<
+ "#line directive requires decimal line number">;
def err_pp_linemarker_requires_integer : Error<
"line marker directive requires a positive integer argument">;
def err_pp_linemarker_invalid_filename : Error<
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index ce86d0edca..2dfb6233bd 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -650,6 +650,11 @@ static bool GetLineValue(Token &DigitTok, unsigned &Val,
return true;
}
+ // Warn about hex and octal line numbers. Do this after the check for 0,
+ // because it is octal.
+ if (Literal.getRadix() != 10)
+ PP.Diag(DigitTok, diag::warn_pp_line_decimal);
+
return false;
}
diff --git a/test/Preprocessor/line-directive.c b/test/Preprocessor/line-directive.c
index 1dd8b292d2..8877406adc 100644
--- a/test/Preprocessor/line-directive.c
+++ b/test/Preprocessor/line-directive.c
@@ -68,3 +68,5 @@ typedef int w; // expected-error {{redefinition of typedef 'w' is invalid in C}
#line 2 "foo.c" EMPTY( )
#line 2 "foo.c" NONEMPTY( ) // expected-warning{{extra tokens at end of #line directive}}
+// PR3940
+#line 0xf // expected-warning {{#line directive requires decimal line number}}