aboutsummaryrefslogtreecommitdiffstats
path: root/mempsetelem.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-06-12 18:48:26 +0200
committerMattias Andrée <maandree@kth.se>2022-06-12 18:48:26 +0200
commit9b483673c0c8a52d81127a23788fa4c976f2b10f (patch)
treef25ded5960dd73ccfe819fc3331f7a2b8c0561a1 /mempsetelem.c
parentRemove `static` from some `static inline` (diff)
downloadlibsimple-9b483673c0c8a52d81127a23788fa4c976f2b10f.tar.gz
libsimple-9b483673c0c8a52d81127a23788fa4c976f2b10f.tar.bz2
libsimple-9b483673c0c8a52d81127a23788fa4c976f2b10f.tar.xz
Replace to last static inline's with line + extern inline, and fix warnings
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'mempsetelem.c')
-rw-r--r--mempsetelem.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/mempsetelem.c b/mempsetelem.c
index cf84702..61b202b 100644
--- a/mempsetelem.c
+++ b/mempsetelem.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "libsimple.h"
+#include "common.h"
#ifndef TEST
@@ -12,6 +12,8 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t width, size_t n)
case 1:
return &((char *)memset(buf_, *(const char *)item, n))[n];
case 2:
+ if ((uintptr_t)buf_ % _Alignof(uint16_t) || (uintptr_t)item % _Alignof(uint16_t))
+ goto misaligned;
{
uint16_t *buf = buf_;
uint16_t *end = &buf[n];
@@ -21,6 +23,8 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t width, size_t n)
return buf;
}
case 4:
+ if ((uintptr_t)buf_ % _Alignof(uint32_t) || (uintptr_t)item % _Alignof(uint32_t))
+ goto misaligned;
{
uint32_t *buf = buf_;
uint32_t *end = &buf[n];
@@ -30,6 +34,8 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t width, size_t n)
return buf;
}
case 8:
+ if ((uintptr_t)buf_ % _Alignof(uint64_t) || (uintptr_t)item % _Alignof(uint64_t))
+ goto misaligned;
{
uint64_t *buf = buf_;
uint64_t *end = &buf[n];
@@ -39,6 +45,7 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t width, size_t n)
return buf;
}
default:
+ misaligned:
{
char *buf = buf_;
size_t i;
@@ -57,8 +64,8 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t width, size_t n)
int
main(void)
{
- char buf_[4096];
- char *buf = buf_;
+ _Alignas(8) char buf_[4096];
+ _Alignas(8) char *buf = buf_;
size_t i;
memset(buf, 0, sizeof(buf_));
@@ -76,6 +83,10 @@ main(void)
assert(libsimple_mempsetelem(buf, &(uint64_t){0x0102030450607080ULL}, 8, 100) == &buf[800]);
assert(libsimple_mempsetelem(buf, (char []){(char)0xA0, (char)0xB0, (char)0xC0}, 3, 16) == &buf[48]);
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wcast-align"
+#endif
+
for (i = 0; i < 48; i++)
assert(buf[i] == ((char []){(char)0xA0, (char)0xB0, (char)0xC0})[i % 3]);
for (; i < 800; i += 8)