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

This should compare equal to not adding the offset of the first member.

See https://github.com/llvm/llvm-project/issues/172165

>From 8ebf12602691f1329db5f8a9bc24784405ad09c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Sat, 13 Dec 2025 19:28:06 +0100
Subject: [PATCH] [clang][bytecode] Fix pointer comparison to first record
 member

This should compare equal to not adding the offset of the first member.

See https://github.com/llvm/llvm-project/issues/172165
---
 clang/lib/AST/ByteCode/Pointer.cpp |  3 ++-
 clang/test/AST/ByteCode/cxx20.cpp  | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/Pointer.cpp 
b/clang/lib/AST/ByteCode/Pointer.cpp
index 00e74db5655d6..1b50de26b7199 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -413,7 +413,8 @@ size_t Pointer::computeOffsetForComparison() const {
     }
 
     // Fields, etc.
-    Result += P.getInlineDesc()->Offset;
+    if (unsigned FO = P.getInlineDesc()->Offset; FO != 
sizeof(InlineDescriptor))
+      Result += FO;
     if (P.isOnePastEnd())
       ++Result;
 
diff --git a/clang/test/AST/ByteCode/cxx20.cpp 
b/clang/test/AST/ByteCode/cxx20.cpp
index 227f34cee80ff..31ea02c2e0e19 100644
--- a/clang/test/AST/ByteCode/cxx20.cpp
+++ b/clang/test/AST/ByteCode/cxx20.cpp
@@ -1225,3 +1225,25 @@ namespace ConditionalTemporaries {
   static_assert(foo(false)== 13);
   static_assert(foo(true)== 12);
 }
+
+namespace FirstRecordMemberCmp {
+
+  struct tuple {
+    int a;
+    int b;
+  };
+
+  constexpr tuple tpl{1,2};
+  static_assert((void*)&tpl == (void*)&tpl.a);
+
+
+  struct B {
+    int a;
+  };
+
+  struct tuple2 : public B {
+    int b;
+  };
+  constexpr tuple2 tpl2{1,2};
+  static_assert((void*)&tpl2 == (void*)&tpl2.a);
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to