https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/77298
>From 68e21b7604964b7b391d9a077ca52175af21b65a Mon Sep 17 00:00:00 2001 From: Nikita Popov <npo...@redhat.com> Date: Mon, 8 Jan 2024 12:41:34 +0100 Subject: [PATCH 1/3] [clang] Fix assertion failure when initializing union with FAM When initializing a union that constrain a struct with a flexible array member, and the initializer list is empty, we currently trigger an assertion failure. This happens because getFlexibleArrayInitChars() assumes that the initializer list is non-empty. Fixes https://github.com/llvm/llvm-project/issues/77085. --- clang/lib/AST/Decl.cpp | 2 +- clang/test/CodeGen/flexible-array-init.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 12e0a6faa4c33d..e1440e5183a4e6 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -2835,7 +2835,7 @@ CharUnits VarDecl::getFlexibleArrayInitChars(const ASTContext &Ctx) const { if (!Ty || !Ty->getDecl()->hasFlexibleArrayMember()) return CharUnits::Zero(); auto *List = dyn_cast<InitListExpr>(getInit()->IgnoreParens()); - if (!List) + if (!List || List->getNumInits() == 0) return CharUnits::Zero(); const Expr *FlexibleInit = List->getInit(List->getNumInits() - 1); auto InitTy = Ctx.getAsConstantArrayType(FlexibleInit->getType()); diff --git a/clang/test/CodeGen/flexible-array-init.c b/clang/test/CodeGen/flexible-array-init.c index b2cf959f7e1220..bae926da5feb07 100644 --- a/clang/test/CodeGen/flexible-array-init.c +++ b/clang/test/CodeGen/flexible-array-init.c @@ -20,3 +20,11 @@ struct __attribute((packed, aligned(4))) { char a; int x; char z[]; } e = { 1, 2 struct { int x; char y[]; } f = { 1, { 13, 15 } }; // CHECK: @f ={{.*}} global <{ i32, [2 x i8] }> <{ i32 1, [2 x i8] c"\0D\0F" }> + +union { + struct { + int a; + char b[]; + } x; +} in_union = {}; +// CHECK: @in_union ={{.*}} global %union.anon zeroinitializer >From ef0cf9bbaf3bf8adda045b19b8213a7573113f6a Mon Sep 17 00:00:00 2001 From: Nikita Popov <npo...@redhat.com> Date: Mon, 8 Jan 2024 15:46:10 +0100 Subject: [PATCH 2/3] Add release note --- clang/docs/ReleaseNotes.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index c9b577bd549b1e..02a235223dafdc 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -696,6 +696,9 @@ Bug Fixes in This Version - Clang now accepts recursive non-dependent calls to functions with deduced return type. Fixes (`#71015 <https://github.com/llvm/llvm-project/issues/71015>`_) +- Fix assertion failure when initializing union containing struct with + flexible array member using empty initializer list. + Fixes (`#77085 <https://github.com/llvm/llvm-project/issues/77085>`) Bug Fixes to Compiler Builtins >From b23017e27df4b50a29828c811c65f37c43111bdd Mon Sep 17 00:00:00 2001 From: Nikita Popov <npo...@redhat.com> Date: Mon, 8 Jan 2024 17:24:25 +0100 Subject: [PATCH 3/3] Add underscore --- clang/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 02a235223dafdc..0a8f8dec38ea58 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -698,7 +698,7 @@ Bug Fixes in This Version Fixes (`#71015 <https://github.com/llvm/llvm-project/issues/71015>`_) - Fix assertion failure when initializing union containing struct with flexible array member using empty initializer list. - Fixes (`#77085 <https://github.com/llvm/llvm-project/issues/77085>`) + Fixes (`#77085 <https://github.com/llvm/llvm-project/issues/77085>`_) Bug Fixes to Compiler Builtins _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits