Fznamznon created this revision. Herald added a project: All. Fznamznon requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Due to missing check on union, there was a null expression added to init list that caused crash later. Fixes https://github.com/llvm/llvm-project/issues/61746 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D150435 Files: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaInit.cpp clang/test/Sema/init.c Index: clang/test/Sema/init.c =================================================================== --- clang/test/Sema/init.c +++ clang/test/Sema/init.c @@ -164,3 +164,6 @@ typedef struct { uintptr_t x : 2; } StructWithBitfield; StructWithBitfield bitfieldvar = { (uintptr_t)&bitfieldvar }; // expected-error {{initializer element is not a compile-time constant}} + +// GH61746 +union { char x[]; } r = {0}; // expected-error {{flexible array member 'x' in a union is not allowed}} Index: clang/lib/Sema/SemaInit.cpp =================================================================== --- clang/lib/Sema/SemaInit.cpp +++ clang/lib/Sema/SemaInit.cpp @@ -811,7 +811,7 @@ // order to leave them uninitialized, the ILE is expanded and the extra // fields are then filled with NoInitExpr. unsigned NumElems = numStructUnionElements(ILE->getType()); - if (RDecl->hasFlexibleArrayMember()) + if (!RDecl->isUnion() && RDecl->hasFlexibleArrayMember()) ++NumElems; if (!VerifyOnly && ILE->getNumInits() < NumElems) ILE->resizeInits(SemaRef.Context, NumElems); Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -395,6 +395,8 @@ when it had been instantiated from a partial template specialization with different template arguments on the containing class. This fixes: (`#60778 <https://github.com/llvm/llvm-project/issues/60778>`_). +- Fix crash on attempt to initialize union with flexible array member. + (`#61746 <https://github.com/llvm/llvm-project/issues/61746>`_). Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Index: clang/test/Sema/init.c =================================================================== --- clang/test/Sema/init.c +++ clang/test/Sema/init.c @@ -164,3 +164,6 @@ typedef struct { uintptr_t x : 2; } StructWithBitfield; StructWithBitfield bitfieldvar = { (uintptr_t)&bitfieldvar }; // expected-error {{initializer element is not a compile-time constant}} + +// GH61746 +union { char x[]; } r = {0}; // expected-error {{flexible array member 'x' in a union is not allowed}} Index: clang/lib/Sema/SemaInit.cpp =================================================================== --- clang/lib/Sema/SemaInit.cpp +++ clang/lib/Sema/SemaInit.cpp @@ -811,7 +811,7 @@ // order to leave them uninitialized, the ILE is expanded and the extra // fields are then filled with NoInitExpr. unsigned NumElems = numStructUnionElements(ILE->getType()); - if (RDecl->hasFlexibleArrayMember()) + if (!RDecl->isUnion() && RDecl->hasFlexibleArrayMember()) ++NumElems; if (!VerifyOnly && ILE->getNumInits() < NumElems) ILE->resizeInits(SemaRef.Context, NumElems); Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -395,6 +395,8 @@ when it had been instantiated from a partial template specialization with different template arguments on the containing class. This fixes: (`#60778 <https://github.com/llvm/llvm-project/issues/60778>`_). +- Fix crash on attempt to initialize union with flexible array member. + (`#61746 <https://github.com/llvm/llvm-project/issues/61746>`_). Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits