llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/202314.diff


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Interp.h (+4) 
- (modified) clang/test/AST/ByteCode/cxx20.cpp (+9) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index d2ca122d0e805..1ead255121302 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2191,6 +2191,8 @@ bool Store(InterpState &S, CodePtr OpPC) {
   const Pointer &Ptr = S.Stk.peek<Pointer>();
   if (!CheckStore(S, OpPC, Ptr))
     return false;
+  if (!Ptr.canDeref(Name))
+    return false;
   if (Ptr.canBeInitialized())
     Ptr.initialize();
   Ptr.deref<T>() = Value;
@@ -2203,6 +2205,8 @@ bool StorePop(InterpState &S, CodePtr OpPC) {
   const Pointer &Ptr = S.Stk.pop<Pointer>();
   if (!CheckStore(S, OpPC, Ptr))
     return false;
+  if (!Ptr.canDeref(Name))
+    return false;
   if (Ptr.canBeInitialized())
     Ptr.initialize();
   Ptr.deref<T>() = Value;
diff --git a/clang/test/AST/ByteCode/cxx20.cpp 
b/clang/test/AST/ByteCode/cxx20.cpp
index b55d274f2408c..5693f45835ab8 100644
--- a/clang/test/AST/ByteCode/cxx20.cpp
+++ b/clang/test/AST/ByteCode/cxx20.cpp
@@ -1404,3 +1404,12 @@ namespace InvalidOMPRequiredSimdAlign {
   typedef decltype(sizeof(int)) T;
   constexpr T foo(T x) { return __builtin_omp_required_simd_align * 42; } // 
both-error {{indirection requires pointer operand}}
 }
+
+namespace StoreCannotDeref {
+  constexpr void foo() { // both-error {{never produces a constant expression}}
+    int l = 10;
+    int *n = &l;
+    int *m = (int *)&n; // both-note {{cast that performs the conversions of a 
reinterpret_cast}}
+    *m = 42;
+  }
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/202314
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to