[clang] 5edde18 - [clang][bytecode] Reject non-blockpointer destinations in __builtin_wmemcpy (#232327)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 15 22:10:19 PDT 2026
Author: Timm Baeder
Date: 2026-10-16T07:10:11+02:00
New Revision: 5edde18bf08af1e31efbdc7769bb1a1e49d81798
URL: https://github.com/llvm/llvm-project/commit/5edde18bf08af1e31efbdc7769bb1a1e49d81798
DIFF: https://github.com/llvm/llvm-project/commit/5edde18bf08af1e31efbdc7769bb1a1e49d81798.diff
LOG: [clang][bytecode] Reject non-blockpointer destinations in __builtin_wmemcpy (#232327)
Added:
Modified:
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/test/AST/ByteCode/builtin-functions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 382a908272849..d73ad308b0c0f 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -200,6 +200,15 @@ static void diagnoseNonConstexprBuiltin(InterpState &S, CodePtr OpPC,
S.CCEDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
}
+static bool diagnoseUnreadableObject(InterpState &S, CodePtr OpPC,
+ const Pointer &Ptr, AccessKinds AK) {
+ S.FFDiag(S.Current->getSource(OpPC),
+ diag::note_constexpr_access_unreadable_object)
+ << AK << Ptr.toDiagnosticString(S.getASTContext());
+ noteValueLocation(S, Ptr);
+ return false;
+}
+
static llvm::APSInt convertBoolVectorToInt(const Pointer &Val) {
assert(Val.getFieldDesc()->isPrimitiveArray() &&
Val.getFieldDesc()->getElemQualType()->isBooleanType() &&
@@ -2029,7 +2038,10 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
return false;
}
- if (!isReadable(DestPtr) || !isReadable(SrcPtr))
+ if (!DestPtr.isBlockPointer())
+ return diagnoseUnreadableObject(S, OpPC, DestPtr, AK_Assign);
+
+ if (!isReadable(SrcPtr))
return false;
if (DestPtr.getType()->isIncompleteType()) {
@@ -2531,13 +2543,8 @@ static bool interp__builtin_is_within_lifetime(InterpState &S, CodePtr OpPC,
return false;
}
- if (!Ptr.isBlockPointer()) {
- S.FFDiag(S.Current->getSource(OpPC),
- diag::note_constexpr_access_unreadable_object)
- << AK_Read << Ptr.toDiagnosticString(S.getASTContext());
- noteValueLocation(S, Ptr);
- return false;
- }
+ if (!Ptr.isBlockPointer())
+ return diagnoseUnreadableObject(S, OpPC, Ptr, AK_Read);
// Check if we're currently running an initializer.
if (S.initializingBlock(Ptr.block()))
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index 802207e1e6e4e..9077a14324b7f 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1911,6 +1911,11 @@ namespace WMemCpy {
// both-note {{source of 'wmemcpy' is nullptr}}
static_assert(__builtin_wmemcpy(null, &global, sizeof(wchar_t))); // both-error {{}} \
// both-note {{destination of 'wmemcpy' is nullptr}}
+
+ static_assert(__builtin_wmemcpy(L"foobar", L"bazqux", 6), ""); // both-warning {{conversion from string literal}} \
+ // both-error {{}} \
+ // both-note {{assignment to object}} \
+ // both-note {{temporary created here}}
}
namespace WMemMove {
More information about the cfe-commits
mailing list