[clang] [clang][bytecode] Fix pointer comparison to first record member (PR #172168)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Dec 13 10:30:53 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
This should compare equal to not adding the offset of the first member.
See https://github.com/llvm/llvm-project/issues/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
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);
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/172168
More information about the cfe-commits
mailing list