summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/PPDirectives.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2011-12-16 22:50:01 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2011-12-16 22:50:01 +0000
commiteb3ce7c3db7ae0238c3f3cfc61344623a1cc9ff0 (patch)
treea564422a5c8a8097a135534f19b8c2d6e0761e6b /clang/lib/Lex/PPDirectives.cpp
parentb6c9d56eb5d35e54e2e4d91463845b6ba9ebeac3 (diff)
downloadbcm5719-llvm-eb3ce7c3db7ae0238c3f3cfc61344623a1cc9ff0.tar.gz
bcm5719-llvm-eb3ce7c3db7ae0238c3f3cfc61344623a1cc9ff0.zip
Don't allow #include (and its friends #import, #include_next and
#__include_macros) in the arguments of a function-style macro. Directives in the arguments of such macros have undefined behaviour, and GCC does not correctly support these cases. In some situations, this can lead to better diagnostics. llvm-svn: 146765
Diffstat (limited to 'clang/lib/Lex/PPDirectives.cpp')
-rw-r--r--clang/lib/Lex/PPDirectives.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index ba65c29e69b..7c8bfd7e7cd 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -577,9 +577,25 @@ void Preprocessor::HandleDirective(Token &Result) {
// A(abc
// #warning blah
// def)
- // If so, the user is relying on non-portable behavior, emit a diagnostic.
- if (InMacroArgs)
+ // If so, the user is relying on undefined behavior, emit a diagnostic. Do
+ // not support this for #include-like directives, since that can result in
+ // terrible diagnostics, and does not work in GCC.
+ if (InMacroArgs) {
+ if (IdentifierInfo *II = Result.getIdentifierInfo()) {
+ switch (II->getPPKeywordID()) {
+ case tok::pp_include:
+ case tok::pp_import:
+ case tok::pp_include_next:
+ case tok::pp___include_macros:
+ Diag(Result, diag::err_embedded_include) << II->getName();
+ DiscardUntilEndOfDirective();
+ return;
+ default:
+ break;
+ }
+ }
Diag(Result, diag::ext_embedded_directive);
+ }
TryAgain:
switch (Result.getKind()) {
OpenPOWER on IntegriCloud