Skip to content

Commit 5b551b7

Browse files
committed
[HIP] Fix default output file for -E
By convention the default output file for -E is "-" (stdout). This is expected by tools like ccache, which uses output of -E to determine if a file and its dependence has changed. Currently clang does not use stdout as default output file for -E for HIP, which causes ccache not working. This patch fixes that. Differential Revision: https://reviews.llvm.org/D88730
1 parent 9756a40 commit 5b551b7

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4604,6 +4604,17 @@ static const char *MakeCLOutputFilename(const ArgList &Args, StringRef ArgValue,
46044604
return Args.MakeArgString(Filename.c_str());
46054605
}
46064606

4607+
static bool HasPreprocessOutput(const Action &JA) {
4608+
if (isa<PreprocessJobAction>(JA))
4609+
return true;
4610+
if (isa<OffloadAction>(JA) && isa<PreprocessJobAction>(JA.getInputs()[0]))
4611+
return true;
4612+
if (isa<OffloadBundlingJobAction>(JA) &&
4613+
HasPreprocessOutput(*(JA.getInputs()[0])))
4614+
return true;
4615+
return false;
4616+
}
4617+
46074618
const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
46084619
const char *BaseInput,
46094620
StringRef BoundArch, bool AtTopLevel,
@@ -4629,8 +4640,9 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
46294640
}
46304641

46314642
// Default to writing to stdout?
4632-
if (AtTopLevel && !CCGenDiagnostics && isa<PreprocessJobAction>(JA))
4643+
if (AtTopLevel && !CCGenDiagnostics && HasPreprocessOutput(JA)) {
46334644
return "-";
4645+
}
46344646

46354647
// Is this the assembly listing for /FA?
46364648
if (JA.getType() == types::TY_PP_Asm &&

clang/test/Driver/hip-output-file-name.hip

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,45 @@
77
// RUN: 2>&1 | FileCheck %s
88

99
// CHECK: {{.*}}clang-offload-bundler{{.*}}"-outputs=hip-output-file-name.o"
10+
11+
// Check -E default output is "-" (stdout).
12+
13+
// RUN: %clang -### -E -target x86_64-linux-gnu \
14+
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
15+
// RUN: 2>&1 | FileCheck -check-prefixes=DASH %s
16+
17+
// RUN: %clang -### -E -save-temps -target x86_64-linux-gnu \
18+
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
19+
// RUN: 2>&1 | FileCheck -check-prefixes=DASH %s
20+
21+
// RUN: %clang -### -E --cuda-device-only -target x86_64-linux-gnu \
22+
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
23+
// RUN: 2>&1 | FileCheck -check-prefixes=CLANG-DASH %s
24+
25+
// RUN: %clang -### -E --cuda-host-only -target x86_64-linux-gnu \
26+
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
27+
// RUN: 2>&1 | FileCheck -check-prefixes=CLANG-DASH %s
28+
29+
// DASH: {{.*}}clang-offload-bundler{{.*}}"-outputs=-"
30+
// CLANG-DASH: {{.*}}clang{{.*}}"-o" "-"
31+
32+
// Check -E with -o.
33+
34+
// RUN: %clang -### -E -o test.cui -target x86_64-linux-gnu \
35+
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
36+
// RUN: 2>&1 | FileCheck -check-prefixes=OUT %s
37+
38+
// RUN: %clang -### -E -o test.cui -save-temps -target x86_64-linux-gnu \
39+
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
40+
// RUN: 2>&1 | FileCheck -check-prefixes=OUT %s
41+
42+
// RUN: %clang -### -E -o test.cui --cuda-device-only -target x86_64-linux-gnu \
43+
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
44+
// RUN: 2>&1 | FileCheck -check-prefixes=CLANG-OUT %s
45+
46+
// RUN: %clang -### -E -o test.cui --cuda-host-only -target x86_64-linux-gnu \
47+
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
48+
// RUN: 2>&1 | FileCheck -check-prefixes=CLANG-OUT %s
49+
50+
// OUT: {{.*}}clang-offload-bundler{{.*}}"-outputs=test.cui"
51+
// CLANG-OUT: {{.*}}clang{{.*}}"-o" "test.cui"

0 commit comments

Comments
 (0)