[clang] Add -fkeep-system-includes modifier for -E (PR #67684)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 28 07:31:21 PDT 2023
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 1b7285bf3ee73975fa63acfc5301a9b57a53fca2 a71131f734c90aeaff9c3fb0cdc57c0f81dd8971 -- clang/test/Frontend/Inputs/dashE/dashE.h clang/test/Frontend/Inputs/dashE/sys/a.h clang/test/Frontend/Inputs/dashE/sys/b.h clang/test/Frontend/dashE-sysincludes.cpp clang/include/clang/Frontend/PreprocessorOutputOptions.h clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Frontend/PrintPreprocessedOutput.cpp clang/test/Preprocessor/minimize-whitespace-messages.c
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 1101add97b65..f4c1b90ff5e7 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6716,8 +6716,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
types::ID InputType = Inputs[0].getType();
if (!isDerivedFromC(InputType))
D.Diag(diag::err_drv_opt_unsupported_input_type)
- << "-fminimize-whitespace"
- << types::getTypeName(InputType);
+ << "-fminimize-whitespace" << types::getTypeName(InputType);
CmdArgs.push_back("-fminimize-whitespace");
}
@@ -6727,8 +6726,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
types::ID InputType = Inputs[0].getType();
if (!isDerivedFromC(InputType))
D.Diag(diag::err_drv_opt_unsupported_input_type)
- << "-fkeep-system-includes"
- << types::getTypeName(InputType);
+ << "-fkeep-system-includes" << types::getTypeName(InputType);
CmdArgs.push_back("-fkeep-system-includes");
}
diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index 4056649e85c2..81ee1654af51 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -52,7 +52,7 @@ static void PrintMacroDefinition(const IdentifierInfo &II, const MacroInfo &MI,
}
if (MI.isGNUVarargs())
- *OS << "..."; // #define foo(x...)
+ *OS << "..."; // #define foo(x...)
*OS << ')';
}
@@ -82,6 +82,7 @@ class PrintPPOutputPPCallbacks : public PPCallbacks {
TokenConcatenation ConcatInfo;
public:
raw_ostream *OS;
+
private:
unsigned CurLine;
@@ -409,11 +410,9 @@ void PrintPPOutputPPCallbacks::InclusionDirective(
MoveToLine(HashLoc, /*RequireStartOfLine=*/true);
const std::string TokenText = PP.getSpelling(IncludeTok);
assert(!TokenText.empty());
- *OS << "#" << TokenText << " "
- << (IsAngled ? '<' : '"') << FileName << (IsAngled ? '>' : '"')
- << " /* clang -E "
- << (DumpIncludeDirectives ? "-dI" : "-fkeep-system-includes")
- << " */";
+ *OS << "#" << TokenText << " " << (IsAngled ? '<' : '"') << FileName
+ << (IsAngled ? '>' : '"') << " /* clang -E "
+ << (DumpIncludeDirectives ? "-dI" : "-fkeep-system-includes") << " */";
setEmittedDirectiveOnThisLine();
}
@@ -424,12 +423,10 @@ void PrintPPOutputPPCallbacks::InclusionDirective(
case tok::pp_import:
case tok::pp_include_next:
MoveToLine(HashLoc, /*RequireStartOfLine=*/true);
- *OS << "#pragma clang module import "
- << Imported->getFullModuleName(true)
+ *OS << "#pragma clang module import " << Imported->getFullModuleName(true)
<< " /* clang -E: implicit import for "
- << "#" << PP.getSpelling(IncludeTok) << " "
- << (IsAngled ? '<' : '"') << FileName << (IsAngled ? '>' : '"')
- << " */";
+ << "#" << PP.getSpelling(IncludeTok) << " " << (IsAngled ? '<' : '"')
+ << FileName << (IsAngled ? '>' : '"') << " */";
setEmittedDirectiveOnThisLine();
break;
@@ -513,10 +510,8 @@ static void outputPrintable(raw_ostream *OS, StringRef Str) {
if (isPrintable(Char) && Char != '\\' && Char != '"')
*OS << (char)Char;
else // Output anything hard as an octal escape.
- *OS << '\\'
- << (char)('0' + ((Char >> 6) & 7))
- << (char)('0' + ((Char >> 3) & 7))
- << (char)('0' + ((Char >> 0) & 7));
+ *OS << '\\' << (char)('0' + ((Char >> 6) & 7))
+ << (char)('0' + ((Char >> 3) & 7)) << (char)('0' + ((Char >> 0) & 7));
}
}
@@ -605,15 +600,33 @@ void PrintPPOutputPPCallbacks::PragmaWarning(SourceLocation Loc,
*OS << "#pragma warning(";
switch(WarningSpec) {
- case PWS_Default: *OS << "default"; break;
- case PWS_Disable: *OS << "disable"; break;
- case PWS_Error: *OS << "error"; break;
- case PWS_Once: *OS << "once"; break;
- case PWS_Suppress: *OS << "suppress"; break;
- case PWS_Level1: *OS << '1'; break;
- case PWS_Level2: *OS << '2'; break;
- case PWS_Level3: *OS << '3'; break;
- case PWS_Level4: *OS << '4'; break;
+ case PWS_Default:
+ *OS << "default";
+ break;
+ case PWS_Disable:
+ *OS << "disable";
+ break;
+ case PWS_Error:
+ *OS << "error";
+ break;
+ case PWS_Once:
+ *OS << "once";
+ break;
+ case PWS_Suppress:
+ *OS << "suppress";
+ break;
+ case PWS_Level1:
+ *OS << '1';
+ break;
+ case PWS_Level2:
+ *OS << '2';
+ break;
+ case PWS_Level3:
+ *OS << '3';
+ break;
+ case PWS_Level4:
+ *OS << '4';
+ break;
}
*OS << ':';
@@ -805,7 +818,6 @@ struct UnknownPragmaHandler : public PragmaHandler {
};
} // end anonymous namespace
-
static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
PrintPPOutputPPCallbacks *Callbacks) {
bool DropComments = PP.getLangOpts().TraditionalCPP &&
@@ -982,8 +994,7 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
PrintPPOutputPPCallbacks *Callbacks = new PrintPPOutputPPCallbacks(
PP, OS, !Opts.ShowLineMarkers, Opts.ShowMacros,
Opts.ShowIncludeDirectives, Opts.UseLineDirectives,
- Opts.MinimizeWhitespace, Opts.DirectivesOnly,
- Opts.KeepSystemIncludes);
+ 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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/67684
More information about the cfe-commits
mailing list