-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Driver] Report invalid target triple versions for all environment types. #78655
Conversation
Followup for llvm#75373 1. Make this feature not just available for android, but everyone. 2. Correct some target triples/ 3. Add opencl to the environment type list.
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: None (ZijunZhaoCCK) ChangesFollowup for #75373
Full diff: https://github.com/llvm/llvm-project/pull/78655.diff 6 Files Affected:
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1889ea28079df10..2d6986d145483b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1430,15 +1430,16 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
const ToolChain &TC = getToolChain(
*UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
- if (TC.getTriple().isAndroid()) {
- llvm::Triple Triple = TC.getTriple();
- StringRef TripleVersionName = Triple.getEnvironmentVersionString();
-
- if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "") {
- Diags.Report(diag::err_drv_triple_version_invalid)
- << TripleVersionName << TC.getTripleString();
- ContainsError = true;
- }
+ // 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;
}
// Report warning when arm64EC option is overridden by specified target
diff --git a/clang/test/CodeGen/fp128_complex.c b/clang/test/CodeGen/fp128_complex.c
index 48659d224168416..0e87cbe8ce81219 100644
--- a/clang/test/CodeGen/fp128_complex.c
+++ b/clang/test/CodeGen/fp128_complex.c
@@ -1,4 +1,4 @@
-// RUN: %clang -target aarch64-linux-gnuabi %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -target aarch64-linux-gnueabi %s -S -emit-llvm -o - | FileCheck %s
_Complex long double a, b, c, d;
void test_fp128_compound_assign(void) {
diff --git a/clang/test/Driver/mips-features.c b/clang/test/Driver/mips-features.c
index fad6009ffb89bab..18edcd05ea85c9f 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -400,12 +400,12 @@
// LONG-CALLS-DEF-NOT: "long-calls"
//
// -mbranch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
// RUN: | FileCheck --check-prefix=BRANCH-LIKELY %s
// BRANCH-LIKELY: argument unused during compilation: '-mbranch-likely'
//
// -mno-branch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
// RUN: | FileCheck --check-prefix=NO-BRANCH-LIKELY %s
// NO-BRANCH-LIKELY: argument unused during compilation: '-mno-branch-likely'
diff --git a/clang/test/Frontend/fixed_point_bit_widths.c b/clang/test/Frontend/fixed_point_bit_widths.c
index ac8db49ed516aef..e56f787e824f24a 100644
--- a/clang/test/Frontend/fixed_point_bit_widths.c
+++ b/clang/test/Frontend/fixed_point_bit_widths.c
@@ -1,7 +1,7 @@
// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4-ubuntu-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 %s | FileCheck %s
// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=ppc64 %s | FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4-windows10pro-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 %s | FileCheck %s
/* Primary signed _Accum */
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index 95014a546f72453..525ea6df3643ca6 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -273,7 +273,7 @@ class Triple {
Callable,
Mesh,
Amplification,
-
+ OpenCL,
OpenHOS,
LastEnvironmentType = OpenHOS
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index b9971c25af71f39..7bb2fb9d1365e2f 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -320,6 +320,7 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
case Callable: return "callable";
case Mesh: return "mesh";
case Amplification: return "amplification";
+ case OpenCL: return "opencl";
case OpenHOS: return "ohos";
}
@@ -687,6 +688,7 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
.StartsWith("callable", Triple::Callable)
.StartsWith("mesh", Triple::Mesh)
.StartsWith("amplification", Triple::Amplification)
+ .StartsWith("opencl", Triple::OpenCL)
.StartsWith("ohos", Triple::OpenHOS)
.Default(Triple::UnknownEnvironment);
}
@@ -1211,8 +1213,20 @@ VersionTuple Triple::getEnvironmentVersion() const {
StringRef Triple::getEnvironmentVersionString() const {
StringRef EnvironmentName = getEnvironmentName();
+
+ // none is a valid environment type - it basically amounts to a freestanding environment.
+ if (EnvironmentName == "none")
+ return "";
+
StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
EnvironmentName.consume_front(EnvironmentTypeName);
+
+ if (EnvironmentName.starts_with("-")) {
+ // arch-vendor-os-env-obj is correct
+ StringRef ObjectFormatType = getObjectFormatTypeName(getObjectFormat());
+ if (ObjectFormatType == StringRef(EnvironmentName).split('-').second)
+ return "";
+ }
return EnvironmentName;
}
|
You can test this locally with the following command:git-clang-format --diff 7a94acb2da5b20d12f13f3c5f4eb0f3f46e78e73 6f41d09f2265338b6403cbb345b7befdb84fe115 -- clang-tools-extra/test/clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-char.cpp clang/lib/Driver/Driver.cpp clang/test/CodeGen/fp128_complex.c clang/test/Driver/mips-features.c clang/test/Frontend/fixed_point_bit_widths.c llvm/include/llvm/TargetParser/Triple.h llvm/lib/TargetParser/Triple.cpp View the diff from clang-format here.diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index 98d8490cc9..5683afd583 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -255,7 +255,7 @@ public:
Cygnus,
CoreCLR,
Simulator, // Simulator variants of other systems, e.g., Apple's iOS
- MacABI, // Mac Catalyst variant of Apple's iOS deployment target.
+ MacABI, // Mac Catalyst variant of Apple's iOS deployment target.
// Shader Stages
// The order of these values matters, and must be kept in sync with the
|
Followup for llvm#75373 1. Make this feature not just available for android, but everyone. 2. Correct some target triples. 3. Add opencl to the environment type list.
Followup for llvm#75373 1. Make this feature not just available for android, but everyone. 2. Correct some target triples. 3. Add opencl to the environment type list.
Followup for llvm#75373 1. Make this feature not just available for android, but everyone. 2. Correct some target triples. 3. Add opencl to the environment type list.
@llvm/clang-vendors Adding clang vendors. FYI, this change expands error reporting on invalid version numbers to all target triples (This was previously restricted to Android triples). This can have potential downstream impact. Please review/test and let us know if this breaks any valid usages. |
Followup for llvm#75373 1. Make this feature not just available for android, but everyone. 2. Correct some target triples. 3. Add opencl to the environment type list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better title may be:
[Driver] Report invalid target triple versions for all environment types.
"Driver" is better than "clang" as it is specific about where the error arises.
Followup for llvm#75373 1. Make this feature not just available for android, but everyone. 2. Correct some target triples. 3. Add opencl to the environment type list.
Followup for llvm#75373 1. Make this feature not just available for android, but everyone. 2. Correct some target triples. 3. Add opencl to the environment type list.
This broke the wasi-threads target: |
…pes. (llvm#78655) Followup for llvm#75373 1. Make this feature not just available for android, but everyone. 2. Correct some target triples. 3. Add opencl to the environment type list.
Because The format should be And one more question, would you mind pointing me out the test case of |
We stumbled upon this downstream because we have jobs building wasi-sdk with clang-trunk, and wasi-sdk builds some things with that target. It apparently comes from WebAssembly/wasi-libc#381 |
There's apparently also wasm32-wasi-preview2 and wasm32-wasi-pthread, which I suppose are equally broken by this change. |
Yes, I think so. I think adding these environment types in wasi-libc repo could help fix those errors. |
WDYM? |
If wasm can arbitrary environment types, it seems that we can opt out the check for |
Okay, I will add this check. |
Add isWasm() check for here: #78655 (comment)
This updates the HLSL invalid environment tests to adapt to llvm#78655.
Followup for #75373