From f5af7d2d987b0b16d7a641b7aa9086a75d533944 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Tue, 23 May 2023 07:59:38 +0000 Subject: [PATCH] Revert "[clang][ExprConstant] fix __builtin_object_size for flexible array members" This reverts commit 57c5c1ab2a188b7962c9de5ac0f95e3c7441940a. Causes an assertion failure: https://reviews.llvm.org/D150892#4363080 --- clang/docs/ReleaseNotes.rst | 9 --------- clang/lib/AST/ExprConstant.cpp | 9 +-------- clang/test/CodeGen/object-size.c | 27 --------------------------- 3 files changed, 1 insertion(+), 44 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index a124617..915c9b0 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -51,11 +51,6 @@ C/C++ Language Potentially Breaking Changes foo: asm goto ("# %0 %1"::"i"(&&foo)::foo); -- ``__builtin_object_size`` and ``__builtin_dynamic_object_size`` now add the - ``sizeof`` the elements specified in designated initializers of flexible - array members for structs that contain them. This change is more consistent - with the behavior of GCC. - C++ Specific Potentially Breaking Changes ----------------------------------------- - Clang won't search for coroutine_traits in std::experimental namespace any more. @@ -429,10 +424,6 @@ Bug Fixes in This Version (`#61746 `_). - Clang `TextNodeDumper` enabled through `-ast-dump` flag no longer evaluates the initializer of constexpr `VarDecl` if the declaration has a dependent type. -- Match GCC's behavior for ``__builtin_object_size`` and - ``__builtin_dynamic_object_size`` on structs containing flexible array - members. - (`#62789 `_). Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index f1a30da..ce3c525 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -11733,14 +11733,7 @@ static bool determineEndOffset(EvalInfo &Info, SourceLocation ExprLoc, auto CheckedHandleSizeof = [&](QualType Ty, CharUnits &Result) { if (Ty.isNull() || Ty->isIncompleteType() || Ty->isFunctionType()) return false; - bool Ret = HandleSizeof(Info, ExprLoc, Ty, Result); - if (Ty->isStructureType() && - Ty->getAsStructureType()->getDecl()->hasFlexibleArrayMember()) { - const auto *VD = - cast(LVal.getLValueBase().get()); - Result += VD->getFlexibleArrayInitChars(Info.Ctx); - } - return Ret; + return HandleSizeof(Info, ExprLoc, Ty, Result); }; // We want to evaluate the size of the entire object. This is a valid fallback diff --git a/clang/test/CodeGen/object-size.c b/clang/test/CodeGen/object-size.c index ac15513..157926d 100644 --- a/clang/test/CodeGen/object-size.c +++ b/clang/test/CodeGen/object-size.c @@ -525,33 +525,6 @@ void test31(void) { gi = OBJECT_SIZE_BUILTIN(&dsv[9].snd[0], 1); } -// CHECK-LABEL: @test32 -static struct DynStructVar D32 = { - .fst = {}, - .snd = { 0, 1, 2, }, -}; -unsigned long test32(void) { - // CHECK: ret i64 19 - return OBJECT_SIZE_BUILTIN(&D32, 1); -} -// CHECK-LABEL: @test33 -static struct DynStructVar D33 = { - .fst = {}, - .snd = {}, -}; -unsigned long test33(void) { - // CHECK: ret i64 16 - return OBJECT_SIZE_BUILTIN(&D33, 1); -} -// CHECK-LABEL: @test34 -static struct DynStructVar D34 = { - .fst = {}, -}; -unsigned long test34(void) { - // CHECK: ret i64 16 - return OBJECT_SIZE_BUILTIN(&D34, 1); -} - // CHECK-LABEL: @PR30346 void PR30346(void) { struct sa_family_t {}; -- 2.7.4