]> granicus.if.org Git - clang/commitdiff
PR16339: Don't produce a diagnostic pointing at the whitespace between a '#if'
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 16 Jun 2013 05:05:39 +0000 (05:05 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 16 Jun 2013 05:05:39 +0000 (05:05 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184054 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp
test/Lexer/Inputs/bad-header-guard-defined.h [new file with mode: 0644]
test/Lexer/header.cpp

index 0cfdac92d23ab2fea35eba489604d68ad684ecbf..3e3312a9261a60f7c78bd821ee482890f89071bc 100644 (file)
@@ -2132,7 +2132,8 @@ void Preprocessor::HandleIfDirective(Token &IfToken,
   // 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();
   }
diff --git a/test/Lexer/Inputs/bad-header-guard-defined.h b/test/Lexer/Inputs/bad-header-guard-defined.h
new file mode 100644 (file)
index 0000000..b28f1a8
--- /dev/null
@@ -0,0 +1,4 @@
+#if !defined(foo)
+#define goo
+int n;
+#endif
index 278ff2e4323799a1e2a14657546531dcadd81187..047240ac0f7a9cb0871300590344535395423d55 100644 (file)
 // 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.