[libc-commits] [compiler-rt] [llvm] [libc] [flang] [clang] [libcxx] [Clang] Use correct base expression for counted_by field (#73168) (PR #73465)

Aaron Ballman via libc-commits libc-commits at lists.llvm.org
Mon Nov 27 06:46:59 PST 2023


================
@@ -956,37 +956,55 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction &CGF,
   return nullptr;
 }
 
-const Expr *
-CodeGenFunction::BuildCountedByFieldExpr(const Expr *Base,
-                                         const ValueDecl *CountedByVD) {
+Expr *CodeGenFunction::BuildCountedByFieldExpr(const Expr *Base,
+                                               const ValueDecl *CountedByVD) {
   // Find the outer struct expr (i.e. p in p->a.b.c.d).
   Expr *CountedByExpr = const_cast<Expr *>(Base)->IgnoreParenImpCasts();
 
+  // Get the enclosing struct, but not the outermost enclosing struct.
+  const DeclContext *DC = CountedByVD->getLexicalDeclContext();
+  const RecordDecl *CountedByRD = dyn_cast<RecordDecl>(DC);
----------------
AaronBallman wrote:

```suggestion
  const auto *CountedByRD = dyn_cast<RecordDecl>(DC);
```

https://github.com/llvm/llvm-project/pull/73465


More information about the libc-commits mailing list