Skip to content

[libc] Include assert.h on baremetal targets #83324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions libc/config/baremetal/api.td
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@ include "config/public_api.td"

include "spec/stdc.td"

def AssertMacro : MacroDef<"assert"> {
let Defn = [{
#undef assert

#ifdef NDEBUG
#define assert(e) (void)0
#else

#ifdef __cplusplus
extern "C"
#endif
_Noreturn void __assert_fail(const char *, const char *, unsigned, const char *) __NOEXCEPT;

#define assert(e) \
((e) ? (void)0 : __assert_fail(#e, __FILE__, __LINE__, __PRETTY_FUNCTION__))

#endif
}];
}

def StaticAssertMacro : MacroDef<"static_assert"> {
let Defn = [{
#ifndef __cplusplus
#undef static_assert
#define static_assert _Static_assert
#endif
}];
}

def AssertAPI : PublicAPI<"assert.h"> {
let Macros = [
AssertMacro,
StaticAssertMacro,
];
}

def CTypeAPI : PublicAPI<"ctype.h"> {
}

Expand Down
3 changes: 3 additions & 0 deletions libc/config/baremetal/arm/entrypoints.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
set(TARGET_LIBC_ENTRYPOINTS
# assert.h entrypoints
libc.src.assert.__assert_fail

# ctype.h entrypoints
libc.src.ctype.isalnum
libc.src.ctype.isalpha
Expand Down
1 change: 1 addition & 0 deletions libc/config/baremetal/arm/headers.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(TARGET_PUBLIC_HEADERS
libc.include.assert
libc.include.ctype
libc.include.fenv
libc.include.errno
Expand Down
3 changes: 3 additions & 0 deletions libc/config/baremetal/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
set(TARGET_LIBC_ENTRYPOINTS
# assert.h entrypoints
libc.src.assert.__assert_fail

# ctype.h entrypoints
libc.src.ctype.isalnum
libc.src.ctype.isalpha
Expand Down
1 change: 1 addition & 0 deletions libc/config/baremetal/riscv/headers.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(TARGET_PUBLIC_HEADERS
libc.include.assert
libc.include.ctype
libc.include.fenv
libc.include.errno
Expand Down