Skip to content

[clang] fix(85447): clang 18.1.0 crashes in clang::ASTContext::getTypeInfoImpl #89850

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

Merged
merged 3 commits into from
May 2, 2024

Conversation

a-tarasyuk
Copy link
Member

@a-tarasyuk a-tarasyuk commented Apr 24, 2024

Fixes #85447


This PR resolves a crash in ActOnUninitializedDecl due to an oversight in updating the isInvalidDecl state before invocation. The crash occurs due to a missing invocation of setInvalidDecl() for an invalid Anon declaration. To address this issue, the setInvalidDecl() method is now properly invoked to mark the Anon declaration as invalid before running ActOnUninitializedDecl().

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

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

llvmbot commented Apr 24, 2024

@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)

Changes

Fixes #85447


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaDecl.cpp (+3)
  • (added) clang/test/Sema/incomplete-struct-decl.cpp (+10)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5fed554d9e25c3..debe0d9e865362 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5789,6 +5789,9 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
     Anon = VarDecl::Create(Context, Owner, DS.getBeginLoc(),
                            Record->getLocation(), /*IdentifierInfo=*/nullptr,
                            Context.getTypeDeclType(Record), TInfo, SC);
+    if (Invalid)
+      Anon->setInvalidDecl();
+
     ProcessDeclAttributes(S, Anon, Dc);
 
     // Default-initialize the implicit variable. This initialization will be
diff --git a/clang/test/Sema/incomplete-struct-decl.cpp b/clang/test/Sema/incomplete-struct-decl.cpp
new file mode 100644
index 00000000000000..21e445fa170f94
--- /dev/null
+++ b/clang/test/Sema/incomplete-struct-decl.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+template <class a> using __impl_of = a; // expected-note {{'__impl_of' declared here}} \
+                                           expected-note {{template is declared here}}
+struct {                                // expected-error {{anonymous structs and classes must be class members}} \
+                                           expected-note {{to match this '{'}}
+  __impl_;                              // expected-error {{no template named '__impl_'; did you mean '__impl_of'?}} \
+                                           expected-error {{cannot specify deduction guide for alias template '__impl_of'}} \
+                                           expected-error {{expected ';' after struct}}
+                                        // expected-error {{expected '}'}}

@cor3ntin
Copy link
Contributor

Can you add a changelog entry indicating the issue fixed?

@a-tarasyuk
Copy link
Member Author

@cor3ntin Thanks for pointing this out. I've updated the PR description. Were you referring to this changelog, or is there something else I should add?

@cor3ntin
Copy link
Contributor

cor3ntin commented May 1, 2024

@a-tarasyuk in clang/docs/ReleaseNotes.rst, you should add an entry in the "Bug Fixes to C++ Support" section.
it should be a short description indicating Fixes (#GH85447)

Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

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

LGTM.
Congratulations on your first contribution!

Will you need me to merge that PR for you?

@a-tarasyuk
Copy link
Member Author

@cor3ntin If no additional feedback is needed, it would be great if you could proceed with the merge. thanks

@cor3ntin cor3ntin merged commit cd132dc into llvm:main May 2, 2024
5 checks passed
Copy link

github-actions bot commented May 2, 2024

@a-tarasyuk Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

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 18.1.0 crashes in clang::ASTContext::getTypeInfoImpl
3 participants