Skip to content

Conversation

@bwendling
Copy link
Collaborator

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

Ensure we have the correct RecordDecl before returning the Expr we're
looking for.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. labels Oct 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 7, 2024

@llvm/pr-subscribers-clang-codegen

Author: Bill Wendling (bwendling)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/111448.diff

1 Files Affected:

  • (modified) clang/lib/CodeGen/CGExpr.cpp (+1-1)
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) {

@llvmbot
Copy link
Member

llvmbot commented Oct 7, 2024

@llvm/pr-subscribers-clang

Author: Bill Wendling (bwendling)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/111448.diff

1 Files Affected:

  • (modified) clang/lib/CodeGen/CGExpr.cpp (+1-1)
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) {

Copy link
Collaborator

@efriedma-quic efriedma-quic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

(I can't come up with a case where it actually fails off the top of my head, but for the sake of consistency, it probably makes sense.)

@bwendling bwendling merged commit 39ac121 into llvm:main Oct 7, 2024
9 of 11 checks passed
@bwendling bwendling deleted the bdos_counted-by-fix branch October 7, 2024 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants