Skip to content

Commit 6fcfc16

Browse files
authored
[SYCLomatic] Skip CUDA SDK header path specified by the option "-isystem" in the auto-generated Makefile (#2241)
Signed-off-by: chenwei.sun <[email protected]>
1 parent 0ebaa16 commit 6fcfc16

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

clang/lib/DPCT/GenMakefile.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
#include "Utility.h"
1313
#include "ValidateArguments.h"
1414

15+
#include "ToolChains/Cuda.h"
16+
#include "clang/Driver/Driver.h"
17+
#include "clang/Driver/Options.h"
1518
#include "clang/Tooling/Refactoring.h"
1619
#include "llvm/ADT/SmallString.h"
1720
#include "llvm/ADT/StringRef.h"
1821
#include "llvm/Support/FileSystem.h"
1922
#include "llvm/Support/Path.h"
2023
#include "llvm/Support/raw_os_ostream.h"
24+
#include "llvm/TargetParser/Host.h"
2125

2226
#include <fstream>
2327
#include <string>
@@ -210,6 +214,27 @@ static void getCompileInfo(
210214
clang::tooling::UnifiedPath IncPath = Option;
211215
rewriteCanonicalDir(IncPath, InRoot, OutRoot);
212216

217+
unsigned MissingArgIndex, MissingArgCount;
218+
MissingArgIndex = MissingArgCount = 0;
219+
auto &Opts = clang::driver::getDriverOptTable();
220+
llvm::opt::InputArgList ParsedArgs =
221+
Opts.ParseArgs(nullptr, MissingArgIndex, MissingArgCount);
222+
223+
// Create minimalist CudaInstallationDetector to call the member
224+
// function validateCudaHeaderDirectory()
225+
DiagnosticsEngine E(nullptr, nullptr, nullptr, false);
226+
clang::driver::Driver Driver("", llvm::sys::getDefaultTargetTriple(),
227+
E);
228+
clang::driver::CudaInstallationDetector CudaIncludeDetector(
229+
Driver, llvm::Triple(Driver.getTargetTriple()), ParsedArgs);
230+
bool Ret = CudaIncludeDetector.validateCudaHeaderDirectory(
231+
IncPath.getCanonicalPath().str(), Driver);
232+
if (Ret) {
233+
// Skip CUDA SDK header path specified by option "-isystem" in the
234+
// auto-generated Makefile.
235+
continue;
236+
}
237+
213238
NewOptions += "-isystem ";
214239
SmallString<512> OutDirectory(IncPath.getCanonicalPath());
215240
llvm::sys::path::replace_path_prefix(OutDirectory,

clang/lib/Tooling/Core/UnifiedPath.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
namespace clang {
1313
namespace tooling {
1414
void UnifiedPath::makeCanonical(const std::string &CWD) {
15+
// To remove quotation marks from _Path
16+
if (_Path.size() >= 2 && _Path.front() == '"' && _Path.back() == '"') {
17+
_Path = _Path.substr(1, _Path.size() - 2);
18+
}
1519
if (_Path.empty()) {
1620
return;
1721
}

clang/test/dpct/gen-build-script.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// RUN: cd ..
2929
// RUN: rm -rf ./gen-build-script
3030

31-
// CHECK: -DFOOBAR -msse4.1 -mavx512vl -O2 -isystem {{.*}}/include
31+
// CHECK: -DFOOBAR -msse4.1 -mavx512vl -O2
3232

3333
void foo() {
3434
}

0 commit comments

Comments
 (0)