Skip to content

Commit fbded66

Browse files
authored
[Driver] Check the environment version except wasm case. (#80783)
Add isWasm() check for here: #78655 (comment)
1 parent 4d8e849 commit fbded66

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

clang/lib/Driver/Driver.cpp

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

1446-
// Check if the environment version is valid.
1446+
// Check if the environment version is valid except wasm case.
14471447
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;
1448+
if (!Triple.isWasm()) {
1449+
StringRef TripleVersionName = Triple.getEnvironmentVersionString();
1450+
StringRef TripleObjectFormat =
1451+
Triple.getObjectFormatTypeName(Triple.getObjectFormat());
1452+
if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "" &&
1453+
TripleVersionName != TripleObjectFormat) {
1454+
Diags.Report(diag::err_drv_triple_version_invalid)
1455+
<< TripleVersionName << TC.getTripleString();
1456+
ContainsError = true;
1457+
}
14561458
}
14571459

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

clang/test/Driver/android-version.cpp renamed to clang/test/Driver/invalid-version.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,18 @@
1414
// RUN: FileCheck --check-prefix=CHECK-TARGET %s
1515

1616
// CHECK-TARGET: "aarch64-unknown-linux-android31"
17+
18+
// RUN: not %clang --target=armv7-linux-gnuS -c %s -### 2>&1 | \
19+
// RUN: FileCheck --check-prefix=CHECK-ERROR2 %s
20+
21+
// CHECK-ERROR2: error: version 'S' in target triple 'armv7-unknown-linux-gnuS' is invalid
22+
23+
// RUN: %clang --target=wasm32-unknown-wasi-preview2 -c %s -### 2>&1 | \
24+
// RUN: FileCheck --check-prefix=CHECK-WASM %s
25+
26+
// CHECK-WASM: "-triple" "wasm32-unknown-wasi-preview2"
27+
28+
// RUN: %clang --target=wasm32-wasi-pthread -c %s -### 2>&1 | \
29+
// RUN: FileCheck --check-prefix=CHECK-WASM1 %s
30+
31+
// CHECK-WASM1: "-triple" "wasm32-unknown-wasi-pthread"

0 commit comments

Comments
 (0)