[clang] [BoundsSafety][Clang][Sema][AST] Introduce CThisExpr for C __counted_by attributes (PR #199241)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Sat May 30 23:26:22 PDT 2026
================
@@ -183,26 +183,34 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes,
return true;
}
- auto *DRE = dyn_cast<DeclRefExpr>(E);
- if (!DRE) {
+ ValueDecl *VD = nullptr;
+ Expr *StrippedExpr = E->IgnoreParenImpCasts();
+
+ if (auto *ME = dyn_cast<MemberExpr>(StrippedExpr)) {
+ VD = ME->getMemberDecl();
+ } else if (auto *DRE = dyn_cast<DeclRefExpr>(StrippedExpr)) {
+ VD = DRE->getDecl();
+ }
+
+ // If we couldn't find a valid declaration in either node type, throw the error
+ if (!VD) {
Diag(E->getBeginLoc(),
diag::err_count_attr_only_support_simple_decl_reference)
<< Kind << E->getSourceRange();
return true;
}
-
- auto *CountDecl = DRE->getDecl();
- FieldDecl *CountFD = dyn_cast<FieldDecl>(CountDecl);
- if (auto *IFD = dyn_cast<IndirectFieldDecl>(CountDecl)) {
+
+ FieldDecl *CountFD = dyn_cast<FieldDecl>(VD);
+ if (auto *IFD = dyn_cast<IndirectFieldDecl>(VD)) {
CountFD = IFD->getAnonField();
}
----------------
ojhunt wrote:
give the change to the code, correct the coding style
https://github.com/llvm/llvm-project/pull/199241
More information about the cfe-commits
mailing list