[clang] fbded66 - [Driver] Check the environment version except wasm case. (#80783)

via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 6 15:40:30 PST 2024


Author: ZijunZhaoCCK
Date: 2024-02-06T15:40:27-08:00
New Revision: fbded6663fb04d12f451c18bc8018989d2db3a87

URL: https://github.com/llvm/llvm-project/commit/fbded6663fb04d12f451c18bc8018989d2db3a87
DIFF: https://github.com/llvm/llvm-project/commit/fbded6663fb04d12f451c18bc8018989d2db3a87.diff

LOG: [Driver] Check the environment version except wasm case. (#80783)

Add isWasm() check for here:
https://github.com/llvm/llvm-project/pull/78655#issuecomment-1928075569

Added: 
    clang/test/Driver/invalid-version.cpp

Modified: 
    clang/lib/Driver/Driver.cpp

Removed: 
    clang/test/Driver/android-version.cpp


################################################################################
diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 29db9543f3655..00e14071a4afe 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1443,16 +1443,18 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
   const ToolChain &TC = getToolChain(
       *UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
 
-  // Check if the environment version is valid.
+  // Check if the environment version is valid except wasm case.
   llvm::Triple Triple = TC.getTriple();
-  StringRef TripleVersionName = Triple.getEnvironmentVersionString();
-  StringRef TripleObjectFormat =
-      Triple.getObjectFormatTypeName(Triple.getObjectFormat());
-  if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "" &&
-      TripleVersionName != TripleObjectFormat) {
-    Diags.Report(diag::err_drv_triple_version_invalid)
-        << TripleVersionName << TC.getTripleString();
-    ContainsError = true;
+  if (!Triple.isWasm()) {
+    StringRef TripleVersionName = Triple.getEnvironmentVersionString();
+    StringRef TripleObjectFormat =
+        Triple.getObjectFormatTypeName(Triple.getObjectFormat());
+    if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "" &&
+        TripleVersionName != TripleObjectFormat) {
+      Diags.Report(diag::err_drv_triple_version_invalid)
+          << TripleVersionName << TC.getTripleString();
+      ContainsError = true;
+    }
   }
 
   // Report warning when arm64EC option is overridden by specified target

diff  --git a/clang/test/Driver/android-version.cpp b/clang/test/Driver/invalid-version.cpp
similarity index 54%
rename from clang/test/Driver/android-version.cpp
rename to clang/test/Driver/invalid-version.cpp
index d365b701c0223..6a4702a9b66b0 100644
--- a/clang/test/Driver/android-version.cpp
+++ b/clang/test/Driver/invalid-version.cpp
@@ -14,3 +14,18 @@
 // RUN:   FileCheck --check-prefix=CHECK-TARGET %s
 
 // CHECK-TARGET: "aarch64-unknown-linux-android31"
+
+// RUN: not %clang --target=armv7-linux-gnuS -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-ERROR2 %s
+
+// CHECK-ERROR2: error: version 'S' in target triple 'armv7-unknown-linux-gnuS' is invalid
+
+// RUN: %clang --target=wasm32-unknown-wasi-preview2 -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-WASM %s
+
+// CHECK-WASM: "-triple" "wasm32-unknown-wasi-preview2"
+
+// RUN: %clang --target=wasm32-wasi-pthread -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-WASM1 %s
+
+// CHECK-WASM1: "-triple" "wasm32-unknown-wasi-pthread"


        


More information about the cfe-commits mailing list