[llvm-branch-commits] [clang] release/19.x: [clang] Fix crash when #embed used in a compound literal (#102304) (PR #102428)
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Aug 10 03:10:22 PDT 2024
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/102428
>From 0df301ba8bc463cc27b9ec86d20b5f881c6c7866 Mon Sep 17 00:00:00 2001
From: Mariya Podchishchaeva <mariya.podchishchaeva at intel.com>
Date: Thu, 8 Aug 2024 08:51:56 +0200
Subject: [PATCH] [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)
---
clang/lib/Sema/SemaInit.cpp | 4 ++--
clang/test/Sema/embed_compound_literal.c | 15 +++++++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Sema/embed_compound_literal.c
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