Skip to content

Commit

Permalink
[Driver] Report invalid target triple versions for all environment ty…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
ZijunZhaoCCK authored Feb 5, 2024
1 parent 6590d0f commit 34c4a0f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// RUN: %check_clang_tidy %s bugprone-implicit-widening-of-multiplication-result %t -- -- -target x86_64-unknown-unknown -x c++ -fsigned-char

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

long t0(char a, char b) {
return a * b;
Expand Down
19 changes: 10 additions & 9 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1443,15 +1443,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
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGen/fp128_complex.c
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Driver/mips-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
4 changes: 2 additions & 2 deletions clang/test/Frontend/fixed_point_bit_widths.c
Original file line number Diff line number Diff line change
@@ -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 */

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/TargetParser/Triple.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class Triple {
Callable,
Mesh,
Amplification,

OpenCL,
OpenHOS,

LastEnvironmentType = OpenHOS
Expand Down
19 changes: 19 additions & 0 deletions llvm/lib/TargetParser/Triple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ 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";
}

Expand Down Expand Up @@ -692,6 +694,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);
}
Expand Down Expand Up @@ -1219,8 +1222,24 @@ 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.contains("-")) {
// -obj is the suffix
if (getObjectFormat() != Triple::UnknownObjectFormat) {
StringRef ObjectFormatTypeName =
getObjectFormatTypeName(getObjectFormat());
const std::string tmp = (Twine("-") + ObjectFormatTypeName).str();
EnvironmentName.consume_back(tmp);
}
}
return EnvironmentName;
}

Expand Down

0 comments on commit 34c4a0f

Please sign in to comment.