You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Swift's API contract has always been that its typed pointers follow strict aliasing rules. (In fact, stricter-than-strict, as Swift does not inherit the char * escape-hatch of C.) As a result, we'd expect pointers of different types to have redundant loads removed.
Environment
Swift 5.3 and nightly, Linux and Mac.
Additional Detail from JIRA
md5: f8c7e59cf64aab2902debd4264d6bb9b
Issue Description:
Swift's API contract has always been that its typed pointers follow strict aliasing rules. (In fact, stricter-than-strict, as Swift does not inherit the
char *
escape-hatch of C.) As a result, we'd expect pointers of different types to have redundant loads removed.Consider the program below:
When compiled on macOS at
-O
and disassembled, we get this (a compiler explorer example is also available):Note that both functions generate two loads from
eax
, even though inaddTwoHeterogeneous
the second load is redundant, as the pointers may not alias.Consider equivalent C code:
Here we get the expected disassembly output when compiled on macOS at
-O2
(again, a compiler explorer example is available):Notice that in the
NoAlias
variant of the function there is only one load fromrax
.The text was updated successfully, but these errors were encountered: