[llvm-branch-commits] [clang] 0df301b - [clang] Fix crash when #embed used in a compound literal (#102304)
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Aug 10 03:10:26 PDT 2024
Author: Mariya Podchishchaeva
Date: 2024-08-10T12:10:15+02:00
New Revision: 0df301ba8bc463cc27b9ec86d20b5f881c6c7866
URL: https://github.com/llvm/llvm-project/commit/0df301ba8bc463cc27b9ec86d20b5f881c6c7866
DIFF: https://github.com/llvm/llvm-project/commit/0df301ba8bc463cc27b9ec86d20b5f881c6c7866.diff
LOG: [clang] Fix crash when #embed used in a compound literal (#102304)
Fixes https://github.com/llvm/llvm-project/issues/102248
(cherry picked from commit 3606d69d0b57dc1d23a4362e376e7ad27f650c27)
Added:
clang/test/Sema/embed_compound_literal.c
Modified:
clang/lib/Sema/SemaInit.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index dc2ba039afe7f3..eea4bdfa68b52a 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 00000000000000..7ba6fd8e649683
--- /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)
+};
More information about the llvm-branch-commits
mailing list