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

Fixes https://github.com/llvm/llvm-project/issues/177587

>From 6d77b868e3d041e0090ca064fd3152739b233212 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Wed, 4 Feb 2026 10:11:18 +0100
Subject: [PATCH] [clang][bytecode] Don't call getOffset on non-block pointers

Fixes https://github.com/llvm/llvm-project/issues/177587
---
 clang/lib/AST/ByteCode/Interp.h | 4 ++--
 clang/test/AST/ByteCode/c.c     | 8 ++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 3313e819e694b..ca5b1fd6bf072 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1164,14 +1164,14 @@ inline bool CmpHelperEQ<Pointer>(InterpState &S, 
CodePtr OpPC, CompareFn Fn) {
 
   // Otherwise we need to do a bunch of extra checks before returning 
Unordered.
   if (LHS.isOnePastEnd() && !RHS.isOnePastEnd() && !RHS.isZero() &&
-      RHS.getOffset() == 0) {
+      RHS.isBlockPointer() && RHS.getOffset() == 0) {
     const SourceInfo &Loc = S.Current->getSource(OpPC);
     S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_past_end)
         << LHS.toDiagnosticString(S.getASTContext());
     return false;
   }
   if (RHS.isOnePastEnd() && !LHS.isOnePastEnd() && !LHS.isZero() &&
-      LHS.getOffset() == 0) {
+      LHS.isBlockPointer() && LHS.getOffset() == 0) {
     const SourceInfo &Loc = S.Current->getSource(OpPC);
     S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_past_end)
         << RHS.toDiagnosticString(S.getASTContext());
diff --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c
index 7b98aa84a482c..9496f8060884a 100644
--- a/clang/test/AST/ByteCode/c.c
+++ b/clang/test/AST/ByteCode/c.c
@@ -425,3 +425,11 @@ int complexMul[2 * (22222222222wb + 2i) == 2]; // 
all-warning {{'_BitInt' suffix
 int complexDiv[2 / (22222222222wb + 2i) == 2]; // all-warning {{'_BitInt' 
suffix for literals is a C23 extension}} \
                                                // pedantic-warning {{imaginary 
constants are a C2y extension}} \
                                                // all-warning {{variable 
length array folded to constant array as an extension}}
+
+
+
+int i = 0;
+void intPtrCmp1(void) { &i + 1 == 2; } // all-warning {{comparison between 
pointer and integer}} \
+                                       // all-warning {{equality comparison 
result unused}}
+void intPtrCmp2(void) { 2 == &i + 1; } // all-warning {{comparison between 
pointer and integer}} \
+                                       // all-warning {{equality comparison 
result unused}}

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

Reply via email to