aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/InterpBuiltin.cpp
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2025-04-17 06:19:37 +0200
committerGitHub <noreply@github.com>2025-04-17 06:19:37 +0200
commitadba24aa3c52c7e2673104fc16bd19e639221077 (patch)
tree304dffe137138ea623770bb4241cdf6b5e07d908 /clang/lib/AST/ByteCode/InterpBuiltin.cpp
parentd647d66da697952f600d7a0d84fba94612fe51db (diff)
downloadllvm-adba24aa3c52c7e2673104fc16bd19e639221077.zip
llvm-adba24aa3c52c7e2673104fc16bd19e639221077.tar.gz
llvm-adba24aa3c52c7e2673104fc16bd19e639221077.tar.bz2
[clang][bytecode] Add missing __builtin_memcpy checks (#135975)
Add a test for type punning and tests and the necessary checks for non-trivially-copyable types and incomplete types.
Diffstat (limited to 'clang/lib/AST/ByteCode/InterpBuiltin.cpp')
-rw-r--r--clang/lib/AST/ByteCode/InterpBuiltin.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index b694a34..31d97d9 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1872,7 +1872,23 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
return false;
}
- // Check if we have enough elements to read from and write to/
+ if (DestElemType->isIncompleteType() ||
+ DestPtr.getType()->isIncompleteType()) {
+ QualType DiagType =
+ DestElemType->isIncompleteType() ? DestElemType : DestPtr.getType();
+ S.FFDiag(S.Current->getSource(OpPC),
+ diag::note_constexpr_memcpy_incomplete_type)
+ << Move << DiagType;
+ return false;
+ }
+
+ if (!DestElemType.isTriviallyCopyableType(ASTCtx)) {
+ S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_memcpy_nontrivial)
+ << Move << DestElemType;
+ return false;
+ }
+
+ // Check if we have enough elements to read from and write to.
size_t RemainingDestBytes = RemainingDestElems * DestElemSize;
size_t RemainingSrcBytes = RemainingSrcElems * SrcElemSize;
if (Size.ugt(RemainingDestBytes) || Size.ugt(RemainingSrcBytes)) {