[clang] 97b3cb2 - [clang][bytecode] Don't call getIndex() on one-past-end pointers (#155173)

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 25 21:33:27 PDT 2025


Author: Timm Baeder
Date: 2025-08-26T06:33:24+02:00
New Revision: 97b3cb223907f636730c1ab8c3c716b27a02084a

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

LOG: [clang][bytecode] Don't call getIndex() on one-past-end pointers (#155173)

That doesn't work.

Fixes #152903

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Interp.cpp
    clang/test/AST/ByteCode/cxx11.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 796c24e9071ec..d4525c8288c68 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -2117,8 +2117,8 @@ bool DiagTypeid(InterpState &S, CodePtr OpPC) {
 
 bool arePotentiallyOverlappingStringLiterals(const Pointer &LHS,
                                              const Pointer &RHS) {
-  unsigned LHSOffset = LHS.getIndex();
-  unsigned RHSOffset = RHS.getIndex();
+  unsigned LHSOffset = LHS.isOnePastEnd() ? LHS.getNumElems() : LHS.getIndex();
+  unsigned RHSOffset = RHS.isOnePastEnd() ? RHS.getNumElems() : RHS.getIndex();
   unsigned LHSLength = (LHS.getNumElems() - 1) * LHS.elemSize();
   unsigned RHSLength = (RHS.getNumElems() - 1) * RHS.elemSize();
 

diff  --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp
index 08caca03b8056..72bc7622eb6d8 100644
--- a/clang/test/AST/ByteCode/cxx11.cpp
+++ b/clang/test/AST/ByteCode/cxx11.cpp
@@ -287,6 +287,8 @@ namespace OverlappingStrings {
   constexpr bool may_overlap_4 = &"xfoo"[1] == &"xfoo"[1]; // both-error {{}} both-note {{addresses of potentially overlapping literals}}
 
 
+  /// Used to crash.
+  const bool x = &"ab"[0] == &"ba"[3];
 
 }
 


        


More information about the cfe-commits mailing list