This is an archive of the discontinued LLVM Phabricator instance.

Implement __stosb intrinsic as a volatile memset
ClosedPublic

Authored by agutowski on Oct 6 2016, 10:23 AM.

Details

Summary

We need __stosb to be an intrinsic, because SecureZeroMemory function uses it without including intrin.h. Implementing it as a volatile memset is not consistent with MSDN specification, but it gives us target-independent IR while keeping the most important properties of __stosb.

Event Timeline

agutowski updated this revision to Diff 73817.Oct 6 2016, 10:23 AM
agutowski retitled this revision from to Implement __stosb intrinsic as a volatile memset.
agutowski updated this object.
agutowski added reviewers: rnk, hans, thakis, majnemer.
agutowski added a subscriber: cfe-commits.
agutowski updated this object.Oct 6 2016, 10:26 AM
hans added inline comments.Oct 6 2016, 10:41 AM
lib/CodeGen/CGBuiltin.cpp
7604

Nit: I'd suggest capital w for "We" and ending the sentence with a period. I see many other comments in the file don't do this, but we can at least set a good example :-)

7610

Hmm, does the __stosb intrinsic require Dest to be non-null (e.g. would Dest=NULL, Count=0 be OK?) I'm not even sure what llvm's memset requires actually.

7613

Why is it returning Dest here, and not the result of Builder.CreateMemSet?

agutowski updated this revision to Diff 73828.Oct 6 2016, 11:36 AM
agutowski marked an inline comment as done.

fix return value and comment

agutowski marked an inline comment as done.Oct 6 2016, 11:37 AM
agutowski added inline comments.
lib/CodeGen/CGBuiltin.cpp
7613

My mistake (that's what memset returns), thanks!

agutowski updated this revision to Diff 74157.Oct 10 2016, 12:06 PM

remove nullptr check; don't repeat EmitScalarExpr

agutowski marked 2 inline comments as done.Oct 10 2016, 12:11 PM
agutowski added inline comments.
lib/CodeGen/CGBuiltin.cpp
7610

I can't find any guarantee that memset accepts Dest=NULL and Count=0. So I guess we can either add a branch here, checking if the pointer is NULL (and that Count=0?) or assume that memset won't do anything strange. I vote for the latter (the current code does it).

majnemer added inline comments.Oct 10 2016, 12:27 PM
lib/CodeGen/CGBuiltin.cpp
7610

I think the approach you've taken here is fine, we shouldn't need a branch.

majnemer added inline comments.Oct 13 2016, 4:41 PM
lib/CodeGen/CGBuiltin.cpp
7777

I think we should manually force the alignment to 1 instead of trying to be clever.

agutowski updated this revision to Diff 74603.Oct 13 2016, 5:17 PM

force the alignment to 1

agutowski marked an inline comment as done.Oct 14 2016, 10:21 AM
majnemer accepted this revision.Oct 14 2016, 10:40 AM
majnemer edited edge metadata.

LGTM

This revision is now accepted and ready to land.Oct 14 2016, 10:40 AM
agutowski closed this revision.Oct 14 2016, 10:42 AM