[clang] [clang][bytecode] Check memcmp for block pointers (PR #165070)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 24 21:13:17 PDT 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/165070
We can't read from non-block pointers anyway.
Fixes https://github.com/llvm/llvm-project/issues/165061
>From af82b4cfc197481303ba6686044ae873908fd8ac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Sat, 25 Oct 2025 06:12:21 +0200
Subject: [PATCH] [clang][bytecode] Check memcmp for block pointers
We can't read from non-block pointers anyway.
Fixes https://github.com/llvm/llvm-project/issues/165061
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 3 +++
clang/test/AST/ByteCode/builtin-functions.cpp | 2 ++
2 files changed, 5 insertions(+)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index ff50e6dbfb44e..8dfeabe536654 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1941,6 +1941,9 @@ static bool interp__builtin_memcmp(InterpState &S, CodePtr OpPC,
return true;
}
+ if (!PtrA.isBlockPointer() || !PtrB.isBlockPointer())
+ return false;
+
bool IsWide =
(ID == Builtin::BIwmemcmp || ID == Builtin::BI__builtin_wmemcmp);
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index 0b7d51be8d824..d8572ba722d69 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1510,6 +1510,8 @@ namespace Memcmp {
static_assert(f());
#endif
+ int unknown;
+ void foo(void) { unknown *= __builtin_memcmp(0, 0, 2); }
}
namespace Memchr {
More information about the cfe-commits
mailing list