[clang] Fix memcpy-operator= generation with restrict parameters. (PR #194906)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 29 11:51:31 PDT 2026
================
@@ -14928,6 +14928,23 @@ buildMemcpyForAssignmentOp(Sema &S, SourceLocation Loc, QualType T,
S.Context, To, UO_AddrOf, S.Context.getPointerType(To->getType()),
VK_PRValue, OK_Ordinary, Loc, false, S.CurFPFeatureOverrides());
+ // If this is restrict qualified, the call to memcpy will fail as this ends up
+ // being an illegal pointer cast (as it has non-local qualifiers in
+ // difference). Sema rules prevent us from calling this with anything other
+ // than the restrict qualifiers as far as I can tell(fields cant have an AS,
+ // copy is deleted if it is const, OBJC can't get here, pointer-auth can't be
+ // applied to any problematic things). In order to avoid that problem, we can
+ // just insert a cast directly to const void * / void *.
----------------
AaronBallman wrote:
```suggestion
// If this is restrict-qualified, the call to memcpy will fail as this ends up
// being an invalid pointer cast (as it has non-local qualifiers in
// difference). Sema rules prevent us from calling this with anything other
// than the restrict qualifiers as far as I can tell (fields can't have an address space,
// copy is deleted if it is const, Objective-C can't get here, pointer-auth can't be
// applied to any problematic things). In order to avoid that problem, we can
// just insert a cast directly to const void * / void *.
```
https://github.com/llvm/llvm-project/pull/194906
More information about the cfe-commits
mailing list