Skip to content

Commit 3841e7d

Browse files
authored
[clang][bytecode] Don't call getThis() on the bottom function frame (#169044)
We can't access the calling frame in that case. Fixes #169032
1 parent 8918921 commit 3841e7d

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,8 @@ bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T) {
14071407
// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1677
14081408
// Therefore, we use the C++1y behavior.
14091409

1410-
if (S.Current->getFunction() && S.Current->getFunction()->isConstructor() &&
1410+
if (!S.Current->isBottomFrame() &&
1411+
S.Current->getFunction()->isConstructor() &&
14111412
S.Current->getThis().getDeclDesc()->asDecl() == S.EvaluatingDecl) {
14121413
return true;
14131414
}

clang/lib/AST/ByteCode/InterpFrame.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,15 @@ class InterpFrame final : public Frame {
109109
/// Returns the 'this' pointer.
110110
const Pointer &getThis() const {
111111
assert(hasThisPointer());
112+
assert(!isBottomFrame());
112113
return stackRef<Pointer>(ThisPointerOffset);
113114
}
114115

115116
/// Returns the RVO pointer, if the Function has one.
116117
const Pointer &getRVOPtr() const {
117118
assert(Func);
118119
assert(Func->hasRVO());
120+
assert(!isBottomFrame());
119121
return stackRef<Pointer>(0);
120122
}
121123

clang/test/AST/ByteCode/new-delete.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,18 @@ namespace ZeroSizeArray {
11141114
static_assert(foo() == 0);
11151115
}
11161116

1117+
namespace NonLiteralType {
1118+
/// This used to crash.
1119+
constexpr void foo() {
1120+
struct O {};
1121+
1122+
struct S {
1123+
O *s;
1124+
constexpr S() : s{std::allocator<O>{}.allocate(1)} {}
1125+
};
1126+
}
1127+
}
1128+
11171129
#else
11181130
/// Make sure we reject this prior to C++20
11191131
constexpr int a() { // both-error {{never produces a constant expression}}

0 commit comments

Comments
 (0)