Skip to content

release/19.x: [clang] Fix crash when #embed used in a compound literal (#102304) #102428

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 1 commit into from
Aug 10, 2024

Conversation

llvmbot
Copy link
Member

@llvmbot llvmbot commented Aug 8, 2024

Backport 3606d69

Requested by: @Fznamznon

@llvmbot llvmbot added this to the LLVM 19.X Release milestone Aug 8, 2024
@llvmbot
Copy link
Member Author

llvmbot commented Aug 8, 2024

@AaronBallman What do you think about merging this PR to the release branch?

@llvmbot llvmbot requested a review from AaronBallman August 8, 2024 07:01
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Aug 8, 2024
@llvmbot
Copy link
Member Author

llvmbot commented Aug 8, 2024

@llvm/pr-subscribers-clang

Author: None (llvmbot)

Changes

Backport 3606d69

Requested by: @Fznamznon


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaInit.cpp (+2-2)
  • (added) clang/test/Sema/embed_compound_literal.c (+15)
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index dc2ba039afe7f..eea4bdfa68b52 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -515,8 +515,8 @@ class InitListChecker {
     uint64_t ElsCount = 1;
     // Otherwise try to fill whole array with embed data.
     if (Entity.getKind() == InitializedEntity::EK_ArrayElement) {
-      ValueDecl *ArrDecl = Entity.getParent()->getDecl();
-      auto *AType = SemaRef.Context.getAsArrayType(ArrDecl->getType());
+      auto *AType =
+          SemaRef.Context.getAsArrayType(Entity.getParent()->getType());
       assert(AType && "expected array type when initializing array");
       ElsCount = Embed->getDataElementCount();
       if (const auto *CAType = dyn_cast<ConstantArrayType>(AType))
diff --git a/clang/test/Sema/embed_compound_literal.c b/clang/test/Sema/embed_compound_literal.c
new file mode 100644
index 0000000000000..7ba6fd8e64968
--- /dev/null
+++ b/clang/test/Sema/embed_compound_literal.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c23 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -x c++ -Wno-c23-extensions %s
+// expected-no-diagnostics
+
+char *p1 = (char[]){
+#embed __FILE__
+};
+
+int *p2 = (int[]){
+#embed __FILE__
+};
+
+int *p3 = (int[30]){
+#embed __FILE__ limit(30)
+};

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

LGTM!

@tru tru merged commit 0df301b into llvm:release/19.x Aug 10, 2024
8 of 9 checks passed
Copy link

@Fznamznon (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR.

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
Development

Successfully merging this pull request may close these issues.

4 participants