Skip to content

Commit

Permalink
[clang] Fix crash when #embed used in a compound literal (llvm#102304)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fznamznon authored Aug 8, 2024
1 parent c62e2a2 commit 3606d69
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
@@ -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))
15 changes: 15 additions & 0 deletions clang/test/Sema/embed_compound_literal.c
Original file line number Diff line number Diff line change
@@ -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)
};

0 comments on commit 3606d69

Please sign in to comment.