[llvm-dev] Which assumptions do llvm.memcpy/memmove/memset.* make when the count is 0?

Ralf Jung via llvm-dev llvm-dev at lists.llvm.org
Thu Jul 20 14:35:54 PDT 2017


Hi all,

when I call the llvm.memcpy/memmove/memset.* intrinsics, typically I
have to pass in valid (non-dangling, non-NULL pointers) of the given
alignment.  However, to what extent to these rules apply when the count
is 0?  Concretely (for any variant of the three aforementioned
intrinsics): Is it UB to call them on a dangling pointer when count is
0?  On a pointer of less than the given alignment?

The actual operation will of course not do anything, but I am worried
about some analysis seeing a pointer being used as an argument to one of
these intrinsics, and then assuming the pointer is valid and aligned
without proving that the count is > 0.

E.g., Rust's HashMap indirectly calls memset(0x0, 0, 0, ..., false).
Vec calls memcpy(..., 0x1, 0, 4, false).  Is that a problem?

Kind regards,
Ralf

PS: I'm not on the list, so please keep me in Cc.


More information about the llvm-dev mailing list