https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/237146
None >From b2ea9697dea73e7c923b1c1b3b0ee50392ba31a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Fri, 30 Oct 2026 09:59:12 +0100 Subject: [PATCH] [clang][bytecode] Reject non-readable pointer types from _load8 --- clang/lib/AST/ByteCode/InterpBuiltin.cpp | 3 +++ clang/test/AST/ByteCode/c2y.c | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index 8fefaa97c9f630..84edb0bce4a102 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -2237,6 +2237,9 @@ static bool interp__builtin_load8(InterpState &S, CodePtr OpPC, if (!isReadable(Ptr) && !Ptr.isOnePastEnd()) return false; + if (!Ptr.isReadablePointerType()) + return false; + if (IsAligned) { CharUnits RequiredAlign = S.getASTContext().getTypeAlignInChars(Call->getType()); diff --git a/clang/test/AST/ByteCode/c2y.c b/clang/test/AST/ByteCode/c2y.c index bbb163ab83833f..7f5f0bc972fa15 100644 --- a/clang/test/AST/ByteCode/c2y.c +++ b/clang/test/AST/ByteCode/c2y.c @@ -1,8 +1,6 @@ // RUN: %clang_cc1 -triple x86_64-linux %s -std=c2y -verify=expected,both -fexperimental-new-constant-interpreter // RUN: %clang_cc1 -triple x86_64-linux %s -std=c2y -verify=ref,both -// both-no-diagnostics - struct S { int x; char c; @@ -21,3 +19,10 @@ int quorble() { const struct S *s_ptr = (struct S *)((struct T *)buffer)->buffer; return s_ptr->x; } + + +__UINT_LEAST32_TYPE__ stdc_load8_aligned_leu32(const unsigned char *); +alignas(8) unsigned char buf[4] = {}; +__UINT_LEAST32_TYPE__ fail_load8 = stdc_load8_aligned_leu32(buf + 4); // both-error {{not a compile-time constant}} + + _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
