[cfe-commits] r168265 - in /cfe/trunk: lib/Lex/PPMacroExpansion.cpp test/Preprocessor/invalid-__has_warning1.c test/Preprocessor/invalid-__has_warning2.c test/Preprocessor/warning_tests.c
Andy Gibbs
andyg1001 at hotmail.co.uk
Sat Nov 17 11:14:53 PST 2012
Author: andyg
Date: Sat Nov 17 13:14:53 2012
New Revision: 168265
URL: http://llvm.org/viewvc/llvm-project?rev=168265&view=rev
Log:
Fix handling of invalid uses of the __has_warning builtin macro
Added:
cfe/trunk/test/Preprocessor/invalid-__has_warning1.c
cfe/trunk/test/Preprocessor/invalid-__has_warning2.c
Modified:
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/test/Preprocessor/warning_tests.c
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=168265&r1=168264&r2=168265&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Sat Nov 17 13:14:53 2012
@@ -1291,7 +1291,10 @@
StartLoc = Tok.getLocation();
IsValid = false;
// Eat tokens until ')'.
- do Lex(Tok); while (!(Tok.is(tok::r_paren) || Tok.is(tok::eod)));
+ while (Tok.isNot(tok::r_paren)
+ && Tok.isNot(tok::eod)
+ && Tok.isNot(tok::eof))
+ Lex(Tok);
break;
}
@@ -1342,7 +1345,8 @@
Diag(StartLoc, diag::err_warning_check_malformed);
OS << (int)Value;
- Tok.setKind(tok::numeric_constant);
+ if (IsValid)
+ Tok.setKind(tok::numeric_constant);
} else if (II == Ident__building_module) {
// The argument to this builtin should be an identifier. The
// builtin evaluates to 1 when that identifier names the module we are
Added: cfe/trunk/test/Preprocessor/invalid-__has_warning1.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/invalid-__has_warning1.c?rev=168265&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/invalid-__has_warning1.c (added)
+++ cfe/trunk/test/Preprocessor/invalid-__has_warning1.c Sat Nov 17 13:14:53 2012
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -verify %s
+
+// These must be the last lines in this test.
+// expected-error at +1{{requires a parenthesized string}} expected-error at +1 2{{expected}}
+int i = __has_warning(
Added: cfe/trunk/test/Preprocessor/invalid-__has_warning2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/invalid-__has_warning2.c?rev=168265&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/invalid-__has_warning2.c (added)
+++ cfe/trunk/test/Preprocessor/invalid-__has_warning2.c Sat Nov 17 13:14:53 2012
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -verify %s
+
+// These must be the last lines in this test.
+// expected-error at +1{{requires a parenthesized string}} expected-error at +1{{expected}}
+int i = __has_warning();
Modified: cfe/trunk/test/Preprocessor/warning_tests.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/warning_tests.c?rev=168265&r1=168264&r2=168265&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/warning_tests.c (original)
+++ cfe/trunk/test/Preprocessor/warning_tests.c Sat Nov 17 13:14:53 2012
@@ -11,7 +11,9 @@
#warning Should have -Wparentheses
#endif
-#if __has_warning(-Wfoo) // expected-error {{builtin warning check macro requires a parenthesized string}}
+// expected-error at +2 {{builtin warning check macro requires a parenthesized string}}
+// expected-error at +1 {{expected value in expression}}
+#if __has_warning(-Wfoo)
#endif
// expected-warning at +3 {{Not a valid warning flag}}
More information about the cfe-commits
mailing list