[clang] [clang][bytecode] Check for memcpy/memmove dummy pointers earlier (PR #121453)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 1 21:37:19 PST 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/121453
None
>From 9aeae2efcfb038af30f01a07eb8960a4a59929f9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Thu, 2 Jan 2025 06:28:08 +0100
Subject: [PATCH] [clang][bytecode] Check for memcpy/memmove dummy pointers
earlier
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 7 ++++---
clang/test/CodeGen/builtin-memfns.c | 1 +
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index d0d8b03deab268..e9f3303f958d3e 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1863,6 +1863,10 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
return false;
}
+ // Can't read from dummy pointers.
+ if (DestPtr.isDummy() || SrcPtr.isDummy())
+ return false;
+
QualType DestElemType;
size_t RemainingDestElems;
if (DestPtr.getFieldDesc()->isArray()) {
@@ -1925,9 +1929,6 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
}
}
- // As a last resort, reject dummy pointers.
- if (DestPtr.isDummy() || SrcPtr.isDummy())
- return false;
assert(Size.getZExtValue() % DestElemSize == 0);
if (!DoMemcpy(S, OpPC, SrcPtr, DestPtr, Bytes(Size.getZExtValue()).toBits()))
return false;
diff --git a/clang/test/CodeGen/builtin-memfns.c b/clang/test/CodeGen/builtin-memfns.c
index 23c3c60b779b37..581eb85eb28e69 100644
--- a/clang/test/CodeGen/builtin-memfns.c
+++ b/clang/test/CodeGen/builtin-memfns.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm < %s| FileCheck %s
+// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -fexperimental-new-constant-interpreter < %s| FileCheck %s
typedef __WCHAR_TYPE__ wchar_t;
typedef __SIZE_TYPE__ size_t;
More information about the cfe-commits
mailing list