Skip to content

[clang][AST] fix dereference on class/struct layouts check. #83686

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

Closed
wants to merge 1 commit into from

Conversation

devnexen
Copy link
Member

@devnexen devnexen commented Mar 2, 2024

close #83671.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Mar 2, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 2, 2024

@llvm/pr-subscribers-clang

Author: David CARLIER (devnexen)

Changes

close #83671.


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

1 Files Affected:

  • (modified) clang/lib/AST/RecordLayoutBuilder.cpp (+3-3)
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp
index a3b7431f7ffd6d..195f17d2e5a42f 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -205,15 +205,15 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
 
   // Check the fields.
   for (const FieldDecl *FD : Class->fields()) {
+    const CXXRecordDecl *MemberDecl;
     const RecordType *RT =
         Context.getBaseElementType(FD->getType())->getAs<RecordType>();
 
-    // We only care about record types.
-    if (!RT)
+    // We only care about members layout.
+    if (!RT || !(MemberDecl = RT->getAsCXXRecordDecl()))
       continue;
 
     CharUnits EmptySize;
-    const CXXRecordDecl *MemberDecl = RT->getAsCXXRecordDecl();
     const ASTRecordLayout &Layout = Context.getASTRecordLayout(MemberDecl);
     if (MemberDecl->isEmpty()) {
       // If the class decl is empty, get its size.

Copy link
Collaborator

@shafik shafik left a comment

Choose a reason for hiding this comment

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

Thank you for the PR.

We need a minimal reproducer here. Looking at the bug report it is not clear to me if this is the correct fix or not. After we have a reproducer we would need a test added to the PR and a release note.

The summary also needs to have more details. This is what usually goes into the git log and it should at least 1) summarize the issue and cause 2) summarize the approach to the fix

@bjrjk
Copy link

bjrjk commented Mar 3, 2024

Hello, this is a mininal reproducer execute with clang++ -Xclang -fdump-record-layouts-complete test.cpp:

template <class _Tp, _Tp __v>
struct integral_constant {
  static constexpr const _Tp value = __v;
  typedef integral_constant type;
};

template <bool _Val>
using _BoolConstant = integral_constant<bool, _Val>;

template <class _Tp, class _Up>
struct is_same : _BoolConstant<__is_same(_Tp, _Up)> {};

@devnexen
Copy link
Member Author

devnexen commented Mar 3, 2024

it seems there is an ongoing fix, could you possibly try so we can just close this one.

@Endilll
Copy link
Contributor

Endilll commented Mar 3, 2024

I posted a different, even shorter reduction in #83671 (comment).

@Sirraide
Copy link
Member

Sirraide commented Mar 3, 2024

it seems there is an ongoing fix, could you possibly try so we can just close this one.

Yeah, it seems that the pr I opened for #83684 also fixes both the reduced test cases for this issue (and it also doesn’t crash anymore if I try to compile the file that was linked in the issue), though it should be noted that that’s only after I noticed that there was another problem and fixed that too.

I think we should be able to close this one, unless someone comes up with a test case that still crashes anyway.

@devnexen devnexen closed this Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Clang] 19.0.0 SIGSEGV due to NULL Pointer dereference caused by receiving an NULL BaseDecl at EmptySubobjectMap::ComputeEmptySubobjectSizes()
6 participants