Skip to content

Commit f440f44

Browse files
committed
Make clang report invalid target versions for all environment.
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.
1 parent 8947469 commit f440f44

File tree

6 files changed

+30
-15
lines changed

6 files changed

+30
-15
lines changed

clang/lib/Driver/Driver.cpp

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

1433-
if (TC.getTriple().isAndroid()) {
1434-
llvm::Triple Triple = TC.getTriple();
1435-
StringRef TripleVersionName = Triple.getEnvironmentVersionString();
1436-
1437-
if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "") {
1438-
Diags.Report(diag::err_drv_triple_version_invalid)
1439-
<< TripleVersionName << TC.getTripleString();
1440-
ContainsError = true;
1441-
}
1433+
// Check if the environment version is valid.
1434+
llvm::Triple Triple = TC.getTriple();
1435+
StringRef TripleVersionName = Triple.getEnvironmentVersionString();
1436+
StringRef TripleObjectFormat = Triple.getObjectFormatTypeName(Triple.getObjectFormat());
1437+
1438+
if (Triple.getEnvironmentVersion().empty() && TripleVersionName != ""
1439+
&& TripleVersionName != TripleObjectFormat) {
1440+
Diags.Report(diag::err_drv_triple_version_invalid)
1441+
<< TripleVersionName << TC.getTripleString();
1442+
ContainsError = true;
14421443
}
14431444

14441445
// 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
@@ -273,7 +273,7 @@ class Triple {
273273
Callable,
274274
Mesh,
275275
Amplification,
276-
276+
OpenCL,
277277
OpenHOS,
278278

279279
LastEnvironmentType = OpenHOS

llvm/lib/TargetParser/Triple.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
320320
case Callable: return "callable";
321321
case Mesh: return "mesh";
322322
case Amplification: return "amplification";
323+
case OpenCL: return "opencl";
323324
case OpenHOS: return "ohos";
324325
}
325326

@@ -687,6 +688,7 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
687688
.StartsWith("callable", Triple::Callable)
688689
.StartsWith("mesh", Triple::Mesh)
689690
.StartsWith("amplification", Triple::Amplification)
691+
.StartsWith("opencl", Triple::OpenCL)
690692
.StartsWith("ohos", Triple::OpenHOS)
691693
.Default(Triple::UnknownEnvironment);
692694
}
@@ -1211,8 +1213,20 @@ VersionTuple Triple::getEnvironmentVersion() const {
12111213

12121214
StringRef Triple::getEnvironmentVersionString() const {
12131215
StringRef EnvironmentName = getEnvironmentName();
1216+
1217+
// none is a valid environment type - it basically amounts to a freestanding environment.
1218+
if (EnvironmentName == "none")
1219+
return "";
1220+
12141221
StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
12151222
EnvironmentName.consume_front(EnvironmentTypeName);
1223+
1224+
if (EnvironmentName.starts_with("-")) {
1225+
// arch-vendor-os-env-obj is correct
1226+
StringRef ObjectFormatType = getObjectFormatTypeName(getObjectFormat());
1227+
if (ObjectFormatType == StringRef(EnvironmentName).split('-').second)
1228+
return "";
1229+
}
12161230
return EnvironmentName;
12171231
}
12181232

0 commit comments

Comments
 (0)