@@ -8167,7 +8167,8 @@ void VirtualMemRule::registerMatcher(ast_matchers::MatchFinder &MF) {
81678167 " CU_MEM_ACCESS_FLAGS_PROT_NONE" , " CU_MEM_ACCESS_FLAGS_PROT_READ" ,
81688168 " CU_MEM_ACCESS_FLAGS_PROT_READWRITE" ,
81698169 " CU_MEM_ALLOC_GRANULARITY_RECOMMENDED" ,
8170- " CU_MEM_ALLOC_GRANULARITY_MINIMUM" );
8170+ " CU_MEM_ALLOC_GRANULARITY_MINIMUM" , " CU_MEM_ALLOCATION_COMP_NONE" ,
8171+ " CU_MEM_ALLOCATION_COMP_GENERIC" );
81718172 };
81728173 MF.addMatcher (
81738174 callExpr (callee (functionDecl (virtualmemoryAPI ()))).bind (" vmCall" ), this );
@@ -8178,11 +8179,47 @@ void VirtualMemRule::registerMatcher(ast_matchers::MatchFinder &MF) {
81788179 MF.addMatcher (
81798180 declRefExpr (to (enumConstantDecl (virtualmemoryEnum ()))).bind (" vmEnum" ),
81808181 this );
8182+ MF.addMatcher (
8183+ memberExpr (
8184+ hasObjectExpression (hasType (qualType (
8185+ hasCanonicalType (asString (" struct CUmemAllocationProp_st" ))))),
8186+ member (hasName (" allocFlags" )),
8187+ hasParent (memberExpr (anyOf (
8188+ hasParent (implicitCastExpr (
8189+ hasCastKind (CK_LValueToRValue),
8190+ hasParent (binaryOperator (isAssignmentOperator ())))
8191+ .bind (" replaceWithZero" )),
8192+ hasParent (
8193+ binaryOperator (isAssignmentOperator ()).bind (" removeBO" )))))),
8194+ this );
81818195}
81828196
81838197void VirtualMemRule::runRule (
81848198 const ast_matchers::MatchFinder::MatchResult &Result) {
81858199 auto &SM = DpctGlobalInfo::getSourceManager ();
8200+
8201+ const Expr *ICE = getNodeAsType<ImplicitCastExpr>(Result, " replaceWithZero" );
8202+ const Expr *BO = getNodeAsType<BinaryOperator>(Result, " removeBO" );
8203+ const Expr *E = ICE ? ICE : BO;
8204+ if (E) {
8205+ // Process pattern like:
8206+ // prop.allocFlags.compressionType = CU_MEM_ALLOCATION_COMP_NONE;
8207+ // uc = prop.allocFlags.compressionType;
8208+ auto Range = getDefinitionRange (E->getBeginLoc (), E->getEndLoc ());
8209+ auto Begin = Range.getBegin ();
8210+ auto End = Range.getEnd ();
8211+ auto Length = Lexer::MeasureTokenLength (
8212+ End, SM, dpct::DpctGlobalInfo::getContext ().getLangOpts ());
8213+ Length +=
8214+ SM.getDecomposedLoc (End).second - SM.getDecomposedLoc (Begin).second ;
8215+ if (ICE) {
8216+ emplaceTransformation (new ReplaceText (Begin, Length, std::move (" 0" )));
8217+ } else {
8218+ emplaceTransformation (
8219+ new ReplaceText (Begin, Length, std::move (" (void)0" )));
8220+ }
8221+ return ;
8222+ }
81868223 if (const CallExpr *CE = getNodeAsType<CallExpr>(Result, " vmCall" )) {
81878224 ExprAnalysis EA (CE);
81888225 emplaceTransformation (EA.getReplacement ());
0 commit comments