Skip to content

Commit 5fd4cb6

Browse files
committed
fix
Signed-off-by: Jiang, Zhiwei <zhiwei.jiang@intel.com>
1 parent 63cd217 commit 5fd4cb6

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

clang/lib/DPCT/RuleInfra/ExprAnalysis.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "clang/AST/StmtCXX.h"
2626
#include "clang/AST/TypeLoc.h"
2727
#include "llvm/Support/raw_ostream.h"
28+
#include <optional>
2829

2930
extern clang::tooling::UnifiedPath DpctInstallPath;
3031
namespace clang {
@@ -552,9 +553,16 @@ void ExprAnalysis::analyzeExpr(const DeclRefExpr *DRE) {
552553
RefString = DRE->getNameInfo().getAsString();
553554
}
554555
if (auto TemplateDecl = dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl()))
555-
if (ConstExprExpanding) {
556-
addReplacement(0 /*FIXME*/, TemplateDecl->getNameAsString(),
557-
TemplateDecl->getIndex());
556+
if (ConstExprExpansionInfo) {
557+
auto Loc = ConstExprExpansionInfo.value().first.find(
558+
TemplateDecl->getNameAsString());
559+
// TODO: more than 1 substrings matched
560+
if (Loc != std::string::npos) {
561+
// Offset is relative to the final migrated string
562+
addReplacement(Loc + ConstExprExpansionInfo.value().second,
563+
TemplateDecl->getNameAsString(),
564+
TemplateDecl->getIndex());
565+
}
558566
} else
559567
addReplacement(DRE, TemplateDecl->getIndex());
560568
else if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl());
@@ -569,9 +577,9 @@ void ExprAnalysis::analyzeExpr(const DeclRefExpr *DRE) {
569577
// TODO: more than 1 substrings matched
570578
if (Loc != std::string::npos) {
571579
addReplacement(Loc, VDStr.size(), VDInitStr);
572-
ConstExprExpanding = true;
580+
ConstExprExpansionInfo = std::make_pair(VDInitStr, Loc);
573581
dispatch(VD->getInit());
574-
ConstExprExpanding = false;
582+
ConstExprExpansionInfo = std::nullopt;
575583
}
576584
}
577585
} else if (auto ECD = dyn_cast<EnumConstantDecl>(DRE->getDecl())) {

clang/lib/DPCT/RuleInfra/ExprAnalysis.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,9 @@ class ExprAnalysis {
719719
std::string RewritePrefix;
720720
std::string RewritePostfix;
721721
std::set<HelperFeatureEnum> HelperFeatureSet;
722-
bool ConstExprExpanding = false;
722+
std::optional<std::pair<std::string /*constexpr definitaion*/,
723+
unsigned /*constexpr offset in original str*/>>
724+
ConstExprExpansionInfo = std::nullopt;
723725

724726
public:
725727
bool IsAnalyzingCtTypeInfo = false;

clang/test/dpct/sharedmem_var_static.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ void fooh() {
229229
constexpr int kWarpSize = 32;
230230

231231
template <int ThreadsPerBlock, int NumWarpQ> __global__ void kerfunc() {
232-
constexpr int kNumWarps = ThreadsPerBlock / kWarpSize;
232+
constexpr int kNumWarps = (2 * ThreadsPerBlock / kWarpSize);
233233
__shared__ int smem[kNumWarps * NumWarpQ];
234234
}
235235

236236
void foo2() {
237-
// CHECK: sycl::local_accessor<int, 1> smem_acc_ct1(sycl::range<1>(128 / kWarpSize * 8), cgh);
237+
// CHECK: sycl::local_accessor<int, 1> smem_acc_ct1(sycl::range<1>((2 * 128 / kWarpSize) * 8), cgh);
238238
kerfunc<128, 8><<<32, 32>>>();
239239
}

0 commit comments

Comments
 (0)