[PATCH] D95915: [clang][driver] Only warn once about invalid -stdlib value

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 2 19:21:44 PST 2021


tbaeder created this revision.
tbaeder added reviewers: Hahnfeld, phosek, yaxunl, rsmith.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Since ToolChain::GetCXXStdlibType() is a simple getter that might emit the "invalid library name in argument" warning, it can conceivably be called several times while initializing the build pipeline.

Before this patch, a simlpe 'clang++ -stdlib=foo ./test.cpp' would print the warning twice.

Change this and always only print the warning once. Keep the rest of the semantics of the function.

E.g,  before:

  $ clang++ -stdlib=foo ./test.cpp
  clang-10: error: invalid library name in argument '-stdlib=foo'
  clang-10: error: invalid library name in argument '-stdlib=foo'

After:

  $ bin/clang++ -stdlib=foo ./test.cpp
  clang-12: error: invalid library name in argument '-stdlib=foo'


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95915

Files:
  clang/lib/Driver/ToolChain.cpp


Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -929,8 +929,14 @@
   else if (LibName == "platform")
     return GetDefaultCXXStdlibType();
 
-  if (A)
-    getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args);
+  if (A) {
+    static bool InvalidStdlibWarned = false;
+    if (!InvalidStdlibWarned) {
+      getDriver().Diag(diag::err_drv_invalid_stdlib_name)
+          << A->getAsString(Args);
+      InvalidStdlibWarned = true;
+    }
+  }
 
   return GetDefaultCXXStdlibType();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95915.320971.patch
Type: text/x-patch
Size: 640 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210203/141594ae/attachment.bin>


More information about the cfe-commits mailing list