Author: Mariya Podchishchaeva Date: 2024-08-08T08:51:56+02:00 New Revision: 3606d69d0b57dc1d23a4362e376e7ad27f650c27
URL: https://github.com/llvm/llvm-project/commit/3606d69d0b57dc1d23a4362e376e7ad27f650c27 DIFF: https://github.com/llvm/llvm-project/commit/3606d69d0b57dc1d23a4362e376e7ad27f650c27.diff LOG: [clang] Fix crash when #embed used in a compound literal (#102304) Fixes https://github.com/llvm/llvm-project/issues/102248 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 90fd6df782f095..abd4401e029817 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) +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits