aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/PPMacroExpansion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Lex/PPMacroExpansion.cpp')
-rw-r--r--lib/Lex/PPMacroExpansion.cpp52
1 files changed, 35 insertions, 17 deletions
diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp
index 687b9a9d3b7b..dfbcaedcacff 100644
--- a/lib/Lex/PPMacroExpansion.cpp
+++ b/lib/Lex/PPMacroExpansion.cpp
@@ -804,7 +804,7 @@ MacroArgs *Preprocessor::ReadMacroCallArgumentList(Token &MacroName,
return nullptr;
}
// Do not lose the EOF/EOD.
- auto Toks = llvm::make_unique<Token[]>(1);
+ auto Toks = std::make_unique<Token[]>(1);
Toks[0] = Tok;
EnterTokenStream(std::move(Toks), 1, true, /*IsReinject*/ false);
break;
@@ -1210,19 +1210,20 @@ static bool EvaluateHasIncludeCommon(Token &Tok,
// Search include directories.
const DirectoryLookup *CurDir;
- const FileEntry *File =
+ Optional<FileEntryRef> File =
PP.LookupFile(FilenameLoc, Filename, isAngled, LookupFrom, LookupFromFile,
CurDir, nullptr, nullptr, nullptr, nullptr, nullptr);
if (PPCallbacks *Callbacks = PP.getPPCallbacks()) {
SrcMgr::CharacteristicKind FileType = SrcMgr::C_User;
if (File)
- FileType = PP.getHeaderSearchInfo().getFileDirFlavor(File);
+ FileType =
+ PP.getHeaderSearchInfo().getFileDirFlavor(&File->getFileEntry());
Callbacks->HasInclude(FilenameLoc, Filename, isAngled, File, FileType);
}
// Get the result value. A result of true means the file exists.
- return File != nullptr;
+ return File.hasValue();
}
/// EvaluateHasInclude - Process a '__has_include("path")' expression.
@@ -1617,21 +1618,38 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
return true;
}
return true;
+ } else if (II->getTokenID() != tok::identifier ||
+ II->hasRevertedTokenIDToIdentifier()) {
+ // Treat all keywords that introduce a custom syntax of the form
+ //
+ // '__some_keyword' '(' [...] ')'
+ //
+ // as being "builtin functions", even if the syntax isn't a valid
+ // function call (for example, because the builtin takes a type
+ // argument).
+ if (II->getName().startswith("__builtin_") ||
+ II->getName().startswith("__is_") ||
+ II->getName().startswith("__has_"))
+ return true;
+ return llvm::StringSwitch<bool>(II->getName())
+ .Case("__array_rank", true)
+ .Case("__array_extent", true)
+ .Case("__reference_binds_to_temporary", true)
+ .Case("__underlying_type", true)
+ .Default(false);
} else {
return llvm::StringSwitch<bool>(II->getName())
- .Case("__make_integer_seq", LangOpts.CPlusPlus)
- .Case("__type_pack_element", LangOpts.CPlusPlus)
- .Case("__builtin_available", true)
- .Case("__is_target_arch", true)
- .Case("__is_target_vendor", true)
- .Case("__is_target_os", true)
- .Case("__is_target_environment", true)
- .Case("__builtin_LINE", true)
- .Case("__builtin_FILE", true)
- .Case("__builtin_FUNCTION", true)
- .Case("__builtin_COLUMN", true)
- .Case("__builtin_bit_cast", true)
- .Default(false);
+ // Report builtin templates as being builtins.
+ .Case("__make_integer_seq", LangOpts.CPlusPlus)
+ .Case("__type_pack_element", LangOpts.CPlusPlus)
+ // Likewise for some builtin preprocessor macros.
+ // FIXME: This is inconsistent; we usually suggest detecting
+ // builtin macros via #ifdef. Don't add more cases here.
+ .Case("__is_target_arch", true)
+ .Case("__is_target_vendor", true)
+ .Case("__is_target_os", true)
+ .Case("__is_target_environment", true)
+ .Default(false);
}
});
} else if (II == Ident__is_identifier) {