Skip to content

Commit 68f0edf

Browse files
authored
[libc] Include assert.h on baremetal targets (#83324)
Many baremetal applications use asserts.
1 parent 1977404 commit 68f0edf

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

libc/config/baremetal/api.td

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,42 @@ include "config/public_api.td"
22

33
include "spec/stdc.td"
44

5+
def AssertMacro : MacroDef<"assert"> {
6+
let Defn = [{
7+
#undef assert
8+
9+
#ifdef NDEBUG
10+
#define assert(e) (void)0
11+
#else
12+
13+
#ifdef __cplusplus
14+
extern "C"
15+
#endif
16+
_Noreturn void __assert_fail(const char *, const char *, unsigned, const char *) __NOEXCEPT;
17+
18+
#define assert(e) \
19+
((e) ? (void)0 : __assert_fail(#e, __FILE__, __LINE__, __PRETTY_FUNCTION__))
20+
21+
#endif
22+
}];
23+
}
24+
25+
def StaticAssertMacro : MacroDef<"static_assert"> {
26+
let Defn = [{
27+
#ifndef __cplusplus
28+
#undef static_assert
29+
#define static_assert _Static_assert
30+
#endif
31+
}];
32+
}
33+
34+
def AssertAPI : PublicAPI<"assert.h"> {
35+
let Macros = [
36+
AssertMacro,
37+
StaticAssertMacro,
38+
];
39+
}
40+
541
def CTypeAPI : PublicAPI<"ctype.h"> {
642
}
743

libc/config/baremetal/arm/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
set(TARGET_LIBC_ENTRYPOINTS
2+
# assert.h entrypoints
3+
libc.src.assert.__assert_fail
4+
25
# ctype.h entrypoints
36
libc.src.ctype.isalnum
47
libc.src.ctype.isalpha

libc/config/baremetal/arm/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set(TARGET_PUBLIC_HEADERS
2+
libc.include.assert
23
libc.include.ctype
34
libc.include.fenv
45
libc.include.errno

libc/config/baremetal/riscv/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
set(TARGET_LIBC_ENTRYPOINTS
2+
# assert.h entrypoints
3+
libc.src.assert.__assert_fail
4+
25
# ctype.h entrypoints
36
libc.src.ctype.isalnum
47
libc.src.ctype.isalpha

libc/config/baremetal/riscv/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set(TARGET_PUBLIC_HEADERS
2+
libc.include.assert
23
libc.include.ctype
34
libc.include.fenv
45
libc.include.errno

0 commit comments

Comments
 (0)