[clang] [clang][bytecode] Don't call getIndex() on one-past-end pointers (PR #155173)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 25 21:06:50 PDT 2025
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/155173
>From 448ee9a9b416b3c78d6134bc649f6a4b2e4b2391 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at 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];
}
More information about the cfe-commits
mailing list