Skip to content

Commit c3db834

Browse files
authored
[SYCLomatic] Fix the migration bug of __attribute__(__noinline__). (#2387)
Signed-off-by: Tang, Jiajun [email protected]
1 parent 4ec14dc commit c3db834

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

clang/include/clang/Lex/Preprocessor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3020,6 +3020,10 @@ class Preprocessor {
30203020
bool setDeserializedSafeBufferOptOutMap(
30213021
const SmallVectorImpl<SourceLocation> &SrcLocSeqs);
30223022

3023+
#ifdef SYCLomatic_CUSTOMIZATION
3024+
bool IsInAttr = false;
3025+
#endif // SYCLomatic_CUSTOMIZATION
3026+
30233027
private:
30243028
/// Helper functions to forward lexing to the actual lexer. They all share the
30253029
/// same signature.

clang/lib/DPCT/ASTTraversal.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ void IncludesCallbacks::MacroDefined(const Token &MacroNameTok,
279279
if (!II)
280280
continue;
281281

282+
// The "__noinline__" macro is re-defined and it is used in
283+
// "__attribute__()", do not migrate it.
284+
if (II->hasMacroDefinition() && (II->getName() == "__noinline__")) {
285+
continue;
286+
}
287+
282288
auto ItRule = MapNames::MacroRuleMap.find(II->getName().str());
283289
if (ItRule != MapNames::MacroRuleMap.end()) {
284290
TransformSet.emplace_back(

clang/lib/Lex/Preprocessor.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,15 @@ bool Preprocessor::HandleIdentifier(Token &Identifier) {
815815
HandlePoisonedIdentifier(Identifier);
816816
}
817817

818+
#ifdef SYCLomatic_CUSTOMIZATION
819+
// The "__noinline__" macro is re-defined and it is used in "__attribute__()",
820+
// do not handle it.
821+
if (LangOpts.CUDA && Identifier.is(tok::TokenKind::kw___noinline__) &&
822+
IsInAnalysisScopeFunc(Identifier.getLocation()) && IsInAttr) {
823+
return true;
824+
}
825+
#endif // SYCLomatic_CUSTOMIZATION
826+
818827
// If this is a macro to be expanded, do it.
819828
if (const MacroDefinition MD = getMacroDefinition(&II)) {
820829
const auto *MI = MD.getMacroInfo();

clang/lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ void Parser::ParseGNUAttributes(ParsedAttributes &Attrs,
193193

194194
SourceLocation StartLoc = Tok.getLocation();
195195
SourceLocation EndLoc = StartLoc;
196+
#ifdef SYCLomatic_CUSTOMIZATION
197+
// Set the 'IsInAttr' to true before parse the arguments of __attribute__(()).
198+
// Then we can handle the macro in __attribute__ arguments specially.
199+
llvm::SaveAndRestore<bool> SART(PP.IsInAttr, true);
200+
#endif // SYCLomatic_CUSTOMIZATION
196201

197202
while (Tok.is(tok::kw___attribute)) {
198203
SourceLocation AttrTokLoc = ConsumeToken();

clang/test/dpct/noinline.cu

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,10 @@ __noinline__ __host__ __device__ scalar_t calc_igammac(scalar_t a, scalar_t b) {
4949
scalar_t c = a + b;
5050
return c;
5151
}
52+
53+
// CHECK: __attribute__((__noinline__)) void macro_with_attr() {}
54+
__attribute__((__noinline__)) void macro_with_attr() {}
55+
// CHECK: #define NOINLINE __attribute__((__noinline__))
56+
#define NOINLINE __attribute__((__noinline__))
57+
// CHECK: NOINLINE void macro_in_macro_with_attr() {}
58+
NOINLINE void macro_in_macro_with_attr() {}

0 commit comments

Comments
 (0)