Skip to content

Commit 34c4a0f

Browse files
authored
[Driver] Report invalid target triple versions for all environment types. (#78655)
Followup for #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.
1 parent 6590d0f commit 34c4a0f

File tree

7 files changed

+36
-16
lines changed

7 files changed

+36
-16
lines changed

clang-tools-extra/test/clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-char.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// RUN: %check_clang_tidy %s bugprone-implicit-widening-of-multiplication-result %t -- -- -target x86_64-unknown-unknown -x c++ -fsigned-char
66

77
// RUN: %check_clang_tidy -std=c99 %s bugprone-implicit-widening-of-multiplication-result %t -- -- -target x86_64-unknown-unknown -x c -funsigned-char
8-
// RUN: %check_clang_tidy %s bugprone-implicit-widening-of-multiplication-result %t -- -- -target x86_64-unknown-unknown-x c++ -funsigned-char
8+
// RUN: %check_clang_tidy %s bugprone-implicit-widening-of-multiplication-result %t -- -- -target x86_64 c++ -funsigned-char
99

1010
long t0(char a, char b) {
1111
return a * b;

clang/lib/Driver/Driver.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,15 +1443,16 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
14431443
const ToolChain &TC = getToolChain(
14441444
*UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
14451445

1446-
if (TC.getTriple().isAndroid()) {
1447-
llvm::Triple Triple = TC.getTriple();
1448-
StringRef TripleVersionName = Triple.getEnvironmentVersionString();
1449-
1450-
if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "") {
1451-
Diags.Report(diag::err_drv_triple_version_invalid)
1452-
<< TripleVersionName << TC.getTripleString();
1453-
ContainsError = true;
1454-
}
1446+
// Check if the environment version is valid.
1447+
llvm::Triple Triple = TC.getTriple();
1448+
StringRef TripleVersionName = Triple.getEnvironmentVersionString();
1449+
StringRef TripleObjectFormat =
1450+
Triple.getObjectFormatTypeName(Triple.getObjectFormat());
1451+
if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "" &&
1452+
TripleVersionName != TripleObjectFormat) {
1453+
Diags.Report(diag::err_drv_triple_version_invalid)
1454+
<< TripleVersionName << TC.getTripleString();
1455+
ContainsError = true;
14551456
}
14561457

14571458
// Report warning when arm64EC option is overridden by specified target

clang/test/CodeGen/fp128_complex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang -target aarch64-linux-gnuabi %s -S -emit-llvm -o - | FileCheck %s
1+
// RUN: %clang -target aarch64-linux-gnueabi %s -S -emit-llvm -o - | FileCheck %s
22

33
_Complex long double a, b, c, d;
44
void test_fp128_compound_assign(void) {

clang/test/Driver/mips-features.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,12 @@
400400
// LONG-CALLS-DEF-NOT: "long-calls"
401401
//
402402
// -mbranch-likely
403-
// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
403+
// RUN: %clang --target=mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
404404
// RUN: | FileCheck --check-prefix=BRANCH-LIKELY %s
405405
// BRANCH-LIKELY: argument unused during compilation: '-mbranch-likely'
406406
//
407407
// -mno-branch-likely
408-
// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
408+
// RUN: %clang --target=mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
409409
// RUN: | FileCheck --check-prefix=NO-BRANCH-LIKELY %s
410410
// NO-BRANCH-LIKELY: argument unused during compilation: '-mno-branch-likely'
411411

clang/test/Frontend/fixed_point_bit_widths.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - %s | FileCheck %s
2-
// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4-ubuntu-fast %s | FileCheck %s
2+
// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 %s | FileCheck %s
33
// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=ppc64 %s | FileCheck %s
4-
// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4-windows10pro-fast %s | FileCheck %s
4+
// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 %s | FileCheck %s
55

66
/* Primary signed _Accum */
77

llvm/include/llvm/TargetParser/Triple.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class Triple {
276276
Callable,
277277
Mesh,
278278
Amplification,
279-
279+
OpenCL,
280280
OpenHOS,
281281

282282
LastEnvironmentType = OpenHOS

llvm/lib/TargetParser/Triple.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
323323
case Callable: return "callable";
324324
case Mesh: return "mesh";
325325
case Amplification: return "amplification";
326+
case OpenCL:
327+
return "opencl";
326328
case OpenHOS: return "ohos";
327329
}
328330

@@ -692,6 +694,7 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
692694
.StartsWith("callable", Triple::Callable)
693695
.StartsWith("mesh", Triple::Mesh)
694696
.StartsWith("amplification", Triple::Amplification)
697+
.StartsWith("opencl", Triple::OpenCL)
695698
.StartsWith("ohos", Triple::OpenHOS)
696699
.Default(Triple::UnknownEnvironment);
697700
}
@@ -1219,8 +1222,24 @@ VersionTuple Triple::getEnvironmentVersion() const {
12191222

12201223
StringRef Triple::getEnvironmentVersionString() const {
12211224
StringRef EnvironmentName = getEnvironmentName();
1225+
1226+
// none is a valid environment type - it basically amounts to a freestanding
1227+
// environment.
1228+
if (EnvironmentName == "none")
1229+
return "";
1230+
12221231
StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
12231232
EnvironmentName.consume_front(EnvironmentTypeName);
1233+
1234+
if (EnvironmentName.contains("-")) {
1235+
// -obj is the suffix
1236+
if (getObjectFormat() != Triple::UnknownObjectFormat) {
1237+
StringRef ObjectFormatTypeName =
1238+
getObjectFormatTypeName(getObjectFormat());
1239+
const std::string tmp = (Twine("-") + ObjectFormatTypeName).str();
1240+
EnvironmentName.consume_back(tmp);
1241+
}
1242+
}
12241243
return EnvironmentName;
12251244
}
12261245

0 commit comments

Comments
 (0)