Skip to content

Commit ae0cb4f

Browse files
authored
[SYCL] Create an empty integration header file with -fsycl-int-header (#3213)
When -save-temps is specified on the command-line, the Driver assumes that an integration header file gets generated and includes the file for consumption by subsequent phases. However, currently the file only gets created when there is something to emit inside it. This causes missing include file failures when a later compilation phase expects this integration header file. Signed-off-by: Premanand M Rao <[email protected]>
1 parent 43ca44a commit ae0cb4f

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,9 +2894,25 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
28942894
if (LangOpts.OpenMPIsDevice)
28952895
Res.getTargetOpts().HostTriple = Res.getFrontendOpts().AuxTriple;
28962896

2897-
// Set the triple of the host for SYCL device compile.
2898-
if (LangOpts.SYCLIsDevice)
2897+
if (LangOpts.SYCLIsDevice) {
2898+
// Set the triple of the host for SYCL device compile.
28992899
Res.getTargetOpts().HostTriple = Res.getFrontendOpts().AuxTriple;
2900+
// If specified, create an empty integration header file for now.
2901+
const StringRef &HeaderName = LangOpts.SYCLIntHeader;
2902+
if (!HeaderName.empty()) {
2903+
Expected<llvm::sys::fs::file_t> ft =
2904+
llvm::sys::fs::openNativeFileForWrite(
2905+
HeaderName, llvm::sys::fs::CD_OpenAlways, llvm::sys::fs::OF_None);
2906+
if (ft)
2907+
llvm::sys::fs::closeFile(*ft);
2908+
else {
2909+
// Emit a message but don't terminate; compilation will fail
2910+
// later if this file is absent.
2911+
llvm::errs() << "Error: " << llvm::toString(ft.takeError())
2912+
<< " when opening " << HeaderName << "\n";
2913+
}
2914+
}
2915+
}
29002916

29012917
Success &= ParseCodeGenArgs(Res.getCodeGenOpts(), Args, DashX, Diags, T,
29022918
Res.getFrontendOpts().OutputFile, LangOpts);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Test that at least an empty integration header file is created when
2+
// compiling source files with no device sycl construct.
3+
4+
// RUN: mkdir -p %t_dir
5+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-int-header=%t.h -save-temps=cwd %s
6+
// RUN: ls %t.h
7+
// RUN: rm -f %t.h
8+
// RUN: touch %t.fail.h
9+
// RUN: chmod 400 %t.fail.h
10+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-int-header=%t.fail.h %s 2>&1 | FileCheck %s --check-prefix=SYCL-BADFILE
11+
// RUN: rm -f %t.fail.h
12+
// SYCL-BADFILE: Error: {{[Pp]ermission}} denied when opening {{.*.fail.h}}

0 commit comments

Comments
 (0)