[clang] [Driver] Check the environment version except wasm case. (PR #80783)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 6 14:14:58 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/3] [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/3] [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"
>From 3af518cee001a0c4ec27ded86ceca5927c0cf86d Mon Sep 17 00:00:00 2001
From: zijunzhao <zijunzhao at google.com>
Date: Tue, 6 Feb 2024 01:58:58 +0000
Subject: [PATCH 3/3] [Driver] Check the environment version except wasm case.
---
clang/lib/Driver/Driver.cpp | 4 ++--
clang/test/Driver/invalid-version.cpp | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 04d02ea500d19..00e14071a4afe 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1444,8 +1444,8 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
*UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
// Check if the environment version is valid except wasm case.
- if (!TC.getTriple().isWasm()) {
- llvm::Triple Triple = TC.getTriple();
+ llvm::Triple Triple = TC.getTriple();
+ if (!Triple.isWasm()) {
StringRef TripleVersionName = Triple.getEnvironmentVersionString();
StringRef TripleObjectFormat =
Triple.getObjectFormatTypeName(Triple.getObjectFormat());
diff --git a/clang/test/Driver/invalid-version.cpp b/clang/test/Driver/invalid-version.cpp
index 01bcbf277aee0..6a4702a9b66b0 100644
--- a/clang/test/Driver/invalid-version.cpp
+++ b/clang/test/Driver/invalid-version.cpp
@@ -21,11 +21,11 @@
// 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
+// RUN: FileCheck --check-prefix=CHECK-WASM %s
-// CHECK-TARGET1: "wasm32-unknown-wasi-preview2"
+// CHECK-WASM: "-triple" "wasm32-unknown-wasi-preview2"
// RUN: %clang --target=wasm32-wasi-pthread -c %s -### 2>&1 | \
-// RUN: FileCheck --check-prefix=CHECK-TARGET2 %s
+// RUN: FileCheck --check-prefix=CHECK-WASM1 %s
-// CHECK-TARGET2: "wasm32-unknown-wasi-pthread"
+// CHECK-WASM1: "-triple" "wasm32-unknown-wasi-pthread"
More information about the cfe-commits
mailing list