[libc-commits] [PATCH] D75420: [libc] Add initial assert definition

Alex Brachet via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Mar 9 00:30:31 PDT 2020

abrachet marked 9 inline comments as done.
abrachet added inline comments.

Comment at: libc/config/linux/api.td:38
   let Defn = [{
     int *__errno_location();
     #define errno (*__errno_location())
sivachandra wrote:
> I think `extern C` for c++ is missing here.
I'll add just commit this outside of this patch to not mess with the diff.

Comment at: libc/config/linux/api.td:45
+  let Macros = [
+    StaticAssertMacro,
+  ];
sivachandra wrote:
> Why not the `assert` macro?
`assert` shouldn't be inside the include guards of assert.h so I think it needs to be handwritten in assert.h.def

Comment at: libc/config/linux/api.td:48
+  let Functions = [
+    "__assert_fail",
sivachandra wrote:
> Instead, we should define the assert macro as:
> ```
> #ifdef __cplusplus
> extern C
> #endif
> void __assert_fail(...); // Don't use size_t for arg types
> #define assert ...
> #endif
> ```
Same as above. For reference the generated header looks like 
//===---------------- C standard library header assert.h ------------------===//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception


#include <__llvm-libc-common.h>

#ifndef __cplusplus
#define static_assert _Static_assert



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


// This file may be usefully included multiple times to change assert()'s
// definition based on NDEBUG.

#undef assert

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



More information about the libc-commits mailing list