Skip to content

Commit ae37aab

Browse files
authored
[SYCLomatic]Add a check if it is an CUDA API before reporting warning message (#834)
Signed-off-by: Ni, Wenhui <[email protected]>
1 parent 9427233 commit ae37aab

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

clang/lib/DPCT/ASTTraversal.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12305,6 +12305,14 @@ void RecognizeAPINameRule::processFuncCall(const CallExpr *CE,
1230512305
std::string Namespace;
1230612306
const NamedDecl *ND = dyn_cast<NamedDecl>(CE->getCalleeDecl());
1230712307
if (ND) {
12308+
if (!dpct::DpctGlobalInfo::isInCudaPath(ND->getLocation()) &&
12309+
!isChildOrSamePath(
12310+
DpctInstallPath,
12311+
dpct::DpctGlobalInfo::getLocInfo(ND).first)) {
12312+
if (!ND->getName().startswith("cudnn") &&
12313+
!ND->getName().startswith("nccl"))
12314+
return;
12315+
}
1230812316
const auto *NSD = dyn_cast<NamespaceDecl>(ND->getDeclContext());
1230912317
if (NSD && !NSD->isInlineNamespace()) {
1231012318
if (dyn_cast<NamespaceDecl>(NSD->getDeclContext())) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: dpct --format-range=none -out-root %T/check_std_assert %s --cuda-include-path="%cuda-path/include"
2+
// RUN: FileCheck %s --match-full-lines --input-file %T/check_std_assert/check_std_assert.dp.cpp
3+
4+
#include <cassert>
5+
#include <thrust/copy.h>
6+
7+
int main(){
8+
// CHECK: int a=1;
9+
// CHECK-NEXT: // The function '__assert_fail' with the same name as cuda runtime will be used in assert func
10+
// CHECK-NEXT: // Non-CUDA APIs should not be touched or emit warning msgs
11+
// CHECK-NEXT: assert(a==0);
12+
// CHECK-NEXT: return 1;
13+
int a=1;
14+
// The function '__assert_fail' with the same name as cuda runtime will be used in assert func
15+
// Non-CUDA APIs should not be touched or emit warning msgs
16+
assert(a==0);
17+
return 1;
18+
}

0 commit comments

Comments
 (0)