[cfe-commits] r158883 - in /cfe/trunk: lib/Lex/PPDirectives.cpp test/Preprocessor/disabled-cond-diags2.c
Richard Smith
richard-llvm at metafoo.co.uk
Wed Jun 20 17:35:03 PDT 2012
Author: rsmith
Date: Wed Jun 20 19:35:03 2012
New Revision: 158883
URL: http://llvm.org/viewvc/llvm-project?rev=158883&view=rev
Log:
Do not complain about junk on the end of a #endif in a skipped block. Such junk
is permitted by all relevant language standards. Patch by Andy Gibbs!
Added:
cfe/trunk/test/Preprocessor/disabled-cond-diags2.c
Modified:
cfe/trunk/lib/Lex/PPDirectives.cpp
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=158883&r1=158882&r2=158883&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Jun 20 19:35:03 2012
@@ -317,7 +317,6 @@
} else if (Directive[0] == 'e') {
StringRef Sub = Directive.substr(1);
if (Sub == "ndif") { // "endif"
- CheckEndOfDirective("endif");
PPConditionalInfo CondInfo;
CondInfo.WasSkipping = true; // Silence bogus warning.
bool InCond = CurPPLexer->popConditionalLevel(CondInfo);
@@ -326,9 +325,12 @@
// If we popped the outermost skipping block, we're done skipping!
if (!CondInfo.WasSkipping) {
+ CheckEndOfDirective("endif");
if (Callbacks)
Callbacks->Endif(Tok.getLocation(), CondInfo.IfLoc);
break;
+ } else {
+ DiscardUntilEndOfDirective();
}
} else if (Sub == "lse") { // "else".
// #else directive in a skipping conditional. If not in some other
Added: cfe/trunk/test/Preprocessor/disabled-cond-diags2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/disabled-cond-diags2.c?rev=158883&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/disabled-cond-diags2.c (added)
+++ cfe/trunk/test/Preprocessor/disabled-cond-diags2.c Wed Jun 20 19:35:03 2012
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -Eonly -verify %s
+
+#if 0
+#if 1
+#endif junk // shouldn't produce diagnostics
+#endif
+
+#if 0
+#endif junk // expected-warning{{extra tokens at end of #endif directive}}
+
+#if 1 junk // expected-error{{token is not a valid binary operator in a preprocessor subexpression}}
+#X // shouldn't produce diagnostics (block #if condition not valid, so skipped)
+#else
+#X // expected-error{{invalid preprocessing directive}}
+#endif
+
+#if 0
+// diagnostics should not be produced until final #endif
+#X
+#include
+#if 1 junk
+#else junk
+#endif junk
+#line -2
+#error
+#warning
+#endif junk // expected-warning{{extra tokens at end of #endif directive}}
More information about the cfe-commits
mailing list