[PATCH] D96848: [clang][cli] Don't emit manufactured warnings

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 17 01:27:19 PST 2021


jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The switch from per-member round-trip to whole-`CompilerInvocation` round-trip in D96280 <https://reviews.llvm.org/D96280> means we'll be running the extra code present in `CompilerInvocation::CreateFromArgs`. This code conditionally manufactures extra warnings based on the target and input. This patch ensures we don't generate arguments for such manufactured warnings. Without this patch, each call to `CompilerInvocation::generateCC1CommandLine` during whole-`CompilerInvocation` round-trip could generate more arguments than the previous one.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96848

Files:
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2295,7 +2295,8 @@
 
 void CompilerInvocation::GenerateDiagnosticArgs(
     const DiagnosticOptions &Opts, SmallVectorImpl<const char *> &Args,
-    StringAllocator SA, bool DefaultDiagColor) {
+    StringAllocator SA, bool DefaultDiagColor, const llvm::Triple &T,
+    InputKind DashX) {
   const DiagnosticOptions *DiagnosticOpts = &Opts;
 #define DIAG_OPTION_WITH_MARSHALLING(                                          \
     PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,        \
@@ -2343,6 +2344,13 @@
     // This option is automatically generated from UndefPrefixes.
     if (Warning == "undef-prefix")
       continue;
+    // This warning was manufactured, don't put it on the command line.
+    if (Warning == "no-stdlibcxx-not-found" && T.isOSDarwin() &&
+        DashX.isPreprocessed())
+      continue;
+    // This warning was manufactured, don't put it on the command line.
+    if (Warning == "spir-compat" && T.isSPIR())
+      continue;
     Args.push_back(SA(StringRef("-W") + Warning));
   }
 
@@ -4831,11 +4839,12 @@
 void CompilerInvocation::generateCC1CommandLine(
     SmallVectorImpl<const char *> &Args, StringAllocator SA) const {
   llvm::Triple T(TargetOpts->Triple);
+  InputKind DashX = FrontendOpts.DashX;
 
   GenerateFileSystemArgs(FileSystemOpts, Args, SA);
   GenerateMigratorArgs(MigratorOpts, Args, SA);
   GenerateAnalyzerArgs(*AnalyzerOpts, Args, SA);
-  GenerateDiagnosticArgs(*DiagnosticOpts, Args, SA, false);
+  GenerateDiagnosticArgs(*DiagnosticOpts, Args, SA, false, T, DashX);
   GenerateFrontendArgs(FrontendOpts, Args, SA, LangOpts->IsHeaderFile);
   GenerateTargetArgs(*TargetOpts, Args, SA);
   GenerateHeaderSearchArgs(*HeaderSearchOpts, Args, SA);
Index: clang/include/clang/Frontend/CompilerInvocation.h
===================================================================
--- clang/include/clang/Frontend/CompilerInvocation.h
+++ clang/include/clang/Frontend/CompilerInvocation.h
@@ -249,7 +249,8 @@
   /// Generate command line options from DiagnosticOptions.
   static void GenerateDiagnosticArgs(const DiagnosticOptions &Opts,
                                      SmallVectorImpl<const char *> &Args,
-                                     StringAllocator SA, bool DefaultDiagColor);
+                                     StringAllocator SA, bool DefaultDiagColor,
+                                     const llvm::Triple &T, InputKind DashX);
 
   /// Parse command line options that map to LangOptions.
   static bool ParseLangArgsImpl(LangOptions &Opts, llvm::opt::ArgList &Args,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96848.324228.patch
Type: text/x-patch
Size: 2773 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210217/c7ef074b/attachment-0001.bin>


More information about the cfe-commits mailing list