Skip to content

Fix mixed-size memcpy_s#1002

Merged
hernanponcedeleon merged 17 commits intodevelopmentfrom
fix-mixedsize-memcpy
Mar 13, 2026
Merged

Fix mixed-size memcpy_s#1002
hernanponcedeleon merged 17 commits intodevelopmentfrom
fix-mixedsize-memcpy

Conversation

@xeren
Copy link
Collaborator

@xeren xeren commented Mar 2, 2026

Modifies the intrinsics for the string.h standard library functions to be compatible with mixed-size accesses. With the current default settings, dynamic memory accesses are torn into units of archType. E.g. memcpy(dest, src, 16) translates to

bv64 __memcpy_1 = load(bv64 dest)
store(bv64 src, bv64 __memcpy_1)
bv64 __memcpy_2 = load(bv64 dest + (bv64) 8)
store(bv64 src + (bv64) 8, bv64 __memcpy_2)

With the option --mixedSize=true, more informed tearing is applied later. So that call translates to

bv128 __memcpy#1 = load(bv64 dest)
store(bv64 src, bv128 __memcpy#1)

WIth this PR, that scheme also applies to memcpy_s, memcmp and memset. This should fix at least #977.

Comment on lines +1744 to +1745
final IntegerType resultType = returnReg.getType() instanceof IntegerType t ? t : null;
final Expression zero = expressions.makeZero(resultType);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like this kind of code. If we expect the result register to be of type integer (otherwise we will get some exception somewhere else when trying to create the zero value with null type), we should have a proper precondition to the method

xeren added 6 commits March 12, 2026 02:16
Support arbitrary fill values for `memset`.
Re-implement deterministic return values for `memcmp`.
Fix span size for `--mixedSize=false`.
This enables more dead code elimination.
Will later enable dynamic-sized memcpy.
Support arbitrary fill values for `memset`.
Re-implement deterministic return values for `memcmp`.
Fix span size for `--mixedSize=false`.
@ThomasHaas
Copy link
Collaborator

ThomasHaas commented Mar 12, 2026

I think the code looks a lot better now, especially with the clarification what a Slice is.
I have not checked all details, but I think it can be merged.

Comment on lines +1665 to +1666
final Expression errorCodeFail = expressions.makeOne((IntegerType)resultRegister.getType());
final Expression errorCodeSuccess = expressions.makeZero((IntegerType)resultRegister.getType());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errorCodeSuccess -> having error/success together is weird. I would call it returnCode

@hernanponcedeleon hernanponcedeleon merged commit 5bc5094 into development Mar 13, 2026
7 checks passed
@hernanponcedeleon hernanponcedeleon deleted the fix-mixedsize-memcpy branch March 13, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants