Skip to content

Conversation

@tbaederr
Copy link
Contributor

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

See #172165

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

See llvm#172165
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Dec 13, 2025
@tbaederr
Copy link
Contributor Author

I haven't run the full test suite with this yet.

@llvmbot
Copy link
Member

llvmbot commented Dec 13, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

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

See #172165


Full diff: https://github.com/llvm/llvm-project/pull/172168.diff

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Pointer.cpp (+2-1)
  • (modified) clang/test/AST/ByteCode/cxx20.cpp (+22)
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);
+}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants