aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Lex/PPDirectives.cpp14
-rw-r--r--test/Preprocessor/include-macros.c4
-rw-r--r--tools/clang-cc/clang-cc.cpp3
3 files changed, 17 insertions, 4 deletions
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index 034d484a93..ba321a7f67 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -1050,8 +1050,7 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok,
return;
}
- // Verify that there is nothing after the filename, other than EOM. Use the
- // preprocessor to lex this in case lexing the filename entered a macro.
+ // Verify that there is nothing after the filename, other than EOM.
CheckEndOfDirective("#include");
// Check that we don't have infinite #include recursion.
@@ -1141,8 +1140,15 @@ void Preprocessor::HandleIncludeMacrosDirective(Token &IncludeMacrosTok) {
return;
}
- // TODO: implement me :)
- DiscardUntilEndOfDirective();
+ // Treat this as a normal #include for checking purposes. If this is
+ // successful, it will push a new lexer onto the include stack.
+ HandleIncludeDirective(IncludeMacrosTok, 0, false);
+
+ Token TmpTok;
+ do {
+ Lex(TmpTok);
+ assert(TmpTok.isNot(tok::eof) && "Didn't find end of -imacros!");
+ } while (TmpTok.isNot(tok::hashhash));
}
//===----------------------------------------------------------------------===//
diff --git a/test/Preprocessor/include-macros.c b/test/Preprocessor/include-macros.c
new file mode 100644
index 0000000000..c085e0c07e
--- /dev/null
+++ b/test/Preprocessor/include-macros.c
@@ -0,0 +1,4 @@
+// RUN: clang-cc -E -Dtest=FOO -imacros pr2086.h %s | grep 'HERE: test'
+
+// This should not be expanded into FOO because pr2086.h undefs 'test'.
+HERE: test
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index 3260a750a2..ea65c0f8cf 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -1029,6 +1029,9 @@ static void AddImplicitIncludeMacros(std::vector<char> &Buf,
Buf.insert(Buf.end(), EscapedFile.begin(), EscapedFile.end());
Buf.push_back('"');
Buf.push_back('\n');
+ // Marker token to stop the __include_macros fetch loop.
+ const char *Marker = "##\n"; // ##?
+ Buf.insert(Buf.end(), Marker, Marker+strlen(Marker));
}
/// AddImplicitIncludePTH - Add an implicit #include using the original file