From 00a8e6711ea5f22e47f81bed85b49511a9c2a60e Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Tue, 14 Nov 2023 14:59:21 -0500 Subject: add a function that triggers UB if the assert() macro is suppressed to access an actual function --- mk/assert.d | 10 ++++++++++ src/assert/assert.c | 13 +++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 mk/assert.d create mode 100644 src/assert/assert.c diff --git a/mk/assert.d b/mk/assert.d new file mode 100644 index 00000000..aae9fcd0 --- /dev/null +++ b/mk/assert.d @@ -0,0 +1,10 @@ +libc_C.0: libc.a(assert.o) +libc.a(assert.o): $(OBJDIR)/assert.o + @$(AR) $(ARFLAGS) $@ $(OBJDIR)/$% + +$(OBJDIR)/assert.o: src/assert/assert.c +$(OBJDIR)/assert.o: src/stdlib/_stdlib.h +$(OBJDIR)/assert.o: + @echo " [CC] $@" + @mkdir -p $(@D) + @$(CC) -c -o $@ $(CFLAGS) src/assert/assert.c diff --git a/src/assert/assert.c b/src/assert/assert.c new file mode 100644 index 00000000..2a5551a4 --- /dev/null +++ b/src/assert/assert.c @@ -0,0 +1,13 @@ +#include +#include "stdlib/_stdlib.h" + +_Noreturn void assert(int exp) +{ + (void)exp; + __stdlib.constraint_handler("Undefined Behavior: The assert() macro has been suppressed to access an actual function", NULL, 0); + abort(); +} + +/* +STDC(0) +*/ -- cgit v1.2.1