Skip to content
Merged
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
13 changes: 13 additions & 0 deletions clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,9 @@ void UnwrappedLineParser::parsePPDefine() {
return;
}

#ifdef SYCLomatic_CUSTOMIZATION
bool MaybeIncludeGuard = false;
#endif // SYCLomatic_CUSTOMIZATION
if (IncludeGuard == IG_IfNdefed &&
IncludeGuardToken->TokenText == FormatTok->TokenText) {
IncludeGuard = IG_Defined;
Expand All @@ -1221,6 +1224,9 @@ void UnwrappedLineParser::parsePPDefine() {
break;
}
}
#ifdef SYCLomatic_CUSTOMIZATION
MaybeIncludeGuard = IncludeGuard == IG_Defined;
#endif // SYCLomatic_CUSTOMIZATION
}

// In the context of a define, even keywords should be treated as normal
Expand All @@ -1231,6 +1237,13 @@ void UnwrappedLineParser::parsePPDefine() {
FormatTok->Tok.setKind(tok::identifier);
FormatTok->Tok.setIdentifierInfo(Keywords.kw_internal_ident_after_define);
nextToken();

#ifdef SYCLomatic_CUSTOMIZATION
// IncludeGuard can't have a non-empty macro definition.
if (MaybeIncludeGuard && !eof())
IncludeGuard = IG_Rejected;
#endif // SYCLomatic_CUSTOMIZATION

if (FormatTok->Tok.getKind() == tok::l_paren &&
!FormatTok->hasWhitespaceBefore()) {
parseParens();
Expand Down
1 change: 1 addition & 0 deletions clang/test/dpct/format/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IndentPPDirectives: BeforeHash
23 changes: 23 additions & 0 deletions clang/test/dpct/format/BeforeHash.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: cd %S
// RUN: dpct --out-root %T %s --cuda-include-path="%cuda-path/include"
// RUN: FileCheck %s --match-full-lines --input-file %T/BeforeHash.dp.cpp
// RUN: %if build_lit %{icpx -c -fsycl %T/BeforeHash.dp.cpp -o %T/BeforeHash.dp.o %}

#ifndef ABCD
#define ABCD 0
#endif

// CHECK: #define DPCT_PROFILING_ENABLED
// CHECK-NEXT: #include <sycl/sycl.hpp>
// CHECK-NEXT: #include <dpct/dpct.hpp>
// CHECK-NEXT: #include <cstdio>
#include <cstdio>

// CHECK: void foo() {
// CHECK-NEXT: dpct::event_ptr start;
// CHECK-NEXT: dpct::sync_barrier(start);
// CHECK-NEXT: }
void foo() {
cudaEvent_t start;
cudaEventRecord(start);
}