[lldb] [lld] [libc] [llvm] [compiler-rt] [clang] [flang] [Driver] Check the environment version except wasm case. (PR #80783)

via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 11:29:16 PST 2024


https://github.com/ZijunZhaoCCK updated https://github.com/llvm/llvm-project/pull/80783

>From 84506beecc20a064a5c895cf5c04135118da6606 Mon Sep 17 00:00:00 2001
From: zijunzhao <zijunzhao at google.com>
Date: Tue, 6 Feb 2024 01:58:58 +0000
Subject: [PATCH 1/2] [Driver] Check the environment version except wasm case.

---
 clang/lib/Driver/Driver.cpp | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 29db9543f3655..04d02ea500d19 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.
-  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;
+  // Check if the environment version is valid except wasm case.
+  if (!TC.getTriple().isWasm()) {
+    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;
+    }
   }
 
   // Report warning when arm64EC option is overridden by specified target

>From 33372e3d875948de91a12316cc07e5ca6222d669 Mon Sep 17 00:00:00 2001
From: zijunzhao <zijunzhao at google.com>
Date: Tue, 6 Feb 2024 01:58:58 +0000
Subject: [PATCH 2/2] [Driver] Check the environment version except wasm case.

---
 .../{android-version.cpp => invalid-version.cpp}  | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 rename clang/test/Driver/{android-version.cpp => invalid-version.cpp} (54%)

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..01bcbf277aee0 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-TARGET1 %s
+
+// CHECK-TARGET1: "wasm32-unknown-wasi-preview2"
+
+// RUN: %clang --target=wasm32-wasi-pthread -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-TARGET2 %s
+
+// CHECK-TARGET2: "wasm32-unknown-wasi-pthread"



More information about the llvm-commits mailing list