diff --git a/clang/lib/DPCT/AnalysisInfo.cpp b/clang/lib/DPCT/AnalysisInfo.cpp index 855d6414a7d9..67fe389b928e 100644 --- a/clang/lib/DPCT/AnalysisInfo.cpp +++ b/clang/lib/DPCT/AnalysisInfo.cpp @@ -2947,7 +2947,7 @@ void MemVarInfo::migrateToDeviceGlobal(const VarDecl *MemVar) { auto &Ctx = DpctGlobalInfo::getContext(); auto &MacroArgMap = DpctGlobalInfo::getMacroArgRecordMap(); auto TSI = MemVar->getTypeSourceInfo(); - auto OriginTL = TSI->getTypeLoc(); + auto OriginTL = TSI->getTypeLoc().getUnqualifiedLoc().getAs(); auto TL = OriginTL; auto BegLoc = MemVar->getBeginLoc(); if (BegLoc.isMacroID()) { diff --git a/clang/lib/DPCT/RulesLang/RulesLangNoneAPIAndType.cpp b/clang/lib/DPCT/RulesLang/RulesLangNoneAPIAndType.cpp index d6c423f56059..027c92263670 100644 --- a/clang/lib/DPCT/RulesLang/RulesLangNoneAPIAndType.cpp +++ b/clang/lib/DPCT/RulesLang/RulesLangNoneAPIAndType.cpp @@ -809,7 +809,6 @@ void MemVarAnalysisRule::runRule(const MatchFinder::MatchResult &Result) { auto MemVarRef = getNodeAsType(Result, "used"); auto Func = getAssistNodeAsType(Result, "func"); auto Decl = getAssistNodeAsType(Result, "decl"); - DpctGlobalInfo &Global = DpctGlobalInfo::getInstance(); if (MemVarRef && Func && Decl) { if (isCubVar(Decl)) { return; @@ -820,8 +819,11 @@ void MemVarAnalysisRule::runRule(const MatchFinder::MatchResult &Result) { return; if (VD == nullptr) return; - - auto Var = Global.findMemVarInfo(VD); + std::string CanonicalType = VD->getType().getCanonicalType().getAsString(); + if (CanonicalType.find("block_tile_memory") != std::string::npos) { + return; + } + auto Var = MemVarInfo::buildMemVarInfo(VD); if (Func->hasAttr() || Func->hasAttr()) { if (!(DpctGlobalInfo::useGroupLocalMemory() && VD->hasAttr() && diff --git a/clang/test/dpct/device_global/device_global2.cu b/clang/test/dpct/device_global/device_global2.cu new file mode 100644 index 000000000000..229da96fe4db --- /dev/null +++ b/clang/test/dpct/device_global/device_global2.cu @@ -0,0 +1,20 @@ +// RUN: dpct --format-range=none --use-experimental-features=device_global -in-root %S -out-root %T/device_global2 %S/device_global2.cu --cuda-include-path="%cuda-path/include" -- -std=c++14 -x cuda --cuda-host-only +// RUN: FileCheck --input-file %T/device_global2/device_global2.dp.cpp --match-full-lines %s + +#include +#include +#include + +// CHECK: static sycl::ext::oneapi::experimental::device_global var_a; +__device__ int var_a; + +// CHECK: static constexpr sycl::ext::oneapi::experimental::device_global var_b {-1, -1}; +static constexpr __device__ int8_t var_b[2] = {-1, -1}; + +template +__global__ void kernel(T b) { + var_a; + var_b[0]; +} + +template __global__ void kernel(int b);