Skip to content

Commit 35f7cfb

Browse files
authored
[clang][bytecode] Check for Pointer dereference in EvaluationResult (#108207)
We will deref<>() it later, so this is the right check.
1 parent ccc4fa1 commit 35f7cfb

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

clang/lib/AST/ByteCode/EvaluationResult.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ bool EvaluationResult::checkFullyInitialized(InterpState &S,
178178
static void collectBlocks(const Pointer &Ptr,
179179
llvm::SetVector<const Block *> &Blocks) {
180180
auto isUsefulPtr = [](const Pointer &P) -> bool {
181-
return P.isLive() && !P.isZero() && !P.isDummy() &&
182-
!P.isUnknownSizeArray() && !P.isOnePastEnd() && P.isBlockPointer();
181+
return P.isLive() && !P.isZero() && !P.isDummy() && P.isDereferencable() &&
182+
!P.isUnknownSizeArray() && !P.isOnePastEnd();
183183
};
184184

185185
if (!isUsefulPtr(Ptr))

clang/test/AST/ByteCode/initializer_list.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fms-extensions -std=c++20 -verify=expected,both %s
22
// RUN: %clang_cc1 -std=c++20 -fms-extensions -verify=ref,both %s
33

4-
// both-no-diagnostics
5-
64
namespace std {
75
typedef decltype(sizeof(int)) size_t;
86
template <class _E>
@@ -53,3 +51,21 @@ constexpr int foo() {
5351
}
5452

5553
static_assert(foo() == 0);
54+
55+
56+
namespace rdar13395022 {
57+
struct MoveOnly { // both-note {{candidate}}
58+
MoveOnly(MoveOnly&&); // both-note 2{{copy constructor is implicitly deleted because}} both-note {{candidate}}
59+
};
60+
61+
void test(MoveOnly mo) {
62+
auto &&list1 = {mo}; // both-error {{call to implicitly-deleted copy constructor}} both-note {{in initialization of temporary of type 'std::initializer_list}}
63+
MoveOnly (&&list2)[1] = {mo}; // both-error {{call to implicitly-deleted copy constructor}} both-note {{in initialization of temporary of type 'MoveOnly[1]'}}
64+
std::initializer_list<MoveOnly> &&list3 = {};
65+
MoveOnly (&&list4)[1] = {}; // both-error {{no matching constructor}}
66+
// both-note@-1 {{in implicit initialization of array element 0 with omitted initializer}}
67+
// both-note@-2 {{in initialization of temporary of type 'MoveOnly[1]' created to list-initialize this reference}}
68+
}
69+
}
70+
71+

0 commit comments

Comments
 (0)