Skip to content

Commit

Permalink
[clang][bytecode] Check for Pointer dereference in EvaluationResult (l…
Browse files Browse the repository at this point in the history
…lvm#108207)

We will deref<>() it later, so this is the right check.
  • Loading branch information
tbaederr authored Sep 11, 2024
1 parent ccc4fa1 commit 35f7cfb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions clang/lib/AST/ByteCode/EvaluationResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ bool EvaluationResult::checkFullyInitialized(InterpState &S,
static void collectBlocks(const Pointer &Ptr,
llvm::SetVector<const Block *> &Blocks) {
auto isUsefulPtr = [](const Pointer &P) -> bool {
return P.isLive() && !P.isZero() && !P.isDummy() &&
!P.isUnknownSizeArray() && !P.isOnePastEnd() && P.isBlockPointer();
return P.isLive() && !P.isZero() && !P.isDummy() && P.isDereferencable() &&
!P.isUnknownSizeArray() && !P.isOnePastEnd();
};

if (!isUsefulPtr(Ptr))
Expand Down
20 changes: 18 additions & 2 deletions clang/test/AST/ByteCode/initializer_list.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fms-extensions -std=c++20 -verify=expected,both %s
// RUN: %clang_cc1 -std=c++20 -fms-extensions -verify=ref,both %s

// both-no-diagnostics

namespace std {
typedef decltype(sizeof(int)) size_t;
template <class _E>
Expand Down Expand Up @@ -53,3 +51,21 @@ constexpr int foo() {
}

static_assert(foo() == 0);


namespace rdar13395022 {
struct MoveOnly { // both-note {{candidate}}
MoveOnly(MoveOnly&&); // both-note 2{{copy constructor is implicitly deleted because}} both-note {{candidate}}
};

void test(MoveOnly mo) {
auto &&list1 = {mo}; // both-error {{call to implicitly-deleted copy constructor}} both-note {{in initialization of temporary of type 'std::initializer_list}}
MoveOnly (&&list2)[1] = {mo}; // both-error {{call to implicitly-deleted copy constructor}} both-note {{in initialization of temporary of type 'MoveOnly[1]'}}
std::initializer_list<MoveOnly> &&list3 = {};
MoveOnly (&&list4)[1] = {}; // both-error {{no matching constructor}}
// both-note@-1 {{in implicit initialization of array element 0 with omitted initializer}}
// both-note@-2 {{in initialization of temporary of type 'MoveOnly[1]' created to list-initialize this reference}}
}
}


0 comments on commit 35f7cfb

Please sign in to comment.