================
@@ -1205,12 +1204,21 @@ llvm::Value *CodeGenFunction::GetCountedByFieldExprGEP(
   // Using getOuterLexicalRecordContext() here would be wrong because it walks
   // past named nested structs to the outermost record, causing a crash when a
   // struct with a counted_by FAM is defined nested inside another struct.
-  const RecordDecl *RD = CountDecl->getParent();
-  while (RD->isAnonymousStructOrUnion()) {
-    const auto *Parent = dyn_cast<RecordDecl>(RD->getLexicalParent());
-    if (!Parent)
-      break;
-    RD = Parent;
+  //
+  // The Base expression may itself be a pointer to a field of type 'struct'. 
If
+  // so, then we want to use that as the "base" RecordDecl.
+  QualType Ty = Base->IgnoreParenNoopCasts(getContext())->getType();
+  if (Ty->isPointerType())
+    Ty = Ty->getPointeeType();
+  const RecordDecl *RD = Ty->getAsRecordDecl();
+  if (!RD) {
+    RD = CountDecl->getParent();
----------------
rapidsna wrote:

Shouldn't the code above `const RecordDecl *RD = Ty->getAsRecordDecl();` cover 
it already?

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

Reply via email to