From 1c236d34da60462c079ec297c840e95521df23c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Mon, 8 Jun 2026 12:17:57 +0200 Subject: [PATCH] [clang][bytecode] Check Ptr primtype in Store op --- clang/lib/AST/ByteCode/Interp.h | 4 ++++ clang/test/AST/ByteCode/cxx20.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) 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(); if (!CheckStore(S, OpPC, Ptr)) return false; + if (!Ptr.canDeref(Name)) + return false; if (Ptr.canBeInitialized()) Ptr.initialize(); Ptr.deref() = Value; @@ -2203,6 +2205,8 @@ bool StorePop(InterpState &S, CodePtr OpPC) { const Pointer &Ptr = S.Stk.pop(); if (!CheckStore(S, OpPC, Ptr)) return false; + if (!Ptr.canDeref(Name)) + return false; if (Ptr.canBeInitialized()) Ptr.initialize(); Ptr.deref() = 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; + } +}