mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-02 16:11:08 +03:00
Fix C assert calls for newlib (#4351)
This commit is contained in:
parent
25dc3fc6eb
commit
d001a7cdb8
3 changed files with 23 additions and 0 deletions
|
@ -317,6 +317,14 @@ void DtoCAssert(Module *M, const Loc &loc, LLValue *msg) {
|
||||||
args.push_back(file);
|
args.push_back(file);
|
||||||
args.push_back(line);
|
args.push_back(line);
|
||||||
args.push_back(msg);
|
args.push_back(msg);
|
||||||
|
} else if (global.params.isNewlibEnvironment) {
|
||||||
|
const auto irFunc = gIR->func();
|
||||||
|
const auto funcName =
|
||||||
|
irFunc && irFunc->decl ? irFunc->decl->toPrettyChars() : "";
|
||||||
|
args.push_back(file);
|
||||||
|
args.push_back(line);
|
||||||
|
args.push_back(DtoConstCString(funcName));
|
||||||
|
args.push_back(msg);
|
||||||
} else {
|
} else {
|
||||||
args.push_back(msg);
|
args.push_back(msg);
|
||||||
args.push_back(file);
|
args.push_back(file);
|
||||||
|
|
|
@ -364,6 +364,8 @@ llvm::Function *getRuntimeFunction(const Loc &loc, llvm::Module &target,
|
||||||
// const char *funcname);
|
// const char *funcname);
|
||||||
// uClibc: void __assert(const char *assertion, const char *filename, int linenumber,
|
// uClibc: void __assert(const char *assertion, const char *filename, int linenumber,
|
||||||
// const char *function);
|
// const char *function);
|
||||||
|
// newlib: void __assert_func(const char *file, int line, const char *func,
|
||||||
|
// const char *failedexpr)
|
||||||
// else: void __assert(const char *msg, const char *file, unsigned line)
|
// else: void __assert(const char *msg, const char *file, unsigned line)
|
||||||
|
|
||||||
static const char *getCAssertFunctionName() {
|
static const char *getCAssertFunctionName() {
|
||||||
|
@ -376,6 +378,8 @@ static const char *getCAssertFunctionName() {
|
||||||
return "__assert_c99";
|
return "__assert_c99";
|
||||||
} else if (triple.isMusl()) {
|
} else if (triple.isMusl()) {
|
||||||
return "__assert_fail";
|
return "__assert_fail";
|
||||||
|
} else if (global.params.isNewlibEnvironment) {
|
||||||
|
return "__assert_func";
|
||||||
}
|
}
|
||||||
return "__assert";
|
return "__assert";
|
||||||
}
|
}
|
||||||
|
@ -392,6 +396,9 @@ static std::vector<PotentiallyLazyType> getCAssertFunctionParamTypes() {
|
||||||
if (triple.getEnvironment() == llvm::Triple::Android) {
|
if (triple.getEnvironment() == llvm::Triple::Android) {
|
||||||
return {voidPtr, uint, voidPtr};
|
return {voidPtr, uint, voidPtr};
|
||||||
}
|
}
|
||||||
|
if (global.params.isNewlibEnvironment) {
|
||||||
|
return {voidPtr, uint, voidPtr, voidPtr};
|
||||||
|
}
|
||||||
return {voidPtr, voidPtr, uint};
|
return {voidPtr, voidPtr, uint};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
tests/codegen/newlib_assert.d
Normal file
8
tests/codegen/newlib_assert.d
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// RUN: %ldc %s -c --output-ll -of=%t.ll --mtriple=arm-none-newlibeabi --betterC --checkaction=C > %t && FileCheck %s < %t.ll
|
||||||
|
|
||||||
|
extern (C) void main()
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// CHECK: declare void @__assert_func(i8*, i32, i8*, i8*)
|
Loading…
Add table
Add a link
Reference in a new issue