aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/InterpBuiltin.cpp
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2025-04-29 08:06:31 +0200
committerGitHub <noreply@github.com>2025-04-29 08:06:31 +0200
commit0ddb5794b7b47481ed713af0add392de324d5cd2 (patch)
tree6858aadf74365672a7c936db8f295d1fe2e96090 /clang/lib/AST/ByteCode/InterpBuiltin.cpp
parentfa1fe11e38db742c4114a8b6aac9caa351f2409c (diff)
downloadllvm-0ddb5794b7b47481ed713af0add392de324d5cd2.zip
llvm-0ddb5794b7b47481ed713af0add392de324d5cd2.tar.gz
llvm-0ddb5794b7b47481ed713af0add392de324d5cd2.tar.bz2
[clang][bytecode] Remove base casts before doing memcpy (#137754)
We have to copy the entire thing, not just one of the bases.
Diffstat (limited to 'clang/lib/AST/ByteCode/InterpBuiltin.cpp')
-rw-r--r--clang/lib/AST/ByteCode/InterpBuiltin.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 0b4585a..b6e5b5f 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1854,8 +1854,17 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
// Check for overlapping memory regions.
if (!Move && Pointer::pointToSameBlock(SrcPtr, DestPtr)) {
- unsigned SrcIndex = SrcPtr.getIndex() * SrcPtr.elemSize();
- unsigned DstIndex = DestPtr.getIndex() * DestPtr.elemSize();
+ // Remove base casts.
+ Pointer SrcP = SrcPtr;
+ while (SrcP.isBaseClass())
+ SrcP = SrcP.getBase();
+
+ Pointer DestP = DestPtr;
+ while (DestP.isBaseClass())
+ DestP = DestP.getBase();
+
+ unsigned SrcIndex = SrcP.expand().getIndex() * SrcP.elemSize();
+ unsigned DstIndex = DestP.expand().getIndex() * DestP.elemSize();
unsigned N = Size.getZExtValue();
if ((SrcIndex <= DstIndex && (SrcIndex + N) > DstIndex) ||