[clang] [clang][bytecode] Check for Pointer dereference in EvaluationResult (PR #108207)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 11 05:19:03 PDT 2024


https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/108207

We will deref<>() it later, so this is the right check.

>From 7f27917b46e254bacc7214ef40d6a61f0db0e92f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Wed, 11 Sep 2024 14:16:58 +0200
Subject: [PATCH] [clang][bytecode] Check for Pointer dereference in
 EvaluationResult

We will deref<>() it later, so this is the right check.
---
 clang/lib/AST/ByteCode/EvaluationResult.cpp  |  4 ++--
 clang/test/AST/ByteCode/initializer_list.cpp | 20 ++++++++++++++++++--
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/ByteCode/EvaluationResult.cpp b/clang/lib/AST/ByteCode/EvaluationResult.cpp
index bdebd19af9f940..627d4b2f65be9d 100644
--- a/clang/lib/AST/ByteCode/EvaluationResult.cpp
+++ b/clang/lib/AST/ByteCode/EvaluationResult.cpp
@@ -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))
diff --git a/clang/test/AST/ByteCode/initializer_list.cpp b/clang/test/AST/ByteCode/initializer_list.cpp
index 4e3b8dc9120167..f882e4ff1b1247 100644
--- a/clang/test/AST/ByteCode/initializer_list.cpp
+++ b/clang/test/AST/ByteCode/initializer_list.cpp
@@ -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>
@@ -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 at -1 {{in implicit initialization of array element 0 with omitted initializer}}
+    // both-note at -2 {{in initialization of temporary of type 'MoveOnly[1]' created to list-initialize this reference}}
+  }
+}
+
+



More information about the cfe-commits mailing list