diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/Lex/PPExpressions.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/Lex/PPExpressions.cpp | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/contrib/llvm-project/clang/lib/Lex/PPExpressions.cpp b/contrib/llvm-project/clang/lib/Lex/PPExpressions.cpp index cab4bab630dc..8f25c67ec9df 100644 --- a/contrib/llvm-project/clang/lib/Lex/PPExpressions.cpp +++ b/contrib/llvm-project/clang/lib/Lex/PPExpressions.cpp @@ -44,7 +44,7 @@ namespace { /// conditional and the source range covered by it. class PPValue { SourceRange Range; - IdentifierInfo *II; + IdentifierInfo *II = nullptr; public: llvm::APSInt Val; @@ -133,6 +133,10 @@ static bool EvaluateDefined(PPValue &Result, Token &PeekTok, DefinedTracker &DT, Result.Val.setIsUnsigned(false); // Result is signed intmax_t. DT.IncludedUndefinedIds = !Macro; + PP.emitMacroExpansionWarnings( + PeekTok, + (II->getName() == "INFINITY" || II->getName() == "NAN") ? true : false); + // If there is a macro, mark it used. if (Result.Val != 0 && ValueLive) PP.markMacroAsUsed(Macro.getMacroInfo()); @@ -265,7 +269,7 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT, const StringRef IdentifierName = II->getName(); if (llvm::any_of(UndefPrefixes, [&IdentifierName](const std::string &Prefix) { - return IdentifierName.startswith(Prefix); + return IdentifierName.starts_with(Prefix); })) PP.Diag(PeekTok, diag::warn_pp_undef_prefix) << AddFlagValue{llvm::join(UndefPrefixes, ",")} << II; @@ -321,13 +325,21 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT, PP.Diag(PeekTok, diag::ext_c99_longlong); } - // 'z/uz' literals are a C++2b feature. + // 'z/uz' literals are a C++23 feature. if (Literal.isSizeT) PP.Diag(PeekTok, PP.getLangOpts().CPlusPlus - ? PP.getLangOpts().CPlusPlus2b + ? PP.getLangOpts().CPlusPlus23 ? diag::warn_cxx20_compat_size_t_suffix - : diag::ext_cxx2b_size_t_suffix - : diag::err_cxx2b_size_t_suffix); + : diag::ext_cxx23_size_t_suffix + : diag::err_cxx23_size_t_suffix); + + // 'wb/uwb' literals are a C23 feature. We explicitly do not support the + // suffix in C++ as an extension because a library-based UDL that resolves + // to a library type may be more appropriate there. + if (Literal.isBitInt) + PP.Diag(PeekTok, PP.getLangOpts().C23 + ? diag::warn_c23_compat_bitint_suffix + : diag::ext_c23_bitint_suffix); // Parse the integer literal into Result. if (Literal.GetIntegerValue(Result.Val)) { @@ -398,9 +410,18 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT, // Set the value. Val = Literal.getValue(); // Set the signedness. UTF-16 and UTF-32 are always unsigned + // UTF-8 is unsigned if -fchar8_t is specified. if (Literal.isWide()) Val.setIsUnsigned(!TargetInfo::isTypeSigned(TI.getWCharType())); - else if (!Literal.isUTF16() && !Literal.isUTF32()) + else if (Literal.isUTF16() || Literal.isUTF32()) + Val.setIsUnsigned(true); + else if (Literal.isUTF8()) { + if (PP.getLangOpts().CPlusPlus) + Val.setIsUnsigned( + PP.getLangOpts().Char8 ? true : !PP.getLangOpts().CharIsSigned); + else + Val.setIsUnsigned(true); + } else Val.setIsUnsigned(!PP.getLangOpts().CharIsSigned); if (Result.Val.getBitWidth() > Val.getBitWidth()) { @@ -660,7 +681,7 @@ static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec, case tok::ampamp: // Logical && does not do UACs. break; // No UAC default: - Res.setIsUnsigned(LHS.isUnsigned()|RHS.isUnsigned()); + Res.setIsUnsigned(LHS.isUnsigned() || RHS.isUnsigned()); // If this just promoted something from signed to unsigned, and if the // value was negative, warn about it. if (ValueLive && Res.isUnsigned()) { @@ -820,7 +841,7 @@ static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec, // Usual arithmetic conversions (C99 6.3.1.8p1): result is unsigned if // either operand is unsigned. - Res.setIsUnsigned(RHS.isUnsigned() | AfterColonVal.isUnsigned()); + Res.setIsUnsigned(RHS.isUnsigned() || AfterColonVal.isUnsigned()); // Figure out the precedence of the token after the : part. PeekPrec = getPrecedence(PeekTok.getKind()); @@ -850,7 +871,7 @@ static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec, /// to "!defined(X)" return X in IfNDefMacro. Preprocessor::DirectiveEvalResult Preprocessor::EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro) { - SaveAndRestore<bool> PPDir(ParsingIfOrElifDirective, true); + SaveAndRestore PPDir(ParsingIfOrElifDirective, true); // Save the current state of 'DisableMacroExpansion' and reset it to false. If // 'DisableMacroExpansion' is true, then we must be in a macro argument list // in which case a directive is undefined behavior. We want macros to be able |