Author: Timm Baeder
Date: 2026-02-04T12:39:21+01:00
New Revision: a8af0901dd1a8133f0978e11b84e91558aa99873

URL: 
https://github.com/llvm/llvm-project/commit/a8af0901dd1a8133f0978e11b84e91558aa99873
DIFF: 
https://github.com/llvm/llvm-project/commit/a8af0901dd1a8133f0978e11b84e91558aa99873.diff

LOG: [clang][bytecode] Don't call getOffset on non-block pointers (#179628)

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

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Interp.h
    clang/test/AST/ByteCode/c.c

Removed: 
    


################################################################################
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