tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Make __CTASSERT1 true static assert

Our version of _CTASSERT does not work as static assert.

$ uname -a
NetBSD rugged 8.99.42 NetBSD 8.99.42 (GENERIC) #2: Sat Jun  1 22:52:15
CEST 2019
root@chieftec:/public/netbsd-root/sys/arch/amd64/compile/GENERIC amd64
$ cat test.c

#include <sys/cdefs.h>
int main(int argc, char **argv) { __CTASSERT(argc < 0); return 0; }
$ gcc test.c
$ ./a.out

This actually rendered into a bug caught by kUBSan:

[   1.0000000] panic: UBSan: Undefined Behavior in
variable length array bound value -1 <= 0


I propose the following version to enforce constantness using bit-fields.

Prior-art is in Perl:

BTW. This will break building in a few places where __CTASSERT is
misused in a similar way.

Attachment: signature.asc
Description: OpenPGP digital signature

Home | Main Index | Thread Index | Old Index