Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCLomatic] Fix migration bug of __attribute__(__noinline__). #2387

Open
wants to merge 2 commits into
base: SYCLomatic
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions clang/lib/DPCT/ASTTraversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ bool IncludesCallbacks::ReplaceCuMacro(const Token &MacroNameTok,
std::string MacroName = MacroNameTok.getIdentifierInfo()->getName().str();
auto Iter = MapNames::MacroRuleMap.find(MacroName);
if (Iter != MapNames::MacroRuleMap.end()) {
// The "__noinline__" macro is re-defined by CUDA compiler.
// When it is used in "__attribute__()", we cannot replace it.
if (MacroName == "__noinline__") {
auto Range = getDefinitionRange(MacroNameTok.getLocation(),
MacroNameTok.getEndLoc());
const auto next = Lexer::findNextToken(Range.getEnd(), SM, LangOptions());
if (next.has_value() && next->is(tok::TokenKind::r_paren)) {
return false;
}
}
auto Repl = generateReplacement(MacroNameTok.getLocation(), Iter->second);
if (MacroName == "__CUDA_ARCH__") {
if (DpctGlobalInfo::getInstance().getContext().getLangOpts().CUDA) {
Expand Down Expand Up @@ -279,6 +289,12 @@ void IncludesCallbacks::MacroDefined(const Token &MacroNameTok,
if (!II)
continue;

// The "__noinline__" macro is re-defined by CUDA compiler.
// When it is used in "__attribute__()", we cannot replace it.
if (II->hasMacroDefinition() && (II->getName() == "__noinline__")) {
continue;
}

auto ItRule = MapNames::MacroRuleMap.find(II->getName().str());
if (ItRule != MapNames::MacroRuleMap.end()) {
TransformSet.emplace_back(
Expand Down
7 changes: 7 additions & 0 deletions clang/test/dpct/noinline.cu
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ __noinline__ __host__ __device__ scalar_t calc_igammac(scalar_t a, scalar_t b) {
scalar_t c = a + b;
return c;
}

// CHECK: __attribute__((__noinline__)) void macro_with_attr() {}
__attribute__((__noinline__)) void macro_with_attr() {}
// CHECK: #define NOINLINE __attribute__((__noinline__))
#define NOINLINE __attribute__((__noinline__))
// CHECK: NOINLINE void macro_in_macro_with_attr() {}
NOINLINE void macro_in_macro_with_attr() {}