mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-03 16:41:06 +03:00
-betterC: Use C assert function
Instead of druntime's _d_assert[_msg], _d_arraybounds and _d_switch_error. Tested by dmd-testsuite's runnable/cassert and compilable/betterCarray.
This commit is contained in:
parent
fbbbeecaca
commit
30b858781b
10 changed files with 106 additions and 32 deletions
|
@ -160,6 +160,21 @@ llvm::Function *getRuntimeFunction(const Loc &loc, llvm::Module &target,
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const char *getCAssertFunctionName() {
|
||||
if (global.params.targetTriple->isOSDarwin()) {
|
||||
return "__assert_rtn";
|
||||
} else if (global.params.targetTriple->isWindowsMSVCEnvironment()) {
|
||||
return "_assert";
|
||||
}
|
||||
return "__assert";
|
||||
}
|
||||
|
||||
llvm::Function *getCAssertFunction(const Loc &loc, llvm::Module &target) {
|
||||
return getRuntimeFunction(loc, target, getCAssertFunctionName());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// extern (D) alias dg_t = int delegate(void*);
|
||||
static Type *rt_dg1() {
|
||||
static Type *dg_t = nullptr;
|
||||
|
@ -330,6 +345,17 @@ static void buildRuntimeModule() {
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// C assert function:
|
||||
// OSX: void __assert_rtn(const char *func, const char *file, unsigned line,
|
||||
// const char *msg)
|
||||
// else: void [_]_assert(const char *msg, const char *file, unsigned line)
|
||||
createFwdDecl(
|
||||
LINKc, Type::tvoid, {getCAssertFunctionName()},
|
||||
global.params.targetTriple->isOSDarwin()
|
||||
? llvm::ArrayRef<Type *>({voidPtrTy, voidPtrTy, uintTy, voidPtrTy})
|
||||
: llvm::ArrayRef<Type *>({voidPtrTy, voidPtrTy, uintTy}),
|
||||
{}, Attr_Cold_NoReturn);
|
||||
|
||||
// void _d_assert(string file, uint line)
|
||||
// void _d_arraybounds(string file, uint line)
|
||||
createFwdDecl(LINKc, Type::tvoid, {"_d_assert", "_d_arraybounds"},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue