Skip to content

Commit 9997cf8

Browse files
authored
[Driver][SYCL] Do not add integration header to integration footer compile (#3907)
When compiling the integration footer with -fsycl-host-compiler, we need to be sure that the integration header is only added to the preprocessing step as opposed to being added all the time. When added all the time, the header would be processed twice, causing compilation errors due to code duplication.
1 parent 324acf6 commit 9997cf8

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4331,6 +4331,15 @@ void Clang::ConstructHostCompilerJob(Compilation &C, const JobAction &JA,
43314331
}
43324332
} else
43334333
HostCompileArgs.push_back("-E");
4334+
4335+
// Add the integration header.
4336+
StringRef Header =
4337+
TC.getDriver().getIntegrationHeader(InputFile.getBaseInput());
4338+
if (types::getPreprocessedType(InputFile.getType()) != types::TY_INVALID &&
4339+
!Header.empty()) {
4340+
HostCompileArgs.push_back(IsMSVCHostCompiler ? "-FI" : "-include");
4341+
HostCompileArgs.push_back(TCArgs.MakeArgString(Header));
4342+
}
43344343
} else if (isa<AssembleJobAction>(JA)) {
43354344
HostCompileArgs.push_back("-c");
43364345
if (IsMSVCHostCompiler)
@@ -4375,15 +4384,6 @@ void Clang::ConstructHostCompilerJob(Compilation &C, const JobAction &JA,
43754384
HostCompileArgs.push_back(Output.getFilename());
43764385
}
43774386

4378-
// Add the integration header.
4379-
StringRef Header =
4380-
TC.getDriver().getIntegrationHeader(InputFile.getBaseInput());
4381-
if (types::getPreprocessedType(InputFile.getType()) != types::TY_INVALID &&
4382-
!Header.empty()) {
4383-
HostCompileArgs.push_back(IsMSVCHostCompiler ? "-FI" : "-include");
4384-
HostCompileArgs.push_back(TCArgs.MakeArgString(Header));
4385-
}
4386-
43874387
SmallString<128> ExecPath;
43884388
if (HostCompilerDefArg) {
43894389
ExecPath = HostCompilerDefArg->getValue();

clang/test/Driver/sycl-host-compiler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
// RUN: %clangxx -fsycl-use-footer -fsycl -fsycl-host-compiler=/some/dir/g++ %s -### 2>&1 \
66
// RUN: | FileCheck -check-prefix=HOST_COMPILER %s
77
// HOST_COMPILER: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer={{.*}}"
8-
// HOST_COMPILER: g++{{.*}} "-E" "-I" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"{{.*}} "-o" "[[TMPII:.+\.ii]]"{{.*}} "-include" "[[INTHEADER]]"
9-
// HOST_COMPILER: g++{{.*}} "-I" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"{{.*}} "-o" "[[HOSTOBJ:.+\.o]]"{{.*}}
8+
// HOST_COMPILER: g++{{.*}} "-E" "-include" "[[INTHEADER]]" "-I" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"{{.*}} "-o" "[[TMPII:.+\.ii]]"
9+
// HOST_COMPILER: g++{{.*}} "-c" "-I" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"{{.*}} "-o" "[[HOSTOBJ:.+\.o]]"{{.*}}
1010
// HOST_COMPILER: ld{{.*}} "[[HOSTOBJ]]"
1111

1212
// RUN: %clang_cl -fsycl-use-footer -fsycl -fsycl-host-compiler=/some/dir/cl %s -### 2>&1 \
1313
// RUN: | FileCheck -check-prefix=HOST_COMPILER_CL %s
1414
// HOST_COMPILER_CL: clang{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-int-header=[[INTHEADER:.+\.h]]" "-fsycl-int-footer={{.*}}"
15-
// HOST_COMPILER_CL: cl{{.*}} "-P" "-Fi[[TMPII:.+\.ii]]"{{.*}} "-I" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"{{.*}} "-FI" "[[INTHEADER]]"
16-
// HOST_COMPILER_CL: cl{{.*}} "-Fo[[HOSTOBJ:.+\.obj]]"{{.*}} "-I" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"{{.*}}
15+
// HOST_COMPILER_CL: cl{{.*}} "-P" "-Fi[[TMPII:.+\.ii]]" "-FI" "[[INTHEADER]]"{{.*}} "-I" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"
16+
// HOST_COMPILER_CL: cl{{.*}} "-c" "-Fo[[HOSTOBJ:.+\.obj]]"{{.*}} "-I" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl"{{.*}}
1717
// HOST_COMPILER_CL: link{{.*}} "[[HOSTOBJ]]"
1818

1919
/// check for additional host options

0 commit comments

Comments
 (0)