Skip to content

Commit ff19999

Browse files
authored
[SYCLomatic] Fix the issue that some macro cause sycl header file inserted. (#2724)
Signed-off-by: intwanghao <hao3.wang@intel.com>
1 parent 18ba075 commit ff19999

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

clang/lib/DPCT/Diagnostics/Diagnostics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ bool report(const clang::tooling::UnifiedPath &FileAbsPath, unsigned int Offset,
433433
nullptr);
434434
if (UseTextBegin)
435435
R->setInsertPosition(InsertPosition::IP_Right);
436+
R->setSYCLHeaderNeeded(false);
436437
DpctGlobalInfo::getInstance().addReplacement(R);
437438
UniqueID++;
438439
}

clang/lib/DPCT/PreProcessor.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ bool IncludesCallbacks::ReplaceCuMacro(const Token &MacroNameTok,
136136
0, SM, LangOptions())),
137137
SM, LangOptions())
138138
.str());
139+
} else if (MacroName == "__CUDACC_VER_MAJOR__" ||
140+
MacroName == "__CUDACC_VER_MINOR__") {
141+
if (MacroNameTok.getIdentifierInfo()->hasMacroDefinition()) {
142+
Repl->setSYCLHeaderNeeded(false);
143+
} else {
144+
return false;
145+
}
139146
}
140147
if (DpctGlobalInfo::getContext().getLangOpts().CUDA) {
141148
// These two macros are defined by CUDA compiler
@@ -757,6 +764,10 @@ void IncludesCallbacks::ReplaceCuMacro(SourceRange ConditionRange, IfType IT,
757764
} else if ((MacroName != "__CUDACC__" ||
758765
DpctGlobalInfo::getMacroDefines().count(MacroName)) &&
759766
MacroName != "__CUDA_ARCH__") {
767+
if (MacroName == "__CUDACC_VER_MAJOR__" ||
768+
MacroName == "__CUDACC_VER_MINOR__") {
769+
Repl->setSYCLHeaderNeeded(false);
770+
}
760771
TransformSet.emplace_back(Repl);
761772
}
762773
// check next

clang/test/dpct/c_source_file_test/test.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#include <stdlib.h>
66
#include <stdio.h>
77

8-
// CHECK: #if defined(__ARM_NEON) && defined(SYCL_LANGUAGE_VERSION)
8+
// CHECK: #if defined(__ARM_NEON) && defined(SYCL_LANGUAGE_VERSION) && (DPCT_COMPAT_RT_MAJOR_VERSION == 11 && DPCT_COMPAT_RT_MINOR_VERSION < 2)
99
// CHECK: typedef uint16_t fp16_t;
1010
// CHECK: #endif
11-
#if defined(__ARM_NEON) && defined(__CUDACC__)
11+
#if defined(__ARM_NEON) && defined(__CUDACC__) && (__CUDACC_VER_MAJOR__ == 11 && __CUDACC_VER_MINOR__ < 2)
1212
typedef uint16_t fp16_t;
1313
#endif
1414

0 commit comments

Comments
 (0)