Skip to content

Commit

Permalink
[SYCLomatic] Fix incorrect typecast of sycl::malloc return type in …
Browse files Browse the repository at this point in the history
…case of CUDA type redefination (#2146)


Co-authored-by: Jiang, Zhiwei <zhiwei.jiang@intel.com>
  • Loading branch information
the-slow-one and zhiweij1 authored Sep 2, 2024
1 parent 9b3c121 commit cbf7309
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion clang/lib/DPCT/CallExprRewriterCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "clang/Basic/LangOptions.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include <algorithm>
#include <cstdarg>

extern clang::tooling::UnifiedPath DpctInstallPath; // Installation directory for this tool
Expand Down Expand Up @@ -792,7 +793,11 @@ inline std::function<std::string(const CallExpr *C)> getDerefedType(size_t Idx)
DerefQT = ET->getNamedType();
if (const auto *TDT = dyn_cast<TypedefType>(DerefQT)) {
auto *TDecl = TDT->getDecl();
if (dpct::DpctGlobalInfo::isInCudaPath(TDecl->getLocation()))
const auto Redecls = TDecl->redecls();
auto IsDeclInCudaHeader = [](const TypedefNameDecl * D) {
return dpct::DpctGlobalInfo::isInCudaPath(D->getLocation());
};
if (std::any_of(Redecls.begin(), Redecls.end(), IsDeclInCudaHeader))
break;
DerefQT = TDecl->getUnderlyingType();
}
Expand Down
13 changes: 13 additions & 0 deletions clang/test/dpct/cu_mem_alloc_typedef.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// UNSUPPORTED: system-linux
// RUN: dpct --format-range=none -out-root %T/cu_mem_alloc_typedef %s --cuda-include-path="%cuda-path/include" -- -std=c++14 -x cuda --cuda-host-only
// RUN: FileCheck %s --match-full-lines --input-file %T/cu_mem_alloc_typedef/cu_mem_alloc_typedef.dp.cpp
#include <cstdint>
#include <cuda.h>

typedef uint64_t CUdeviceptr;

// CHECK: void foo(dpct::device_ptr ptr) {
void foo(CUdeviceptr ptr) {
// CHECK: ptr = (dpct::device_ptr)sycl::malloc_device(1024, dpct::get_in_order_queue());
cuMemAlloc(&ptr, 1024);
}

0 comments on commit cbf7309

Please sign in to comment.