================
@@ -7016,6 +7016,21 @@ static void handleCountedByAttrField(Sema &S, Decl *D, 
const ParsedAttr &AL) {
   if (S.CheckCountedByAttrOnField(FD, CountExpr, CountInBytes, OrNull))
     return;
 
+  // --- CThisExpr Interception Block (This block swaps the DeclRefExpr out)---
+  if (auto *DRE = dyn_cast<DeclRefExpr>(CountExpr)) {
+    if (auto *TargetField = dyn_cast<FieldDecl>(DRE->getDecl())) {
+      QualType StructTy = 
S.Context.getTypeDeclType(cast<TypeDecl>(FD->getParent()));
+      QualType ThisPtrTy = S.Context.getPointerType(StructTy);
+      
+      Expr *CThis = CThisExpr::Create(S.Context, DRE->getBeginLoc(), 
ThisPtrTy);
+
+      CountExpr = MemberExpr::CreateImplicit(S.Context, CThis, 
/*IsArrow=*/true,
+                                             TargetField, 
TargetField->getType(),
+                                             VK_LValue, OK_Ordinary);
----------------
Caryoake wrote:

I understand the comment suggestion you made and the places i should look for 
in the future to add comments.

and for the the latter part , Yes exactly. In this example, accessing i inside 
the get() will creates an implicit CXXThisExpr, and an implicit MemberExpr with 
IsArrow == true. Since i am explicitly constructing CThisExpr as a pointer to 
the struct, we need to hardcode IsArrow == true so that it mirrors the 
C++behaviour. 
This is my take on it. 


https://github.com/llvm/llvm-project/pull/199241
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to