Skip to content

Commit f3c921b

Browse files
authored
[SYCLomatic] Fix the issue that vector type member access is not migrated in the uninstantiated template function #2863
Signed-off-by: intwanghao <hao3.wang@intel.com>
1 parent 57a5791 commit f3c921b

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

clang/lib/DPCT/RuleInfra/ExprAnalysis.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,26 @@ void ExprAnalysis::analyzeExpr(const CXXConstructExpr *Ctor) {
686686
}
687687
}
688688

689+
void ExprAnalysis::analyzeExpr(const CXXDependentScopeMemberExpr *CDSME) {
690+
if (auto AE = dyn_cast<ArraySubscriptExpr>(CDSME->getBase())) {
691+
auto Base = AE->getBase();
692+
if (auto BT =
693+
dyn_cast<DependentSizedArrayType>(Base->getType().getTypePtr())) {
694+
auto ET = BT->getElementType();
695+
if (isTypeInAnalysisScope(ET.getTypePtr()))
696+
return;
697+
std::string BaseType = dpct::DpctGlobalInfo::getUnqualifiedTypeName(ET);
698+
if (MapNamesLang::SupportedVectorTypes.find(BaseType) !=
699+
MapNamesLang::SupportedVectorTypes.end()) {
700+
std::string MemberName = CDSME->getMemberNameInfo().getAsString();
701+
if (MapNames::replaceName(MapNamesLang::MemberNamesMap, MemberName)) {
702+
addReplacement(CDSME->getMemberLoc(), CDSME->getEndLoc(), MemberName);
703+
}
704+
}
705+
}
706+
}
707+
}
708+
689709
void ExprAnalysis::analyzeExpr(const MemberExpr *ME) {
690710
const auto BaseType = getBaseTypeRemoveTemplateArguments(ME);
691711

clang/lib/DPCT/RuleInfra/ExprAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ class ExprAnalysis {
631631
inline void analyzeExpr(const ExprWithCleanups *EWC) {
632632
dispatch(EWC->getSubExpr());
633633
}
634-
634+
void analyzeExpr(const CXXDependentScopeMemberExpr *CDSME);
635635
void analyzeExpr(const CXXConstructExpr *Ctor);
636636
void analyzeExpr(const CXXTemporaryObjectExpr *Temp);
637637
void analyzeExpr(const CXXUnresolvedConstructExpr *Ctor);

clang/test/dpct/vector_type.cu

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ void func_char1(char1 a) {
1414
__global__ void kernel_char1(char1 *a, char1 *b) {
1515
}
1616

17+
template <int np> __global__ void kernel_foo() {
18+
constexpr int nmeta = np;
19+
float2 meta[nmeta];
20+
float KQ_cmn;
21+
for (int imeta = 1; imeta < nmeta; ++imeta) {
22+
// CHECK: KQ_cmn = sycl::fmax(KQ_cmn, (float)(meta[imeta].x()));
23+
KQ_cmn = fmaxf(KQ_cmn, meta[imeta].x);
24+
}
25+
}
26+
1727
int main_char1() {
1828
// range default constructor does the right thing.
1929
// CHECK: int8_t char1_a;

0 commit comments

Comments
 (0)