Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2431,9 +2431,12 @@ inline bool This(InterpState &S, CodePtr OpPC) {
// Ensure the This pointer has been cast to the correct base.
if (!This.isDummy()) {
assert(isa<CXXMethodDecl>(S.Current->getFunction()->getDecl()));
assert(This.getRecord());
[[maybe_unused]] const Record *R = This.getRecord();
if (!R)
R = This.narrow().getRecord();
assert(R);
assert(
This.getRecord()->getDecl() ==
R->getDecl() ==
cast<CXXMethodDecl>(S.Current->getFunction()->getDecl())->getParent());
}

Expand Down
24 changes: 24 additions & 0 deletions clang/test/AST/ByteCode/placement-new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,30 @@ namespace PR48606 {
static_assert(f());
}

/// This used to crash because of an assertion in the implementation
/// of the This instruction.
namespace ExplicitThisOnArrayElement {
struct S {
int a = 12;
constexpr S(int a) {
this->a = a;
}
};

template <class _Tp, class... _Args>
constexpr void construct_at(_Tp *__location, _Args &&...__args) {
new (__location) _Tp(__args...);
}

constexpr bool foo() {
auto *M = std::allocator<S>().allocate(13); // both-note {{allocation performed here was not deallocated}}
construct_at(M, 12);
return true;
}

static_assert(foo()); // both-error {{not an integral constant expression}}
}

#ifdef BYTECODE
constexpr int N = [] // expected-error {{must be initialized by a constant expression}} \
// expected-note {{assignment to dereferenced one-past-the-end pointer is not allowed in a constant expression}} \
Expand Down
Loading