github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}--> :warning: C/C++ code formatter, clang-format found issues in your code. :warning: <details> <summary> You can test this locally with the following command: </summary> ``````````bash git-clang-format --diff 67b675ee55cce183b93874a38ab94eee00aedbcc adc973776a526f97b6da2435edf143a10e7e0ad5 -- clang/include/clang/Lex/PPDirectiveParameter.h clang/include/clang/Lex/PPEmbedParameters.h clang/test/Preprocessor/embed___has_embed.c clang/test/Preprocessor/embed___has_embed_supported.c clang/test/Preprocessor/embed_art.c clang/test/Preprocessor/embed_feature_test.cpp clang/test/Preprocessor/embed_file_not_found.c clang/test/Preprocessor/embed_init.c clang/test/Preprocessor/embed_parameter_if_empty.c clang/test/Preprocessor/embed_parameter_limit.c clang/test/Preprocessor/embed_parameter_offset.c clang/test/Preprocessor/embed_parameter_prefix.c clang/test/Preprocessor/embed_parameter_suffix.c clang/test/Preprocessor/embed_parameter_unrecognized.c clang/test/Preprocessor/embed_path_chevron.c clang/test/Preprocessor/embed_path_quote.c clang/test/Preprocessor/embed_single_entity.c clang/test/Preprocessor/embed_weird.cpp clang/include/clang/AST/Expr.h clang/include/clang/AST/RecursiveASTVisitor.h clang/include/clang/Basic/FileManager.h clang/include/clang/Frontend/PreprocessorOutputOptions.h clang/include/clang/Lex/PPCallbacks.h clang/include/clang/Lex/Preprocessor.h clang/include/clang/Lex/PreprocessorOptions.h clang/include/clang/Lex/Token.h clang/include/clang/Sema/Sema.h clang/include/clang/Serialization/ASTBitCodes.h clang/lib/AST/Expr.cpp clang/lib/AST/ExprClassification.cpp clang/lib/AST/ExprConstant.cpp clang/lib/AST/ItaniumMangle.cpp clang/lib/AST/StmtPrinter.cpp clang/lib/AST/StmtProfile.cpp clang/lib/Basic/FileManager.cpp clang/lib/Basic/IdentifierTable.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Format/FormatToken.h clang/lib/Format/TokenAnnotator.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Frontend/DependencyFile.cpp clang/lib/Frontend/DependencyGraph.cpp clang/lib/Frontend/InitPreprocessor.cpp clang/lib/Frontend/PrintPreprocessedOutput.cpp clang/lib/Frontend/Rewrite/InclusionRewriter.cpp clang/lib/Interpreter/Interpreter.cpp clang/lib/Lex/Lexer.cpp clang/lib/Lex/PPCallbacks.cpp clang/lib/Lex/PPDirectives.cpp clang/lib/Lex/PPExpressions.cpp clang/lib/Lex/PPMacroExpansion.cpp clang/lib/Lex/Preprocessor.cpp clang/lib/Parse/ParseDeclCXX.cpp clang/lib/Parse/ParseExpr.cpp clang/lib/Parse/ParseInit.cpp clang/lib/Parse/ParseTemplate.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaExceptionSpec.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaTemplate.cpp clang/lib/Sema/SemaTemplateVariadic.cpp clang/lib/Sema/TreeTransform.h clang/lib/Serialization/ASTReaderStmt.cpp clang/lib/Serialization/ASTWriterStmt.cpp clang/lib/StaticAnalyzer/Core/ExprEngine.cpp llvm/include/llvm/Support/Base64.h `````````` </details> <details> <summary> View the diff from clang-format here. </summary> ``````````diff diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index 9303307fd..d3fba205c 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -4818,14 +4818,13 @@ public: FoundOne, Expanded, }; - - PPEmbedExpr(const ASTContext &Ctx, QualType ResultTy, StringLiteral* Filename, StringLiteral* BinaryData, - SourceLocation BLoc, SourceLocation RParenLoc, - DeclContext *Context); + + PPEmbedExpr(const ASTContext &Ctx, QualType ResultTy, StringLiteral *Filename, + StringLiteral *BinaryData, SourceLocation BLoc, + SourceLocation RParenLoc, DeclContext *Context); /// Build an empty call expression. - explicit PPEmbedExpr(EmptyShell Empty) - : Expr(SourceLocExprClass, Empty) {} + explicit PPEmbedExpr(EmptyShell Empty) : Expr(SourceLocExprClass, Empty) {} /// If the PPEmbedExpr has been resolved return the subexpression /// representing the resolved value. Otherwise return null. diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index c757f8775..cbfcb2927 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -282,8 +282,9 @@ public: getBufferForFile(StringRef Filename, bool isVolatile = false, bool RequiresNullTerminator = true, std::optional<int64_t> MaybeLimit = std::nullopt) { - return getBufferForFileImpl(Filename, /*FileSize=*/(MaybeLimit ? *MaybeLimit : -1), isVolatile, - RequiresNullTerminator); + return getBufferForFileImpl(Filename, + /*FileSize=*/(MaybeLimit ? *MaybeLimit : -1), + isVolatile, RequiresNullTerminator); } private: diff --git a/clang/include/clang/Frontend/PreprocessorOutputOptions.h b/clang/include/clang/Frontend/PreprocessorOutputOptions.h index 3e36db3f8..0bc32c65a 100644 --- a/clang/include/clang/Frontend/PreprocessorOutputOptions.h +++ b/clang/include/clang/Frontend/PreprocessorOutputOptions.h @@ -22,7 +22,8 @@ public: unsigned ShowMacroComments : 1; ///< Show comments, even in macros. unsigned ShowMacros : 1; ///< Print macro definitions. unsigned ShowIncludeDirectives : 1; ///< Print includes, imports etc. within preprocessed output. - unsigned ShowEmbedDirectives : 1; ///< Print embeds, etc. within preprocessed output. + unsigned ShowEmbedDirectives : 1; ///< Print embeds, etc. within preprocessed + ///< output. unsigned RewriteIncludes : 1; ///< Preprocess include directives only. unsigned RewriteImports : 1; ///< Include contents of transitively-imported modules. unsigned MinimizeWhitespace : 1; ///< Ignore whitespace from input. diff --git a/clang/include/clang/Lex/PPEmbedParameters.h b/clang/include/clang/Lex/PPEmbedParameters.h index c2a01b80b..7b76d2d57 100644 --- a/clang/include/clang/Lex/PPEmbedParameters.h +++ b/clang/include/clang/Lex/PPEmbedParameters.h @@ -13,8 +13,8 @@ #ifndef LLVM_CLANG_LEX_PPEMBEDPARAMETERS_H #define LLVM_CLANG_LEX_PPEMBEDPARAMETERS_H -#include "clang/Lex/Token.h" #include "clang/Lex/PPDirectiveParameter.h" +#include "clang/Lex/Token.h" #include "llvm/ADT/SmallVector.h" namespace clang { @@ -25,7 +25,8 @@ class PPEmbedParameterOffset : public PPDirectiveParameter { public: size_t Offset; - PPEmbedParameterOffset(size_t Offset, SourceLocation Start, SourceLocation End) + PPEmbedParameterOffset(size_t Offset, SourceLocation Start, + SourceLocation End) : Offset(Offset), PPDirectiveParameter(Start, End) {} }; @@ -35,8 +36,7 @@ class PPEmbedParameterLimit : public PPDirectiveParameter { public: size_t Limit; - PPEmbedParameterLimit(size_t Limit, SourceLocation Start, - SourceLocation End) + PPEmbedParameterLimit(size_t Limit, SourceLocation Start, SourceLocation End) : Limit(Limit), PPDirectiveParameter(Start, End) {} }; @@ -47,7 +47,7 @@ public: SmallVector<Token, 2> Tokens; PPEmbedParameterPrefix(SmallVector<Token, 2> Tokens, SourceLocation Start, - SourceLocation End) + SourceLocation End) : Tokens(std::move(Tokens)), PPDirectiveParameter(Start, End) {} }; @@ -58,7 +58,7 @@ public: SmallVector<Token, 2> Tokens; PPEmbedParameterSuffix(SmallVector<Token, 2> Tokens, SourceLocation Start, - SourceLocation End) + SourceLocation End) : Tokens(std::move(Tokens)), PPDirectiveParameter(Start, End) {} }; diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 61e244408..2255ac70c 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -1811,7 +1811,8 @@ public: /// Parses a simple integer literal to get its numeric value. Floating /// point literals and user defined literals are rejected. Used primarily to /// handle pragmas that accept integer arguments. - bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value, bool WithLex = true); + bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value, + bool WithLex = true); /// Disables macro expansion everywhere except for preprocessor directives. void SetMacroExpansionOnlyInDirectives() { diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 98f83d4d6..6a95df6ba 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -5980,7 +5980,8 @@ public: StringRef GetLocationName(PPEmbedExprContext Context) const; bool DiagnosePPEmbedExpr(Expr *&E, SourceLocation ContextLocation, - PPEmbedExprContext Context, bool SingleAllowed = true); + PPEmbedExprContext Context, + bool SingleAllowed = true); // Build a potentially resolved SourceLocExpr. ExprResult BuildSourceLocExpr(SourceLocExpr::IdentKind Kind, diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index cdee83758..be3696102 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -2330,19 +2330,18 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx, } PPEmbedExpr::PPEmbedExpr(const ASTContext &Ctx, QualType ResultTy, - StringLiteral *Filename, - StringLiteral *BinaryData, - SourceLocation BLoc, - SourceLocation RParenLoc, - DeclContext *ParentContext) + StringLiteral *Filename, StringLiteral *BinaryData, + SourceLocation BLoc, SourceLocation RParenLoc, + DeclContext *ParentContext) : Expr(PPEmbedExprClass, ResultTy, VK_PRValue, OK_Ordinary), - BuiltinLoc(BLoc), RParenLoc(RParenLoc), ParentContext(ParentContext), Filename(Filename), BinaryData(BinaryData) { + BuiltinLoc(BLoc), RParenLoc(RParenLoc), ParentContext(ParentContext), + Filename(Filename), BinaryData(BinaryData) { setDependence(ExprDependence::None); } size_t PPEmbedExpr::getDataElementCount(ASTContext &Context) const { - return getDataStringLiteral()->getByteLength() / - (Context.getTypeSize(getType()) / Context.getTypeSize(Context.CharTy)); + return getDataStringLiteral()->getByteLength() / + (Context.getTypeSize(getType()) / Context.getTypeSize(Context.CharTy)); } InitListExpr::InitListExpr(const ASTContext &C, SourceLocation lbraceloc, diff --git a/clang/lib/AST/ExprClassification.cpp b/clang/lib/AST/ExprClassification.cpp index ddb0dfc49..fbbbd72b1 100644 --- a/clang/lib/AST/ExprClassification.cpp +++ b/clang/lib/AST/ExprClassification.cpp @@ -205,7 +205,8 @@ static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const Expr *E) { return Cl::CL_PRValue; case Expr::PPEmbedExprClass: - // Nominally, this just goes through as a PRValue until we actually expand it and check it. + // Nominally, this just goes through as a PRValue until we actually expand + // it and check it. return Cl::CL_PRValue; // Make HLSL this reference-like diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index b70d4d925..0be044f54 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -2284,9 +2284,7 @@ void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) { VisitExpr(E); } -void StmtProfiler::VisitPPEmbedExpr(const PPEmbedExpr *E) { - VisitExpr(E); -} +void StmtProfiler::VisitPPEmbedExpr(const PPEmbedExpr *E) { VisitExpr(E); } void StmtProfiler::VisitRecoveryExpr(const RecoveryExpr *E) { VisitExpr(E); } diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 690a72ea8..c45436fe0 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -549,7 +549,6 @@ FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile, if (MaybeLimit) FileSize = *MaybeLimit; - // If there's a high enough chance that the file have changed since we // got its size, force a stat before opening it. if (isVolatile || Entry->isNamedPipe()) diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index d2b5426d2..96ac3663c 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -422,8 +422,8 @@ tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const { // collisions (if there were, the switch below would complain about duplicate // case values). Note that this depends on 'if' being null terminated. -#define HASH(LEN, FIRST, THIRD) \ - (LEN << 6) + (((FIRST-'a') - (THIRD-'a')) & 63) +#define HASH(LEN, FIRST, THIRD) \ + (LEN << 6) + (((FIRST - 'a') - (THIRD - 'a')) & 63) #define CASE(LEN, FIRST, THIRD, NAME) \ case HASH(LEN, FIRST, THIRD): \ return memcmp(Name, #NAME, LEN) ? tok::pp_not_keyword : tok::pp_ ## NAME @@ -438,7 +438,7 @@ tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const { CASE( 4, 'e', 's', else); CASE( 4, 'l', 'n', line); CASE( 4, 's', 'c', sccs); - CASE( 5, 'e', 'b', embed); + CASE(5, 'e', 'b', embed); CASE( 5, 'e', 'd', endif); CASE( 5, 'e', 'r', error); CASE( 5, 'i', 'e', ident); diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index a8d51179a..a9dc716b1 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1324,7 +1324,8 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, Args.AddAllArgs(CmdArgs, {options::OPT_D, options::OPT_U, options::OPT_I_Group, - options::OPT_F, options::OPT_index_header_map, options::OPT_EmbedPath_Group}); + options::OPT_F, options::OPT_index_header_map, + options::OPT_EmbedPath_Group}); // Add -Wp, and -Xpreprocessor if using the preprocessor. diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index e405a9085..0a3c16f3a 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1399,8 +1399,7 @@ private: if (Tok->isOneOf(Keywords.kw___has_include, Keywords.kw___has_include_next)) { parseHasInclude(); - } - else if (Tok->is(Keywords.kw___has_embed)) { + } else if (Tok->is(Keywords.kw___has_embed)) { parseHasEmbed(); } if (Style.isCSharp() && Tok->is(Keywords.kw_where) && Tok->Next && diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index e1bec00a8..a982932c4 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4277,7 +4277,6 @@ static void GeneratePreprocessorArgs(const PreprocessorOptions &Opts, continue; GenerateArg(Consumer, M.second ? OPT_U : OPT_D, M.first); - } for (const auto &I : Opts.Includes) { diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp index 10558b1d3..04ddb92ff 100644 --- a/clang/lib/Frontend/DependencyFile.cpp +++ b/clang/lib/Frontend/DependencyFile.cpp @@ -65,11 +65,11 @@ struct DepCollectorPPCallbacks : public PPCallbacks { /*IsMissing=*/false); } - void EmbedDirective(SourceLocation HashLoc, - StringRef FileName, bool IsAngled, - CharSourceRange FilenameRange, CharSourceRange ParametersRange, - OptionalFileEntryRef File, StringRef SearchPath, - StringRef RelativePath) override { + void EmbedDirective(SourceLocation HashLoc, StringRef FileName, bool IsAngled, + CharSourceRange FilenameRange, + CharSourceRange ParametersRange, + OptionalFileEntryRef File, StringRef SearchPath, + StringRef RelativePath) override { if (!File) DepCollector.maybeAddDependency(FileName, /*FromModule*/ false, @@ -97,14 +97,13 @@ struct DepCollectorPPCallbacks : public PPCallbacks { } void HasEmbed(SourceLocation Loc, StringRef SpelledFilename, bool IsAngled, - OptionalFileEntryRef File) override { + OptionalFileEntryRef File) override { if (!File) return; StringRef Filename = llvm::sys::path::remove_leading_dotslash(File->getName()); DepCollector.maybeAddDependency(Filename, - /*FromModule=*/false, - false, + /*FromModule=*/false, false, /*IsModuleFile=*/false, &PP.getFileManager(), /*IsMissing=*/false); diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index 4e0931ebb..e547b4dc1 100644 --- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -108,9 +108,10 @@ private: public: PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream *os, bool lineMarkers, - bool defines, bool DumpIncludeDirectives, bool DumpEmbedDirectives, - bool UseLineDirectives, bool MinimizeWhitespace, - bool DirectivesOnly, bool KeepSystemIncludes) + bool defines, bool DumpIncludeDirectives, + bool DumpEmbedDirectives, bool UseLineDirectives, + bool MinimizeWhitespace, bool DirectivesOnly, + bool KeepSystemIncludes) : PP(pp), SM(PP.getSourceManager()), ConcatInfo(PP), OS(os), DisableLineMarkers(lineMarkers), DumpDefines(defines), DumpIncludeDirectives(DumpIncludeDirectives), @@ -412,10 +413,9 @@ void PrintPPOutputPPCallbacks::EmbedDirective( if (DumpEmbedDirectives) { MoveToLine(HashLoc, /*RequireStartOfLine=*/true); *OS << "#embed " << (IsAngled ? '<' : '"') << FileName - << (IsAngled ? '>' : '"') << " /* clang -E -dE */"; + << (IsAngled ? '>' : '"') << " /* clang -E -dE */"; setEmittedDirectiveOnThisLine(); } - } void PrintPPOutputPPCallbacks::InclusionDirective( @@ -999,8 +999,9 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS, PrintPPOutputPPCallbacks *Callbacks = new PrintPPOutputPPCallbacks( PP, OS, !Opts.ShowLineMarkers, Opts.ShowMacros, - Opts.ShowIncludeDirectives, Opts.ShowEmbedDirectives, Opts.UseLineDirectives, - Opts.MinimizeWhitespace, Opts.DirectivesOnly, Opts.KeepSystemIncludes); + Opts.ShowIncludeDirectives, Opts.ShowEmbedDirectives, + Opts.UseLineDirectives, Opts.MinimizeWhitespace, Opts.DirectivesOnly, + Opts.KeepSystemIncludes); // Expand macros in pragmas with -fms-extensions. The assumption is that // the majority of pragmas in such a file will be Microsoft pragmas. diff --git a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp index c8d680239..12ccb5941 100644 --- a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp +++ b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp @@ -451,8 +451,8 @@ void InclusionRewriter::Process(FileID FileId, OS << "#pragma clang module begin " << Mod->getFullModuleName(true) << "\n"; - // Include and recursively process the file. - Process(Inc->Id, Inc->FileType); + // Include and recursively process the file. + Process(Inc->Id, Inc->FileType); if (Mod) OS << "#pragma clang module end /*" @@ -460,88 +460,88 @@ void InclusionRewriter::Process(FileID FileId, OS << "#endif /* " << getIncludedFileName(Inc) << " expanded by -frewrite-includes */" << LocalEOL; - // Add line marker to indicate we're returning from an included - // file. - LineInfoExtra = " 2"; + // Add line marker to indicate we're returning from an included + // file. + LineInfoExtra = " 2"; } // fix up lineinfo (since commented out directive changed line // numbers) for inclusions that were skipped due to header guards WriteLineInfo(FileName, Line, FileType, LineInfoExtra); break; - } - case tok::pp_pragma: { - StringRef Identifier = NextIdentifierName(RawLex, RawToken); - if (Identifier == "clang" || Identifier == "GCC") { - if (NextIdentifierName(RawLex, RawToken) == "system_header") { + } + case tok::pp_pragma: { + StringRef Identifier = NextIdentifierName(RawLex, RawToken); + if (Identifier == "clang" || Identifier == "GCC") { + if (NextIdentifierName(RawLex, RawToken) == "system_header") { + // keep the directive in, commented out + CommentOutDirective(RawLex, HashToken, FromFile, LocalEOL, + NextToWrite, Line); + // update our own type + FileType = SM.getFileCharacteristic(RawToken.getLocation()); + WriteLineInfo(FileName, Line, FileType); + } + } else if (Identifier == "once") { // keep the directive in, commented out CommentOutDirective(RawLex, HashToken, FromFile, LocalEOL, NextToWrite, Line); - // update our own type - FileType = SM.getFileCharacteristic(RawToken.getLocation()); WriteLineInfo(FileName, Line, FileType); } - } else if (Identifier == "once") { - // keep the directive in, commented out - CommentOutDirective(RawLex, HashToken, FromFile, LocalEOL, - NextToWrite, Line); + break; + } + case tok::pp_if: + case tok::pp_elif: { + bool elif = (RawToken.getIdentifierInfo()->getPPKeywordID() == + tok::pp_elif); + bool isTrue = IsIfAtLocationTrue(RawToken.getLocation()); + OutputContentUpTo(FromFile, NextToWrite, + SM.getFileOffset(HashToken.getLocation()), + LocalEOL, Line, /*EnsureNewline=*/true); + do { + RawLex.LexFromRawLexer(RawToken); + } while (!RawToken.is(tok::eod) && RawToken.isNot(tok::eof)); + // We need to disable the old condition, but that is tricky. + // Trying to comment it out can easily lead to comment nesting. + // So instead make the condition harmless by making it enclose + // and empty block. Moreover, put it itself inside an #if 0 block + // to disable it from getting evaluated (e.g. __has_include_next + // warns if used from the primary source file). + OS << "#if 0 /* disabled by -frewrite-includes */" << MainEOL; + if (elif) { + OS << "#if 0" << MainEOL; + } + OutputContentUpTo(FromFile, NextToWrite, + SM.getFileOffset(RawToken.getLocation()) + + RawToken.getLength(), + LocalEOL, Line, /*EnsureNewline=*/true); + // Close the empty block and the disabling block. + OS << "#endif" << MainEOL; + OS << "#endif /* disabled by -frewrite-includes */" << MainEOL; + OS << (elif ? "#elif " : "#if ") << (isTrue ? "1" : "0") + << " /* evaluated by -frewrite-includes */" << MainEOL; WriteLineInfo(FileName, Line, FileType); + break; } - break; - } - case tok::pp_if: - case tok::pp_elif: { - bool elif = - (RawToken.getIdentifierInfo()->getPPKeywordID() == tok::pp_elif); - bool isTrue = IsIfAtLocationTrue(RawToken.getLocation()); - OutputContentUpTo(FromFile, NextToWrite, - SM.getFileOffset(HashToken.getLocation()), LocalEOL, - Line, /*EnsureNewline=*/true); - do { - RawLex.LexFromRawLexer(RawToken); - } while (!RawToken.is(tok::eod) && RawToken.isNot(tok::eof)); - // We need to disable the old condition, but that is tricky. - // Trying to comment it out can easily lead to comment nesting. - // So instead make the condition harmless by making it enclose - // and empty block. Moreover, put it itself inside an #if 0 block - // to disable it from getting evaluated (e.g. __has_include_next - // warns if used from the primary source file). - OS << "#if 0 /* disabled by -frewrite-includes */" << MainEOL; - if (elif) { - OS << "#if 0" << MainEOL; + case tok::pp_endif: + case tok::pp_else: { + // We surround every #include by #if 0 to comment it out, but that + // changes line numbers. These are fixed up right after that, but + // the whole #include could be inside a preprocessor conditional + // that is not processed. So it is necessary to fix the line + // numbers one the next line after each #else/#endif as well. + RawLex.SetKeepWhitespaceMode(true); + do { + RawLex.LexFromRawLexer(RawToken); + } while (RawToken.isNot(tok::eod) && RawToken.isNot(tok::eof)); + OutputContentUpTo(FromFile, NextToWrite, + SM.getFileOffset(RawToken.getLocation()) + + RawToken.getLength(), + LocalEOL, Line, /*EnsureNewline=*/true); + WriteLineInfo(FileName, Line, FileType); + RawLex.SetKeepWhitespaceMode(false); + break; } - OutputContentUpTo(FromFile, NextToWrite, - SM.getFileOffset(RawToken.getLocation()) + - RawToken.getLength(), - LocalEOL, Line, /*EnsureNewline=*/true); - // Close the empty block and the disabling block. - OS << "#endif" << MainEOL; - OS << "#endif /* disabled by -frewrite-includes */" << MainEOL; - OS << (elif ? "#elif " : "#if ") << (isTrue ? "1" : "0") - << " /* evaluated by -frewrite-includes */" << MainEOL; - WriteLineInfo(FileName, Line, FileType); - break; - } - case tok::pp_endif: - case tok::pp_else: { - // We surround every #include by #if 0 to comment it out, but that - // changes line numbers. These are fixed up right after that, but - // the whole #include could be inside a preprocessor conditional - // that is not processed. So it is necessary to fix the line - // numbers one the next line after each #else/#endif as well. - RawLex.SetKeepWhitespaceMode(true); - do { - RawLex.LexFromRawLexer(RawToken); - } while (RawToken.isNot(tok::eod) && RawToken.isNot(tok::eof)); - OutputContentUpTo(FromFile, NextToWrite, - SM.getFileOffset(RawToken.getLocation()) + - RawToken.getLength(), - LocalEOL, Line, /*EnsureNewline=*/true); - WriteLineInfo(FileName, Line, FileType); - RawLex.SetKeepWhitespaceMode(false); - break; - } - default: - break; + default: + break; } } RawLex.setParsingPreprocessorDirective(false); diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index e8b0d75eb..7f6c964b0 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -1274,7 +1274,7 @@ int Preprocessor::EvaluateHasEmbed(Token &Tok, IdentifierInfo *II) { : diag::warn_c23_pp_has_embed); Diag(Tok, EitherDiag); } - + // Save the location of the current token. If a '(' is later found, use // that location. If not, use the end of this location instead. SourceLocation LParenLoc = Tok.getLocation(); @@ -1321,7 +1321,8 @@ int Preprocessor::EvaluateHasEmbed(Token &Tok, IdentifierInfo *II) { SourceLocation FilenameLoc = Tok.getLocation(); Token FilenameTok = Tok; - Preprocessor::LexEmbedParametersResult Params = this->LexEmbedParameters(Tok, true, false); + Preprocessor::LexEmbedParametersResult Params = + this->LexEmbedParameters(Tok, true, false); if (!Params.Successful) { if (Tok.isNot(tok::eod)) this->DiscardUntilEndOfDirective(); @@ -1339,7 +1340,6 @@ int Preprocessor::EvaluateHasEmbed(Token &Tok, IdentifierInfo *II) { return VALUE__STDC_EMBED_NOT_FOUND__; } - SmallString<128> FilenameBuffer; SmallString<256> RelativePath; StringRef Filename = this->getSpelling(FilenameTok, FilenameBuffer); @@ -1351,11 +1351,10 @@ int Preprocessor::EvaluateHasEmbed(Token &Tok, IdentifierInfo *II) { assert(!Filename.empty()); const FileEntry *LookupFromFile = this->getCurrentFileLexer() ? this->getCurrentFileLexer()->getFileEntry() - : nullptr; + : nullptr; OptionalFileEntryRef MaybeFileEntry = this->LookupEmbedFile(FilenameLoc, Filename, isAngled, false, - LookupFromFile, nullptr, - &RelativePath); + LookupFromFile, nullptr, &RelativePath); if (Callbacks) { Callbacks->HasEmbed(LParenLoc, Filename, isAngled, MaybeFileEntry); } @@ -1920,7 +1919,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) { // double-quotes (""), optionally followed by a series of // arguments similar to form like attributes. int Value = EvaluateHasEmbed(Tok, II); - + if (Tok.isNot(tok::r_paren)) return; OS << Value; diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index bd12e71a2..10eb6d268 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -1411,7 +1411,8 @@ bool Preprocessor::FinishLexStringLiteral(Token &Result, std::string &String, return true; } -bool Preprocessor::parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value, bool WithLex) { +bool Preprocessor::parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value, + bool WithLex) { assert(Tok.is(tok::numeric_constant)); SmallString<8> IntegerBuffer; bool NumberInvalid = false; @@ -1427,7 +1428,7 @@ bool Preprocessor::parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value, bool W if (Literal.GetIntegerValue(APVal)) return false; if (WithLex) - Lex(Tok); + Lex(Tok); Value = APVal.getLimitedValue(); return true; } diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 844ddd18f..0f096297c 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -1046,9 +1046,9 @@ Parser::ParseCastExpression(CastParseKind ParseKind, bool isAddressOfOperand, isVectorLiteral, NotPrimaryExpression); case tok::identifier: - ParseIdentifier : { // primary-expression: identifier - // unqualified-id: identifier - // constant: enumeration-constant + ParseIdentifier: { // primary-expression: identifier + // unqualified-id: identifier + // constant: enumeration-constant // Turn a potentially qualified name into a annot_typename or // annot_cxxscope if it would be valid. This handles things like x::y, etc. if (getLangOpts().CPlusPlus) { @@ -2861,7 +2861,7 @@ ExprResult Parser::ParseBuiltinPrimaryExpression() { Res = ExprError(); } } - + StringLiteral *FilenameLiteral = nullptr; if (FilenameArgExpr.isInvalid()) { Res = ExprError(); @@ -2883,7 +2883,7 @@ ExprResult Parser::ParseBuiltinPrimaryExpression() { } const auto OnDecodeError = [&](const llvm::ErrorInfoBase &) { Diag(Base64Str->getExprLoc(), - diag::err_builtin_pp_embed_invalid_argument) + diag::err_builtin_pp_embed_invalid_argument) << "expected a valid base64 encoded string"; }; llvm::Error Err = llvm::decodeBase64(Base64Str->getBytes(), BinaryData); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 06c7f293b..911ec01f5 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -13347,8 +13347,9 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) { // Legitimately, in all other cases, COMPLETELY nuke the PPEmbedExpr // and turn it into a list of integers where applicable. - if (InitListExpr *ILExpr = dyn_cast_if_present<InitListExpr>(Init); ILExpr) { - ArrayRef<Expr*> Inits = ILExpr->inits(); + if (InitListExpr *ILExpr = dyn_cast_if_present<InitListExpr>(Init); + ILExpr) { + ArrayRef<Expr *> Inits = ILExpr->inits(); SmallVector<Expr *, 4> OutputExprList{}; if (ExpandPPEmbedExprInExprList(Inits, OutputExprList, false) == PPEmbedExpr::Expanded) { diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 25355c00b..37321d241 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -17023,7 +17023,7 @@ Decl *Sema::ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, if (DiagnoseUnexpandedParameterPack(AssertExpr, UPPC_StaticAssertExpression)) return nullptr; if (DiagnosePPEmbedExpr(AssertExpr, StaticAssertLoc, PPEEC_StaticAssert)) - return nullptr; + return nullptr; return BuildStaticAssertDeclaration(StaticAssertLoc, AssertExpr, AssertMessageExpr, RParenLoc, false); } diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 76308cf9f..a7f1ae9ae 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -17885,12 +17885,13 @@ bool Sema::DiagnosePPEmbedExpr(Expr *&E, SourceLocation ContextLocation, } StringRef LocationName = GetLocationName(PPEmbedContext); - StringRef DiagnosticMessage = (SingleAllowed - ? "cannot use a preprocessor embed that expands to nothing or expands to " - "more than one item in " - : "cannot use a preprocessor embed in "); + StringRef DiagnosticMessage = + (SingleAllowed ? "cannot use a preprocessor embed that expands to " + "nothing or expands to " + "more than one item in " + : "cannot use a preprocessor embed in "); Diag(ContextLocation, diag::err_builtin_pp_embed_invalid_location) - << DiagnosticMessage << 1 << LocationName; + << DiagnosticMessage << 1 << LocationName; return false; } diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index daf89262a..ed5a03393 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -12128,8 +12128,7 @@ ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) { } template <typename Derived> -ExprResult -TreeTransform<Derived>::TransformPPEmbedExpr(PPEmbedExpr *E) { +ExprResult TreeTransform<Derived>::TransformPPEmbedExpr(PPEmbedExpr *E) { // TODO: fully implement for tree transformations return E; } `````````` </details> https://github.com/llvm/llvm-project/pull/68620 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits