diff options
author | ZijunZhaoCCK <88353225+ZijunZhaoCCK@users.noreply.github.com> | 2024-01-08 20:46:05 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-08 20:46:05 -0800 |
commit | f6dbd4cc5f52b6d40f98cf09af22b276b8e1f289 (patch) | |
tree | 4dc0a11ec9ce7b79eb65b0487f14c3c3e11cfc60 | |
parent | 49c35f69ac6884a07f07e7c09ca7b79282707f49 (diff) | |
download | llvm-f6dbd4cc5f52b6d40f98cf09af22b276b8e1f289.zip llvm-f6dbd4cc5f52b6d40f98cf09af22b276b8e1f289.tar.gz llvm-f6dbd4cc5f52b6d40f98cf09af22b276b8e1f289.tar.bz2 |
Make clang report invalid target versions. (#75373)
Clang always silently ignores garbage target versions and this makes
debug harder. So clang will report when target versions are invalid.
-rw-r--r-- | clang/include/clang/Basic/DiagnosticDriverKinds.td | 3 | ||||
-rw-r--r-- | clang/lib/Driver/Driver.cpp | 11 | ||||
-rw-r--r-- | clang/test/CodeGen/aarch64-fix-cortex-a53-835769.c | 6 | ||||
-rw-r--r-- | clang/test/Driver/aarch64-fix-cortex-a53-835769.c | 2 | ||||
-rw-r--r-- | clang/test/Driver/android-version.cpp | 16 | ||||
-rw-r--r-- | llvm/include/llvm/TargetParser/Triple.h | 6 | ||||
-rw-r--r-- | llvm/lib/TargetParser/Triple.cpp | 7 |
7 files changed, 45 insertions, 6 deletions
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 676f1a6..0a8a77f 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -786,4 +786,7 @@ def warn_android_unversioned_fallback : Warning< " directories will not be used in Clang 19. Provide a versioned directory" " for the target version or lower instead.">, InGroup<DiagGroup<"android-unversioned-fallback">>; + +def err_drv_triple_version_invalid : Error< + "version '%0' in target triple '%1' is invalid">; } diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 9b2f2a3..1889ea2 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1430,6 +1430,17 @@ 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; + } + } + // Report warning when arm64EC option is overridden by specified target if ((TC.getTriple().getArch() != llvm::Triple::aarch64 || TC.getTriple().getSubArch() != llvm::Triple::AArch64SubArch_arm64ec) && diff --git a/clang/test/CodeGen/aarch64-fix-cortex-a53-835769.c b/clang/test/CodeGen/aarch64-fix-cortex-a53-835769.c index 3d1a2c7..e5d7056 100644 --- a/clang/test/CodeGen/aarch64-fix-cortex-a53-835769.c +++ b/clang/test/CodeGen/aarch64-fix-cortex-a53-835769.c @@ -5,13 +5,13 @@ // RUN: %clang -O3 -target aarch64-linux-eabi -mno-fix-cortex-a53-835769 %s -S -o- 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-NO --check-prefix=CHECK %s -// RUN: %clang -O3 -target aarch64-android-eabi %s -S -o- \ +// RUN: %clang -O3 --target=aarch64-linux-androideabi %s -S -o- \ // RUN: | FileCheck --check-prefix=CHECK-YES --check-prefix=CHECK %s // RUN: %clang -O3 -target aarch64-linux-ohos %s -S -o- \ // RUN: | FileCheck --check-prefix=CHECK-YES --check-prefix=CHECK %s -// RUN: %clang -O3 -target aarch64-android-eabi -mfix-cortex-a53-835769 %s -S -o- \ +// RUN: %clang -O3 --target=aarch64-linux-androideabi -mfix-cortex-a53-835769 %s -S -o- \ // RUN: | FileCheck --check-prefix=CHECK-YES --check-prefix=CHECK %s -// RUN: %clang -O3 -target aarch64-android-eabi -mno-fix-cortex-a53-835769 %s -S -o- \ +// RUN: %clang -O3 --target=aarch64-linux-androideabi -mno-fix-cortex-a53-835769 %s -S -o- \ // RUN: | FileCheck --check-prefix=CHECK-NO --check-prefix=CHECK %s // REQUIRES: aarch64-registered-target diff --git a/clang/test/Driver/aarch64-fix-cortex-a53-835769.c b/clang/test/Driver/aarch64-fix-cortex-a53-835769.c index a854920..d7a2ad9 100644 --- a/clang/test/Driver/aarch64-fix-cortex-a53-835769.c +++ b/clang/test/Driver/aarch64-fix-cortex-a53-835769.c @@ -5,7 +5,7 @@ // RUN: %clang --target=aarch64-linux-eabi -mno-fix-cortex-a53-835769 %s -### 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-NO %s -// RUN: %clang --target=aarch64-android-eabi %s -### 2>&1 \ +// RUN: %clang --target=aarch64-linux-androideabi %s -### 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-YES %s // RUN: %clang --target=aarch64-fuchsia %s -### 2>&1 \ diff --git a/clang/test/Driver/android-version.cpp b/clang/test/Driver/android-version.cpp new file mode 100644 index 0000000..d365b70 --- /dev/null +++ b/clang/test/Driver/android-version.cpp @@ -0,0 +1,16 @@ +// Check that we get the right Android version. + +// RUN: not %clang --target=aarch64-linux-androidS -c %s -### 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-ERROR %s + +// CHECK-ERROR: error: version 'S' in target triple 'aarch64-unknown-linux-androidS' is invalid + +// RUN: not %clang --target=armv7-linux-androideabiS -c %s -### 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-ERROR1 %s + +// CHECK-ERROR1: error: version 'S' in target triple 'armv7-unknown-linux-androidS' is invalid + +// RUN: %clang --target=aarch64-linux-android31 -c %s -### 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-TARGET %s + +// CHECK-TARGET: "aarch64-unknown-linux-android31" diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h index 4790462..95014a5 100644 --- a/llvm/include/llvm/TargetParser/Triple.h +++ b/llvm/include/llvm/TargetParser/Triple.h @@ -434,6 +434,12 @@ public: /// string (separated by a '-' if the environment component is present). StringRef getOSAndEnvironmentName() const; + /// Get the version component of the environment component as a single + /// string (the version after the environment). + /// + /// For example, "fooos1.2.3" would return "1.2.3". + StringRef getEnvironmentVersionString() const; + /// @} /// @name Convenience Predicates /// @{ diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp index e935021..b9971c2 100644 --- a/llvm/lib/TargetParser/Triple.cpp +++ b/llvm/lib/TargetParser/Triple.cpp @@ -1206,11 +1206,14 @@ static VersionTuple parseVersionFromName(StringRef Name) { } VersionTuple Triple::getEnvironmentVersion() const { + return parseVersionFromName(getEnvironmentVersionString()); +} + +StringRef Triple::getEnvironmentVersionString() const { StringRef EnvironmentName = getEnvironmentName(); StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment()); EnvironmentName.consume_front(EnvironmentTypeName); - - return parseVersionFromName(EnvironmentName); + return EnvironmentName; } VersionTuple Triple::getOSVersion() const { |