r184054 - PR16339: Don't produce a diagnostic pointing at the whitespace between a '#if'
Richard Smith
richard-llvm at metafoo.co.uk
Sat Jun 15 22:05:39 PDT 2013
Author: rsmith
Date: Sun Jun 16 00:05:39 2013
New Revision: 184054
URL: http://llvm.org/viewvc/llvm-project?rev=184054&view=rev
Log:
PR16339: Don't produce a diagnostic pointing at the whitespace between a '#if'
and a '!defined(X)' if we find a broken header guard. This is suboptimal; we
should point the diagnostic at the 'X' token not the 'if' token, but it fixes
the crash.
Added:
cfe/trunk/test/Lexer/Inputs/bad-header-guard-defined.h
Modified:
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/test/Lexer/header.cpp
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=184054&r1=184053&r2=184054&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Sun Jun 16 00:05:39 2013
@@ -2132,7 +2132,8 @@ void Preprocessor::HandleIfDirective(Tok
// directive seen, handle it for the multiple-include optimization.
if (CurPPLexer->getConditionalStackDepth() == 0) {
if (!ReadAnyTokensBeforeDirective && IfNDefMacro && ConditionalTrue)
- CurPPLexer->MIOpt.EnterTopLevelIfndef(IfNDefMacro, ConditionalBegin);
+ // FIXME: Pass in the location of the macro name, not the 'if' token.
+ CurPPLexer->MIOpt.EnterTopLevelIfndef(IfNDefMacro, IfToken.getLocation());
else
CurPPLexer->MIOpt.EnterTopLevelConditional();
}
Added: cfe/trunk/test/Lexer/Inputs/bad-header-guard-defined.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/Inputs/bad-header-guard-defined.h?rev=184054&view=auto
==============================================================================
--- cfe/trunk/test/Lexer/Inputs/bad-header-guard-defined.h (added)
+++ cfe/trunk/test/Lexer/Inputs/bad-header-guard-defined.h Sun Jun 16 00:05:39 2013
@@ -0,0 +1,4 @@
+#if !defined(foo)
+#define goo
+int n;
+#endif
Modified: cfe/trunk/test/Lexer/header.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/header.cpp?rev=184054&r1=184053&r2=184054&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/header.cpp (original)
+++ cfe/trunk/test/Lexer/header.cpp Sun Jun 16 00:05:39 2013
@@ -17,6 +17,16 @@
// CHECK: {{^}} ^~~~~~~~~
// CHECK: {{^}} bad_header_guard
+#include "Inputs/bad-header-guard-defined.h"
+// CHECK: In file included from {{.*}}header.cpp:{{[0-9]*}}:
+// CHECK: {{.*}}bad-header-guard-defined.h:1:2: warning: 'foo' is used as a header guard here, followed by #define of a different macro
+// CHECK: {{^}}#if !defined(foo)
+// CHECK: {{^}} ^~
+// CHECK: {{.*}}bad-header-guard-defined.h:2:9: note: 'goo' is defined here; did you mean 'foo'?
+// CHECK: {{^}}#define goo
+// CHECK: {{^}} ^~~
+// CHECK: {{^}} foo
+
#include "Inputs/multiple.h"
#include "Inputs/multiple.h"
#include "Inputs/multiple.h"
@@ -30,4 +40,4 @@
// CHECK: {{^}} ^~~~~
// CHECK: {{^}} multiple
-// CHECK: 2 warnings generated.
+// CHECK: 3 warnings generated.
More information about the cfe-commits
mailing list