aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Lex
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/Lex')
-rw-r--r--contrib/llvm-project/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp13
-rw-r--r--contrib/llvm-project/clang/lib/Lex/Lexer.cpp3
-rw-r--r--contrib/llvm-project/clang/lib/Lex/LiteralSupport.cpp6
-rw-r--r--contrib/llvm-project/clang/lib/Lex/ModuleMap.cpp2
-rw-r--r--contrib/llvm-project/clang/lib/Lex/PPDirectives.cpp4
-rw-r--r--contrib/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp52
-rw-r--r--contrib/llvm-project/clang/lib/Lex/Pragma.cpp4
-rw-r--r--contrib/llvm-project/clang/lib/Lex/Preprocessor.cpp7
8 files changed, 65 insertions, 26 deletions
diff --git a/contrib/llvm-project/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp b/contrib/llvm-project/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
index f063ed711c44..029bfe1cd600 100644
--- a/contrib/llvm-project/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ b/contrib/llvm-project/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -763,12 +763,13 @@ bool Minimizer::lexEndif(const char *&First, const char *const End) {
if (top() == pp_else)
popToken();
- // Strip out "#elif" if they're empty.
- while (top() == pp_elif)
- popToken();
-
- // If "#if" is empty, strip it and skip the "#endif".
- if (top() == pp_if || top() == pp_ifdef || top() == pp_ifndef) {
+ // If "#ifdef" is empty, strip it and skip the "#endif".
+ //
+ // FIXME: Once/if Clang starts disallowing __has_include in macro expansions,
+ // we can skip empty `#if` and `#elif` blocks as well after scanning for a
+ // literal __has_include in the condition. Even without that rule we could
+ // drop the tokens if we scan for identifiers in the condition and find none.
+ if (top() == pp_ifdef || top() == pp_ifndef) {
popToken();
skipLine(First, End);
return false;
diff --git a/contrib/llvm-project/clang/lib/Lex/Lexer.cpp b/contrib/llvm-project/clang/lib/Lex/Lexer.cpp
index 17f5ab1e035d..648bda270578 100644
--- a/contrib/llvm-project/clang/lib/Lex/Lexer.cpp
+++ b/contrib/llvm-project/clang/lib/Lex/Lexer.cpp
@@ -1431,6 +1431,8 @@ void Lexer::SetByteOffset(unsigned Offset, bool StartOfLine) {
static bool isAllowedIDChar(uint32_t C, const LangOptions &LangOpts) {
if (LangOpts.AsmPreprocessor) {
return false;
+ } else if (LangOpts.DollarIdents && '$' == C) {
+ return true;
} else if (LangOpts.CPlusPlus11 || LangOpts.C11) {
static const llvm::sys::UnicodeCharSet C11AllowedIDChars(
C11AllowedIDCharRanges);
@@ -2656,6 +2658,7 @@ void Lexer::ReadToEndOfLine(SmallVectorImpl<char> *Result) {
assert(ParsingPreprocessorDirective && ParsingFilename == false &&
"Must be in a preprocessing directive!");
Token Tmp;
+ Tmp.startToken();
// CurPtr - Cache BufferPtr in an automatic variable.
const char *CurPtr = BufferPtr;
diff --git a/contrib/llvm-project/clang/lib/Lex/LiteralSupport.cpp b/contrib/llvm-project/clang/lib/Lex/LiteralSupport.cpp
index 2108408377fb..9a852141c6ee 100644
--- a/contrib/llvm-project/clang/lib/Lex/LiteralSupport.cpp
+++ b/contrib/llvm-project/clang/lib/Lex/LiteralSupport.cpp
@@ -1051,7 +1051,11 @@ NumericLiteralParser::GetFloatValue(llvm::APFloat &Result) {
Str = Buffer;
}
- return Result.convertFromString(Str, APFloat::rmNearestTiesToEven);
+ auto StatusOrErr =
+ Result.convertFromString(Str, APFloat::rmNearestTiesToEven);
+ assert(StatusOrErr && "Invalid floating point representation");
+ return !errorToBool(StatusOrErr.takeError()) ? *StatusOrErr
+ : APFloat::opInvalidOp;
}
static inline bool IsExponentPart(char c) {
diff --git a/contrib/llvm-project/clang/lib/Lex/ModuleMap.cpp b/contrib/llvm-project/clang/lib/Lex/ModuleMap.cpp
index db59629997ee..fe20a3507036 100644
--- a/contrib/llvm-project/clang/lib/Lex/ModuleMap.cpp
+++ b/contrib/llvm-project/clang/lib/Lex/ModuleMap.cpp
@@ -229,7 +229,7 @@ const FileEntry *ModuleMap::findHeader(
llvm::sys::path::append(FullPathName, RelativePathName);
auto *NormalHdrFile = GetFile(FullPathName);
- if (M && !NormalHdrFile && Directory->getName().endswith(".framework")) {
+ if (!NormalHdrFile && Directory->getName().endswith(".framework")) {
// The lack of 'framework' keyword in a module declaration it's a simple
// mistake we can diagnose when the header exists within the proper
// framework style path.
diff --git a/contrib/llvm-project/clang/lib/Lex/PPDirectives.cpp b/contrib/llvm-project/clang/lib/Lex/PPDirectives.cpp
index 3b7eaee3c914..e433b2cf1b95 100644
--- a/contrib/llvm-project/clang/lib/Lex/PPDirectives.cpp
+++ b/contrib/llvm-project/clang/lib/Lex/PPDirectives.cpp
@@ -2727,7 +2727,9 @@ void Preprocessor::HandleDefineDirective(
/*Syntactic=*/LangOpts.MicrosoftExt))
Diag(MI->getDefinitionLoc(), diag::warn_pp_macro_def_mismatch_with_pch)
<< MacroNameTok.getIdentifierInfo();
- return;
+ // Issue the diagnostic but allow the change if msvc extensions are enabled
+ if (!LangOpts.MicrosoftExt)
+ return;
}
// Finally, if this identifier already had a macro defined for it, verify that
diff --git a/contrib/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp b/contrib/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp
index dfbcaedcacff..cf8bb2fbab99 100644
--- a/contrib/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/contrib/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Basic/Attributes.h"
+#include "clang/Basic/Builtins.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LLVM.h"
@@ -28,6 +29,7 @@
#include "clang/Lex/MacroInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/PreprocessorLexer.h"
+#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Lex/Token.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
@@ -35,9 +37,9 @@
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/Casting.h"
@@ -369,7 +371,11 @@ void Preprocessor::RegisterBuiltinMacros() {
Ident__has_extension = RegisterBuiltinMacro(*this, "__has_extension");
Ident__has_builtin = RegisterBuiltinMacro(*this, "__has_builtin");
Ident__has_attribute = RegisterBuiltinMacro(*this, "__has_attribute");
- Ident__has_c_attribute = RegisterBuiltinMacro(*this, "__has_c_attribute");
+ if (!LangOpts.CPlusPlus)
+ Ident__has_c_attribute = RegisterBuiltinMacro(*this, "__has_c_attribute");
+ else
+ Ident__has_c_attribute = nullptr;
+
Ident__has_declspec = RegisterBuiltinMacro(*this, "__has_declspec_attribute");
Ident__has_include = RegisterBuiltinMacro(*this, "__has_include");
Ident__has_include_next = RegisterBuiltinMacro(*this, "__has_include_next");
@@ -820,18 +826,26 @@ MacroArgs *Preprocessor::ReadMacroCallArgumentList(Token &MacroName,
}
} else if (Tok.is(tok::l_paren)) {
++NumParens;
- } else if (Tok.is(tok::comma) && NumParens == 0 &&
- !(Tok.getFlags() & Token::IgnoredComma)) {
+ } else if (Tok.is(tok::comma)) {
// In Microsoft-compatibility mode, single commas from nested macro
// expansions should not be considered as argument separators. We test
- // for this with the IgnoredComma token flag above.
-
- // Comma ends this argument if there are more fixed arguments expected.
- // However, if this is a variadic macro, and this is part of the
- // variadic part, then the comma is just an argument token.
- if (!isVariadic) break;
- if (NumFixedArgsLeft > 1)
- break;
+ // for this with the IgnoredComma token flag.
+ if (Tok.getFlags() & Token::IgnoredComma) {
+ // However, in MSVC's preprocessor, subsequent expansions do treat
+ // these commas as argument separators. This leads to a common
+ // workaround used in macros that need to work in both MSVC and
+ // compliant preprocessors. Therefore, the IgnoredComma flag can only
+ // apply once to any given token.
+ Tok.clearFlag(Token::IgnoredComma);
+ } else if (NumParens == 0) {
+ // Comma ends this argument if there are more fixed arguments
+ // expected. However, if this is a variadic macro, and this is part of
+ // the variadic part, then the comma is just an argument token.
+ if (!isVariadic)
+ break;
+ if (NumFixedArgsLeft > 1)
+ break;
+ }
} else if (Tok.is(tok::comment) && !KeepMacroComments) {
// If this is a comment token in the argument list and we're just in
// -C mode (not -CC mode), discard the comment.
@@ -1437,6 +1451,17 @@ static bool isTargetEnvironment(const TargetInfo &TI,
return TI.getTriple().getEnvironment() == Env.getEnvironment();
}
+static void remapMacroPath(
+ SmallString<256> &Path,
+ const std::map<std::string, std::string, std::greater<std::string>>
+ &MacroPrefixMap) {
+ for (const auto &Entry : MacroPrefixMap)
+ if (Path.startswith(Entry.first)) {
+ Path = (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
+ break;
+ }
+}
+
/// ExpandBuiltinMacro - If an identifier token is read that is to be expanded
/// as a builtin macro, handle it and return the next token as 'Tok'.
void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
@@ -1503,7 +1528,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
}
// Escape this filename. Turn '\' -> '\\' '"' -> '\"'
- SmallString<128> FN;
+ SmallString<256> FN;
if (PLoc.isValid()) {
// __FILE_NAME__ is a Clang-specific extension that expands to the
// the last part of __FILE__.
@@ -1519,6 +1544,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
FN += PLoc.getFilename();
}
Lexer::Stringify(FN);
+ remapMacroPath(FN, PPOpts->MacroPrefixMap);
OS << '"' << FN << '"';
}
Tok.setKind(tok::string_literal);
diff --git a/contrib/llvm-project/clang/lib/Lex/Pragma.cpp b/contrib/llvm-project/clang/lib/Lex/Pragma.cpp
index 79953804b5d3..e4636265a72b 100644
--- a/contrib/llvm-project/clang/lib/Lex/Pragma.cpp
+++ b/contrib/llvm-project/clang/lib/Lex/Pragma.cpp
@@ -848,8 +848,8 @@ void Preprocessor::HandlePragmaModuleBuild(Token &Tok) {
CurLexer->getBuffer().begin() <= End &&
End <= CurLexer->getBuffer().end() &&
"module source range not contained within same file buffer");
- TheModuleLoader.loadModuleFromSource(Loc, ModuleName->getName(),
- StringRef(Start, End - Start));
+ TheModuleLoader.createModuleFromSource(Loc, ModuleName->getName(),
+ StringRef(Start, End - Start));
}
void Preprocessor::HandlePragmaHdrstop(Token &Tok) {
diff --git a/contrib/llvm-project/clang/lib/Lex/Preprocessor.cpp b/contrib/llvm-project/clang/lib/Lex/Preprocessor.cpp
index 82007732a9b1..0e9be3923630 100644
--- a/contrib/llvm-project/clang/lib/Lex/Preprocessor.cpp
+++ b/contrib/llvm-project/clang/lib/Lex/Preprocessor.cpp
@@ -25,6 +25,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Lex/Preprocessor.h"
+#include "clang/Basic/Builtins.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/FileSystemStatCache.h"
#include "clang/Basic/IdentifierTable.h"
@@ -53,9 +54,9 @@
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/Capacity.h"
@@ -112,6 +113,8 @@ Preprocessor::Preprocessor(std::shared_ptr<PreprocessorOptions> PPOpts,
// We haven't read anything from the external source.
ReadMacrosFromExternalSource = false;
+ BuiltinInfo = std::make_unique<Builtin::Context>();
+
// "Poison" __VA_ARGS__, __VA_OPT__ which can only appear in the expansion of
// a macro. They get unpoisoned where it is allowed.
(Ident__VA_ARGS__ = getIdentifierInfo("__VA_ARGS__"))->setIsPoisoned();
@@ -202,7 +205,7 @@ void Preprocessor::Initialize(const TargetInfo &Target,
this->AuxTarget = AuxTarget;
// Initialize information about built-ins.
- BuiltinInfo.InitializeTarget(Target, AuxTarget);
+ BuiltinInfo->InitializeTarget(Target, AuxTarget);
HeaderInfo.setTarget(Target);
// Populate the identifier table with info about keywords for the current language.