Skip to content

Commit 97b3cb2

Browse files
authored
[clang][bytecode] Don't call getIndex() on one-past-end pointers (#155173)
That doesn't work. Fixes #152903
1 parent c825c8a commit 97b3cb2

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,8 +2117,8 @@ bool DiagTypeid(InterpState &S, CodePtr OpPC) {
21172117

21182118
bool arePotentiallyOverlappingStringLiterals(const Pointer &LHS,
21192119
const Pointer &RHS) {
2120-
unsigned LHSOffset = LHS.getIndex();
2121-
unsigned RHSOffset = RHS.getIndex();
2120+
unsigned LHSOffset = LHS.isOnePastEnd() ? LHS.getNumElems() : LHS.getIndex();
2121+
unsigned RHSOffset = RHS.isOnePastEnd() ? RHS.getNumElems() : RHS.getIndex();
21222122
unsigned LHSLength = (LHS.getNumElems() - 1) * LHS.elemSize();
21232123
unsigned RHSLength = (RHS.getNumElems() - 1) * RHS.elemSize();
21242124

clang/test/AST/ByteCode/cxx11.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ namespace OverlappingStrings {
287287
constexpr bool may_overlap_4 = &"xfoo"[1] == &"xfoo"[1]; // both-error {{}} both-note {{addresses of potentially overlapping literals}}
288288

289289

290+
/// Used to crash.
291+
const bool x = &"ab"[0] == &"ba"[3];
290292

291293
}
292294

0 commit comments

Comments
 (0)