[clang] 45e874e - [clang][bytecode] Check for memcpy/memmove dummy pointers earlier (#121453)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 2 00:15:18 PST 2025
Author: Timm Baeder
Date: 2025-01-02T09:15:14+01:00
New Revision: 45e874e39030bc622ea43fbcfc4fcdd1dd404353
URL: https://github.com/llvm/llvm-project/commit/45e874e39030bc622ea43fbcfc4fcdd1dd404353
DIFF: https://github.com/llvm/llvm-project/commit/45e874e39030bc622ea43fbcfc4fcdd1dd404353.diff
LOG: [clang][bytecode] Check for memcpy/memmove dummy pointers earlier (#121453)
Added:
Modified:
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/test/CodeGen/builtin-memfns.c
Removed:
################################################################################
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