Skip to content

Commit f5fff21

Browse files
authored
[SYCLomatic] Fix a bug in clang-format by cherry-pick upstream PR (#2799)
Signed-off-by: Jiang, Zhiwei <[email protected]>
1 parent 4ac0755 commit f5fff21

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,9 @@ void UnwrappedLineParser::parsePPDefine() {
12111211
return;
12121212
}
12131213

1214+
#ifdef SYCLomatic_CUSTOMIZATION
1215+
bool MaybeIncludeGuard = false;
1216+
#endif // SYCLomatic_CUSTOMIZATION
12141217
if (IncludeGuard == IG_IfNdefed &&
12151218
IncludeGuardToken->TokenText == FormatTok->TokenText) {
12161219
IncludeGuard = IG_Defined;
@@ -1221,6 +1224,9 @@ void UnwrappedLineParser::parsePPDefine() {
12211224
break;
12221225
}
12231226
}
1227+
#ifdef SYCLomatic_CUSTOMIZATION
1228+
MaybeIncludeGuard = IncludeGuard == IG_Defined;
1229+
#endif // SYCLomatic_CUSTOMIZATION
12241230
}
12251231

12261232
// In the context of a define, even keywords should be treated as normal
@@ -1231,6 +1237,13 @@ void UnwrappedLineParser::parsePPDefine() {
12311237
FormatTok->Tok.setKind(tok::identifier);
12321238
FormatTok->Tok.setIdentifierInfo(Keywords.kw_internal_ident_after_define);
12331239
nextToken();
1240+
1241+
#ifdef SYCLomatic_CUSTOMIZATION
1242+
// IncludeGuard can't have a non-empty macro definition.
1243+
if (MaybeIncludeGuard && !eof())
1244+
IncludeGuard = IG_Rejected;
1245+
#endif // SYCLomatic_CUSTOMIZATION
1246+
12341247
if (FormatTok->Tok.getKind() == tok::l_paren &&
12351248
!FormatTok->hasWhitespaceBefore()) {
12361249
parseParens();

clang/test/dpct/format/.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
IndentPPDirectives: BeforeHash

clang/test/dpct/format/BeforeHash.cu

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: cd %S
2+
// RUN: dpct --out-root %T %s --cuda-include-path="%cuda-path/include"
3+
// RUN: FileCheck %s --match-full-lines --input-file %T/BeforeHash.dp.cpp
4+
// RUN: %if build_lit %{icpx -c -fsycl %T/BeforeHash.dp.cpp -o %T/BeforeHash.dp.o %}
5+
6+
#ifndef ABCD
7+
#define ABCD 0
8+
#endif
9+
10+
// CHECK: #define DPCT_PROFILING_ENABLED
11+
// CHECK-NEXT: #include <sycl/sycl.hpp>
12+
// CHECK-NEXT: #include <dpct/dpct.hpp>
13+
// CHECK-NEXT: #include <cstdio>
14+
#include <cstdio>
15+
16+
// CHECK: void foo() {
17+
// CHECK-NEXT: dpct::event_ptr start;
18+
// CHECK-NEXT: dpct::sync_barrier(start);
19+
// CHECK-NEXT: }
20+
void foo() {
21+
cudaEvent_t start;
22+
cudaEventRecord(start);
23+
}

0 commit comments

Comments
 (0)