https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/240742

In the current interpreter, removing the equivalent if statement breaks this 
test:
+  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

>From b0882d623e3a2f23e2ac7116d029d81c4ea9a0a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Tue, 10 Nov 2026 08:42:33 +0100
Subject: [PATCH] [clang][bytecode] Remove unreachable code in
 __builtin_object_size

In the current interpreter, removing the equivalent if statement breaks
this test:
+  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
---
 clang/lib/AST/ByteCode/InterpBuiltinObjectSize.cpp |  4 ----
 .../AST/ByteCode/builtin-object-size-codegen.c     | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltinObjectSize.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltinObjectSize.cpp
index 41b347150886f8..18dfc8e8e1b92d 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 d1880e803c0972..932793c5988199 100644
--- a/clang/test/AST/ByteCode/builtin-object-size-codegen.c
+++ b/clang/test/AST/ByteCode/builtin-object-size-codegen.c
@@ -146,3 +146,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

Reply via email to