Author: Timm Baeder Date: 2026-11-12T06:49:34+01:00 New Revision: a60677dca3a8536a0cf5bec1b846610014a983fd
URL: https://github.com/llvm/llvm-project/commit/a60677dca3a8536a0cf5bec1b846610014a983fd DIFF: https://github.com/llvm/llvm-project/commit/a60677dca3a8536a0cf5bec1b846610014a983fd.diff LOG: [clang][bytecode] Remove unreachable code in __builtin_object_size (#240742) In the current interpreter, removing the equivalent if statement breaks this test: ```c gi = __builtin_object_size(&t[1].v[14], 3); ``` but in the bytecode interpeter, removing this if does not break anything as it's unreachable, see https://github.com/llvm/llvm-project/pull/213017/changes#r4475679359 Added: Modified: clang/lib/AST/ByteCode/InterpBuiltinObjectSize.cpp clang/test/AST/ByteCode/builtin-object-size-codegen.c Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/InterpBuiltinObjectSize.cpp b/clang/lib/AST/ByteCode/InterpBuiltinObjectSize.cpp index 41b347150886f..18dfc8e8e1b92 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltinObjectSize.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltinObjectSize.cpp @@ -432,10 +432,6 @@ UnsignedOrNone evaluateBuiltinObjectSize(const ASTContext &ASTCtx, } if (!UseClosestSurroundingVariable || DetermineForCompleteObject) { - // Kind=3 wants a lower bound, so we can't fall back to this. - if (Kind == 3 && !DetermineForCompleteObject) - return std::nullopt; - if (InvalidBase) return std::nullopt; diff --git a/clang/test/AST/ByteCode/builtin-object-size-codegen.c b/clang/test/AST/ByteCode/builtin-object-size-codegen.c index e9b0e85b4fce7..c25f204109d12 100644 --- a/clang/test/AST/ByteCode/builtin-object-size-codegen.c +++ b/clang/test/AST/ByteCode/builtin-object-size-codegen.c @@ -148,3 +148,17 @@ void f18(void) { // CHECK: store i32 3 gi = __builtin_object_size((char*)&_P + 5, 0); } + +void test26(void) { + struct { int v[10]; } t[10]; + + // CHECK: store i32 316 + gi = __builtin_object_size(&t[1].v[11], 0); + // FIXME: Not sure why this should return 312. GCC also returns 0. + // store i32 312 + // gi = __builtin_object_size(&t[1].v[12], 1); + // CHECK: store i32 308 + gi = __builtin_object_size(&t[1].v[13], 2); + // CHECK: store i32 0 + gi = __builtin_object_size(&t[1].v[14], 3); +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
