Skip to content

Commit 0666f52

Browse files
authored
[Driver][SYCL] Retain comments when preprocessing for integration footer (#3918)
When generating the source file that has the integration footer appended too, we want to retain the comments, which will improve verification and diagnostic information.
1 parent 18ac172 commit 0666f52

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,17 @@ static void handleAMDGPUCodeObjectVersionOptions(const Driver &D,
11481148
}
11491149
}
11501150

1151+
/// Check whether the given input tree contains any append footer actions
1152+
static bool ContainsAppendFooterAction(const Action *A) {
1153+
if (isa<AppendFooterJobAction>(A))
1154+
return true;
1155+
for (const auto &AI : A->inputs())
1156+
if (ContainsAppendFooterAction(AI))
1157+
return true;
1158+
1159+
return false;
1160+
}
1161+
11511162
void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
11521163
const Driver &D, const ArgList &Args,
11531164
ArgStringList &CmdArgs,
@@ -1161,6 +1172,13 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
11611172
Args.AddLastArg(CmdArgs, options::OPT_C);
11621173
Args.AddLastArg(CmdArgs, options::OPT_CC);
11631174

1175+
// When preprocessing using the integration footer, add the comments
1176+
// to the first preprocessing step.
1177+
if (JA.isOffloading(Action::OFK_SYCL) && !ContainsAppendFooterAction(&JA) &&
1178+
Args.hasArg(options::OPT_fsycl_use_footer) &&
1179+
JA.isDeviceOffloading(Action::OFK_None))
1180+
CmdArgs.push_back("-C");
1181+
11641182
// Handle dependency file generation.
11651183
Arg *ArgM = Args.getLastArg(options::OPT_MM);
11661184
if (!ArgM)
@@ -4232,17 +4250,6 @@ static bool ContainsWrapperAction(const Action *A) {
42324250
return false;
42334251
}
42344252

4235-
/// Check whether the given input tree contains any append footer actions
4236-
static bool ContainsAppendFooterAction(const Action *A) {
4237-
if (isa<AppendFooterJobAction>(A))
4238-
return true;
4239-
for (const auto &AI : A->inputs())
4240-
if (ContainsAppendFooterAction(AI))
4241-
return true;
4242-
4243-
return false;
4244-
}
4245-
42464253
// Put together an external compiler compilation call which is used instead
42474254
// of the clang invocation for the host compile of an offload compilation.
42484255
// Enabling command line: clang++ -fsycl -fsycl-host-compiler=<HostExe>

clang/test/Driver/sycl-int-footer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: %clangxx -fsycl -fsycl-use-footer %s -### 2>&1 \
33
// RUN: | FileCheck -check-prefix FOOTER %s
44
// FOOTER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer=[[INTFOOTER:.+\h]]" "-sycl-std={{.*}}"
5-
// FOOTER: clang{{.*}} "-include" "[[INTHEADER]]"{{.*}} "-fsycl-is-host"{{.*}} "-E"{{.*}} "-o" "[[PREPROC:.+\.ii]]"
5+
// FOOTER: clang{{.*}} "-include" "[[INTHEADER]]"{{.*}} "-fsycl-is-host"{{.*}} "-E"{{.*}} "-C"{{.*}} "-o" "[[PREPROC:.+\.ii]]"
66
// FOOTER: append-file{{.*}} "[[PREPROC]]" "--append=[[INTFOOTER]]" "--output=[[APPENDEDSRC:.+\.cpp]]"
77
// FOOTER: clang{{.*}} "-fsycl-is-host"{{.*}} "[[APPENDEDSRC]]"
88
// FOOTER-NOT: "-include" "[[INTHEADER]]"

0 commit comments

Comments
 (0)