[clang] [Clang] Check that we have the correct RecordDecl (PR #111448)

Bill Wendling via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 7 15:28:42 PDT 2024


https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/111448

Ensure we have the correct RecordDecl before returning the Expr we're looking for.

>From 1936cd507a38d3085fa13016fb40a9a7df35a821 Mon Sep 17 00:00:00 2001
From: Bill Wendling <morbo at google.com>
Date: Mon, 7 Oct 2024 15:25:47 -0700
Subject: [PATCH] [Clang] Check that we have the correct RecordDecl

Ensure we have the correct RecordDecl before returning the Expr we're
looking for.
---
 clang/lib/CodeGen/CGExpr.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 52d2f6d52abf94..451442765620f7 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -1096,7 +1096,7 @@ class StructAccessBase
   }
   const Expr *VisitCastExpr(const CastExpr *E) {
     if (E->getCastKind() == CK_LValueToRValue)
-      return E;
+      return IsExpectedRecordDecl(E) ? E : nullptr;
     return Visit(E->getSubExpr());
   }
   const Expr *VisitParenExpr(const ParenExpr *E) {



More information about the cfe-commits mailing list