Skip to content
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

ICE when providing mismatched _d_assert_msg() declaration #958

Closed
timotheecour opened this issue May 31, 2015 · 3 comments
Closed

ICE when providing mismatched _d_assert_msg() declaration #958

timotheecour opened this issue May 31, 2015 · 3 comments

Comments

@timotheecour
Copy link

ldc2 -c -oq -od=/tmp/d08 fun.d

fun.d:

import std.string;
void fun(){
  format("");
}
extern(C)void _d_assert_msg();

ldc2 --version
LDC - the LLVM D compiler (cf0589):
based on DMD v2.066.1 and LLVM 3.6.1
Default target: x86_64-apple-darwin14.3.0
Host CPU: core-avx2

0 ldc2 0x0000000104878ad1 llvm::sys::PrintStackTrace(sFILE) + 57
1 ldc2 0x0000000104879027 SignalHandler(int) + 217
2 libsystem_platform.dylib 0x00007fff9a658f1a sigtramp + 26
3 ldc2 0x0000000104c0ec36 nuls + 69742
4 ldc2 0x0000000104878eb6 abort + 22
5 ldc2 0x0000000104878ea0 abort + 0
6 ldc2 0x000000010480c0d8 llvm::CallInst::init(llvm::Value
, llvm::Twine const&) + 0
7 ldc2 0x0000000103f38f99 llvm::IRBuilder<true, llvm::ConstantFolder, llvm::IRBuilderDefaultInserter >::CreateCall(llvm::Value
, llvm::ArrayRefllvm::Value_, llvm::Twine const&) + 201
8 ldc2 0x0000000103f3fbde llvm::CallSite IRState::CreateCallOrInvoke<llvm::SmallVector<llvm::Value*, 3u> >(llvm::Value_, llvm::SmallVector<llvm::Value_, 3u> const&, char const_) + 686
9 ldc2 0x0000000103f39af8 DtoAssert(Module_, Loc&, DValue_) + 312
10 ldc2 0x0000000103f7427b ToElemVisitor::visit(AssertExp_) + 763
11 ldc2 0x0000000103f70236 toElemDtor(Expression_) + 614
12 ldc2 0x0000000103f5f502 ToIRVisitor::visit(ExpStatement_) + 130
13 ldc2 0x0000000103f5f594 ToIRVisitor::visit(CompoundStatement_) + 116
14 ldc2 0x0000000103f5f3ee codegenFunction(Statement_, IRState_) + 190
15 ldc2 0x0000000103f35eee DtoDefineFunction(FuncDeclaration_) + 3982
16 ldc2 0x0000000103f2cf4f CodegenVisitor::visit(StructDeclaration_) + 223
17 ldc2 0x0000000103f2cd3f CodegenVisitor::visit(TemplateInstance_) + 143
18 ldc2 0x0000000103f2c352 Declaration_codegen(Dsymbol*) + 50
19 ldc2 0x0000000103f42ea6 Module::genLLVMModule(llvm::LLVMContext&) + 3206
20 ldc2 0x0000000103de260c main + 6044
21 libdyld.dylib 0x00007fff8c15d5c9 start + 1
22 libdyld.dylib 0x0000000000000011 start + 1944726089

@redstar
Copy link
Member

redstar commented May 31, 2015

This is a nasty one. A call to _d_assert_msg() is generated for an assert expression. Inside the same module, the prototype is checked. E.g.

void fun(int x){
  assert(x > 1, "x should be greater than 1");
}
extern(C)void _d_assert_msg();

triggers the error message:

ldc_github_958.d(4): Error: Function type does not match previously declared fun ction with the same mangled name: _d_assert_msg

But the import for std.string indirectly imports assert expressions. Here the prototype is not checked. Then 2 different prototypes are used, which triggers the assertion.

@dnadlinger
Copy link
Member

Are you sure? At first glance, the difference simply seems to be that the imported asserts would be codegen'd after the declaration, so instead of copying over the _d_assert_msg declaration from our internal runtime module we just use the existing ones. The code that declares runtime functions should check for matching types if the functions already exist.

@dnadlinger dnadlinger reopened this Jun 1, 2015
@dnadlinger dnadlinger changed the title Assertion failed: ((Args.size() == FTy->getNumParams() || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && "Calling a function with bad signature!"), function init, file Instructions.cpp, line 276. ICE when providing invalid _d_assert_msg declaration Jul 13, 2015
@dnadlinger dnadlinger changed the title ICE when providing invalid _d_assert_msg declaration ICE when providing mismatched _d_assert_msg() declaration Jul 13, 2015
kinke added a commit to kinke/ldc that referenced this issue Jun 19, 2016
This fixes issue ldc-developers#958 by checking the function type of an existing
function declaration with the same runtime function name inside the
codegen'd module.
This should normally be an existing forward declaration from a previous
runtime call, but the user is free to declare (and even implement) it
too.

The LOC for the error is empty as the provided `loc` may likely be from
a template instantiation from another module.
@kinke
Copy link
Member

kinke commented Oct 30, 2017

Seems like we forgot to close this. Failing now with a proper error msg: https://godbolt.org/g/1Wqm1u

@kinke kinke closed this as completed Oct 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants