@@ -8167,7 +8167,8 @@ void VirtualMemRule::registerMatcher(ast_matchers::MatchFinder &MF) {
8167
8167
" CU_MEM_ACCESS_FLAGS_PROT_NONE" , " CU_MEM_ACCESS_FLAGS_PROT_READ" ,
8168
8168
" CU_MEM_ACCESS_FLAGS_PROT_READWRITE" ,
8169
8169
" 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" );
8171
8172
};
8172
8173
MF.addMatcher (
8173
8174
callExpr (callee (functionDecl (virtualmemoryAPI ()))).bind (" vmCall" ), this );
@@ -8178,11 +8179,47 @@ void VirtualMemRule::registerMatcher(ast_matchers::MatchFinder &MF) {
8178
8179
MF.addMatcher (
8179
8180
declRefExpr (to (enumConstantDecl (virtualmemoryEnum ()))).bind (" vmEnum" ),
8180
8181
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 );
8181
8195
}
8182
8196
8183
8197
void VirtualMemRule::runRule (
8184
8198
const ast_matchers::MatchFinder::MatchResult &Result) {
8185
8199
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
+ }
8186
8223
if (const CallExpr *CE = getNodeAsType<CallExpr>(Result, " vmCall" )) {
8187
8224
ExprAnalysis EA (CE);
8188
8225
emplaceTransformation (EA.getReplacement ());
0 commit comments