Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang] Check that we have the correct RecordDecl #111448

Merged
merged 1 commit into from
Oct 7, 2024

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 labels Oct 7, 2024
@llvmbot
Copy link
Collaborator

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
Collaborator

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 clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants