This is an archive of the discontinued LLVM Phabricator instance.

[LangRef] Memset/memcpy/memmove can take undef/poison pointer if the size is 0
ClosedPublic

Authored by aqjune on Aug 26 2020, 10:14 AM.

Details

Summary

According to the current LangRef, Memset/memcpy/memmove can take a
null/dangling pointer if the size is zero.
(Relevant thread: http://lists.llvm.org/pipermail/llvm-dev/2017-July/115665.html )
This patch expands it and allows the functions to take undef/poison pointers
too.

This required the updates in the align attribute since it isn't specified
what is the alignment of undef/poison pointers.
This patch states that their alignment is 1.

Diff Detail

Event Timeline

aqjune created this revision.Aug 26 2020, 10:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2020, 10:14 AM
aqjune requested review of this revision.Aug 26 2020, 10:14 AM
jdoerfert added inline comments.Aug 26 2020, 10:19 AM
llvm/docs/LangRef.rst
1161

Unsure if this is needed TBH. Might be confusing.

aqjune added inline comments.Aug 26 2020, 10:26 AM
llvm/docs/LangRef.rst
1161

Would it be better if I move this next to However, they must still be appropriately aligned. for a better context?

aqjune added inline comments.Aug 26 2020, 11:00 AM
llvm/docs/LangRef.rst
1161

This sentence was added to clarify this case:

ptr = poison
memset(ptr align 1, 0, 0) // UB?

Since memset(ptr, 0, 0) is equivalent to memset(ptr align 1, 0, 0), making the latter non-UB seemed natural to me.

efriedma added inline comments.Aug 26 2020, 11:19 AM
llvm/docs/LangRef.rst
1161

I think I would rather state it more like "align 1 has no effect on non-byval arguments", rather than explicitly refer to undef values. The practical effect is the same, and I think it makes it easier to understand the expected semantics.

12654–12655

"pointers"?

nikic added a subscriber: nikic.Aug 26 2020, 11:22 AM
aqjune updated this revision to Diff 288067.Aug 26 2020, 12:07 PM

Updated wording about align 1

jdoerfert added inline comments.Aug 26 2020, 12:07 PM
llvm/docs/LangRef.rst
1161

Right, everything has an implicit align 1 anyway, at least that was my thinking so far. So align 1 is a "no-op" on any pointer value.

aqjune updated this revision to Diff 288070.Aug 26 2020, 12:11 PM
aqjune marked an inline comment as done.

Minor updates to wording

aqjune marked an inline comment as done.Aug 26 2020, 12:13 PM
aqjune added inline comments.
llvm/docs/LangRef.rst
12654–12655

Hope this was a right fix..? :)

efriedma added inline comments.Aug 26 2020, 1:00 PM
llvm/docs/LangRef.rst
12654–12655

That's an improvement, sure. I was thinking about the existing use of "pointers" here, though, since there's only one pointer argument.

aqjune updated this revision to Diff 288097.Aug 26 2020, 1:20 PM

Wording fix

aqjune updated this revision to Diff 288098.Aug 26 2020, 1:22 PM

Wording fix

aqjune marked an inline comment as done.Aug 26 2020, 1:24 PM
This revision is now accepted and ready to land.Aug 26 2020, 1:48 PM
This revision was landed with ongoing or failed builds.Aug 26 2020, 2:19 PM
This revision was automatically updated to reflect the committed changes.