]> Sergey Matveev's repositories - bfs.git/commitdiff
dstring: Limit the special dchar typedef to lint builds
authorTavian Barnes <tavianator@tavianator.com>
Tue, 3 Oct 2023 20:26:05 +0000 (16:26 -0400)
committerTavian Barnes <tavianator@tavianator.com>
Wed, 4 Oct 2023 13:28:52 +0000 (09:28 -0400)
Clang still thinks that alignof(dstr[1]) == 2, so out of an abundance of
caution, don't mess with dchar alignment in normal builds.

src/dstring.h

index 91a600c5cda9403f5592d06b7ecb5fd3c022c194..6496a4fe171797b26af9e1161d85f4f8c72d0a1e 100644 (file)
 #include <stddef.h>
 
 /** Marker type for dynamic strings. */
-#if __clang__
+#if BFS_LINT && __clang__
 // Abuse __attribute__(aligned) to make a type that allows
 //
 //     dchar * -> char *
 //
-// conversions, but warns on
+// conversions, but warns (with Clang's -Walign-mismatch) on
 //
 //     char * -> dchar *
-//
-// (with Clang's -Walign-mismatch).  The alignment is not a lie, due to the
-// layout of struct dstring, but we only enable this on Clang because GCC
-// tracks alignment through array accesses, reporting UBSan errors on (and
-// maybe even miscompiling) dstr[1].
 typedef __attribute__((aligned(alignof(size_t)))) char dchar;
 #else
 typedef char dchar;