[clang] 8d72f44 - [Clang] Do not crash when an invalid offload architecture is set
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 12 12:08:04 PDT 2022
Author: Joseph Huber
Date: 2022-10-12T14:07:52-05:00
New Revision: 8d72f445f79992fd860a73ca4ebd78c1bcc6324b
URL: https://github.com/llvm/llvm-project/commit/8d72f445f79992fd860a73ca4ebd78c1bcc6324b
DIFF: https://github.com/llvm/llvm-project/commit/8d72f445f79992fd860a73ca4ebd78c1bcc6324b.diff
LOG: [Clang] Do not crash when an invalid offload architecture is set
If an invalid architecture is set we currently return an empty string.
This will cause the offloading toolchain to continue to be built and
hit an assertion elsewhere due to the invalid architecture. This patch
fixes that so we now correctly exit.
Reviewed By: tra
Differential Revision: https://reviews.llvm.org/D135791
Added:
Modified:
clang/lib/Driver/Driver.cpp
clang/test/Driver/cuda-phases.cu
Removed:
################################################################################
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 3300919d7cdd1..45530f5d68e6c 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4273,15 +4273,27 @@ Driver::getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args,
Arg = ExtractedArg.get();
}
+ // Add or remove the seen architectures in order of appearance. If an
+ // invalid architecture is given we simply exit.
if (Arg->getOption().matches(options::OPT_offload_arch_EQ)) {
- for (StringRef Arch : llvm::split(Arg->getValue(), ","))
- Archs.insert(getCanonicalArchString(C, Args, Arch, TC->getTriple()));
+ for (StringRef Arch : llvm::split(Arg->getValue(), ",")) {
+ StringRef ArchStr =
+ getCanonicalArchString(C, Args, Arch, TC->getTriple());
+ if (ArchStr.empty())
+ return Archs;
+ Archs.insert(ArchStr);
+ }
} else if (Arg->getOption().matches(options::OPT_no_offload_arch_EQ)) {
for (StringRef Arch : llvm::split(Arg->getValue(), ",")) {
- if (Arch == StringRef("all"))
+ if (Arch == "all") {
Archs.clear();
- else
- Archs.erase(getCanonicalArchString(C, Args, Arch, TC->getTriple()));
+ } else {
+ StringRef ArchStr =
+ getCanonicalArchString(C, Args, Arch, TC->getTriple());
+ if (ArchStr.empty())
+ return Archs;
+ Archs.erase(ArchStr);
+ }
}
}
}
diff --git a/clang/test/Driver/cuda-phases.cu b/clang/test/Driver/cuda-phases.cu
index 2622c3a1bf55e..c7e8d08c6d5b8 100644
--- a/clang/test/Driver/cuda-phases.cu
+++ b/clang/test/Driver/cuda-phases.cu
@@ -318,3 +318,16 @@
// LTO-NEXT: 14: offload, "host-cuda (powerpc64le-ibm-linux-gnu)" {2}, "device-cuda (powerpc64le-ibm-linux-gnu)" {13}, ir
// LTO-NEXT: 15: backend, {14}, assembler, (host-cuda)
// LTO-NEXT: 16: assembler, {15}, object, (host-cuda)
+
+//
+// Test that the new driver does not create actions for invalid architectures.
+//
+// RUN: %clang -### -target powerpc64le-ibm-linux-gnu --offload-new-driver \
+// RUN: -ccc-print-phases --offload-arch=sm_999 -fgpu-rdc -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix=INVALID-ARCH %s
+// INVALID-ARCH: error: unsupported CUDA gpu architecture: sm_999
+// INVALID-ARCH-NEXT: 0: input, "[[INPUT:.+]]", cuda, (host-cuda)
+// INVALID-ARCH-NEXT: 1: preprocessor, {0}, cuda-cpp-output, (host-cuda)
+// INVALID-ARCH-NEXT: 2: compiler, {1}, ir, (host-cuda)
+// INVALID-ARCH-NEXT: 3: backend, {2}, assembler, (host-cuda)
+// INVALID-ARCH-NEXT: 4: assembler, {3}, object, (host-cuda)
More information about the cfe-commits
mailing list