* patch: sequence points in memset
@ 2017-07-10 14:39 Pascal Cuoq
2017-07-10 15:10 ` Alexander Monakov
0 siblings, 1 reply; 2+ messages in thread
From: Pascal Cuoq @ 2017-07-10 14:39 UTC (permalink / raw)
To: musl
[-- Attachment #1: Type: text/plain, Size: 435 bytes --]
Following a recent discussion of statements shaped like x = x = c;, the attached patch introduces additional sequence points in musl's implementation of memset, because no realistic target platform benefits from the lack of sequence points in the current version, and if a hypothetical target (VLIW maybe?) was designed to benefit from the lack of sequence point, the lack of sequence point might just as well cause harm.
Pascal
[-- Attachment #2: memset_sp.patch --]
[-- Type: application/octet-stream, Size: 632 bytes --]
diff --git a/src/string/memset.c b/src/string/memset.c
index f438b07..5613a14 100644
--- a/src/string/memset.c
+++ b/src/string/memset.c
@@ -11,12 +11,16 @@ void *memset(void *dest, int c, size_t n)
* offsets are well-defined and in the dest region. */
if (!n) return dest;
- s[0] = s[n-1] = c;
+ s[0] = c;
+ s[n-1] = c;
if (n <= 2) return dest;
- s[1] = s[n-2] = c;
- s[2] = s[n-3] = c;
+ s[1] = c;
+ s[2] = c;
+ s[n-2] = c;
+ s[n-3] = c;
if (n <= 6) return dest;
- s[3] = s[n-4] = c;
+ s[3] = c;
+ s[n-4] = c;
if (n <= 8) return dest;
/* Advance pointer to align it at a 4-byte boundary,
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: patch: sequence points in memset
2017-07-10 14:39 patch: sequence points in memset Pascal Cuoq
@ 2017-07-10 15:10 ` Alexander Monakov
0 siblings, 0 replies; 2+ messages in thread
From: Alexander Monakov @ 2017-07-10 15:10 UTC (permalink / raw)
To: musl
Alternatively, the middle group could read:
s[1] = s[2] = c;
s[n-3] = s[n-2] = c;
(it doesn't really matter, but spelling it this way at least leaves
a hint in the source that some assignments are not chained for a reason)
Alexander
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-07-10 15:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-10 14:39 patch: sequence points in memset Pascal Cuoq
2017-07-10 15:10 ` Alexander Monakov
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).