Skip to content

Commit b653b40

Browse files
committed
[OpenMP] Don't build the offloading driver without a source input
The Clang driver additional stages to build a complete offloading program for applications using CUDA or OpenMP offloading. This normally requires either a source file input or a valid object file to be handled. This would cause problems when trying to compile an assembly or LLVM IR file through clang with flags that would enable offloading. This patch simply adds a check to prevent the offloading toolchain from being used if we don't have a valid source file. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D125705
1 parent 5ffecd2 commit b653b40

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4377,9 +4377,11 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
43774377
Mode && Mode->getOption().matches(options::OPT_offload_device_only);
43784378

43794379
// Don't build offloading actions if explicitly disabled or we do not have a
4380-
// compile action to embed it in. If preprocessing only ignore embedding.
4381-
if (HostOnly || !(isa<CompileJobAction>(HostAction) ||
4382-
getFinalPhase(Args) == phases::Preprocess))
4380+
// valid source input and compile action to embed it in. If preprocessing only
4381+
// ignore embedding.
4382+
if (HostOnly || !types::isSrcFile(Input.first) ||
4383+
!(isa<CompileJobAction>(HostAction) ||
4384+
getFinalPhase(Args) == phases::Preprocess))
43834385
return HostAction;
43844386

43854387
ActionList OffloadActions;

clang/test/Driver/openmp-offload-gpu-new.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@
7070
// CHECK-NVIDIA-AMDGPU: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[HOST_BC]]", "[[BINARY]]"], output: "[[HOST_OBJ:.+]]"
7171
// CHECK-NVIDIA-AMDGPU: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["[[HOST_OBJ]]"], output: "a.out"
7272

73+
// RUN: %clang -x ir -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp --offload-arch=sm_52 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-IR
74+
75+
// CHECK-IR: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT_IR:.+]]"], output: "[[OBJECT:.+]]"
76+
// CHECK-IR: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["[[OBJECT]]"], output: "a.out"
77+
7378
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target=nvptx64-nvidia-cuda -march=sm_52 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-EMIT-LLVM-IR
7479
// CHECK-EMIT-LLVM-IR: "-cc1"{{.*}}"-triple" "nvptx64-nvidia-cuda"{{.*}}"-emit-llvm"
7580

0 commit comments

Comments
 (0)