https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/155173
That doesn't work. Fixes #152903 >From dd0d243e9799f8fbdfcabafbfb5f11ebff124a1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Sun, 24 Aug 2025 16:47:01 +0200 Subject: [PATCH] [clang][bytecode] Don't call getIndex() on one-past-end pointers That doesn't work. Fixes #152903 --- clang/lib/AST/ByteCode/Interp.cpp | 4 ++-- clang/test/AST/ByteCode/cxx11.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) 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]; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits