Skip to content

Commit 3606d69

Browse files
authored
[clang] Fix crash when #embed used in a compound literal (llvm#102304)
Fixes llvm#102248
1 parent c62e2a2 commit 3606d69

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

clang/lib/Sema/SemaInit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,8 @@ class InitListChecker {
515515
uint64_t ElsCount = 1;
516516
// Otherwise try to fill whole array with embed data.
517517
if (Entity.getKind() == InitializedEntity::EK_ArrayElement) {
518-
ValueDecl *ArrDecl = Entity.getParent()->getDecl();
519-
auto *AType = SemaRef.Context.getAsArrayType(ArrDecl->getType());
518+
auto *AType =
519+
SemaRef.Context.getAsArrayType(Entity.getParent()->getType());
520520
assert(AType && "expected array type when initializing array");
521521
ElsCount = Embed->getDataElementCount();
522522
if (const auto *CAType = dyn_cast<ConstantArrayType>(AType))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 -std=c23 -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify -x c++ -Wno-c23-extensions %s
3+
// expected-no-diagnostics
4+
5+
char *p1 = (char[]){
6+
#embed __FILE__
7+
};
8+
9+
int *p2 = (int[]){
10+
#embed __FILE__
11+
};
12+
13+
int *p3 = (int[30]){
14+
#embed __FILE__ limit(30)
15+
};

0 commit comments

Comments
 (0)