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] extern(C) struct with ctor and field #624

Closed
MartinNowak opened this issue Jun 9, 2014 · 8 comments
Closed

[ICE] extern(C) struct with ctor and field #624

MartinNowak opened this issue Jun 9, 2014 · 8 comments

Comments

@MartinNowak
Copy link
Contributor

module bug;
extern(C):

struct Value
{
    this(string) {}
    string s;
}

ldc2 -c bug.d

Incompatible argument and return types for 'returned' attribute
{ i64, i64 } (%bug.Value_, { i64, i8_ })* @D3bug5Value6__ctorMUNcAyaZS3bug5Value
Broken module found, compilation aborted!
0 ldc2 0x000000000115b1d2 llvm::sys::PrintStackTrace(IO_FILE) + 34
1 ldc2 0x000000000115a781
2 libpthread.so.0 0x00007f7214e13750
3 libc.so.6 0x00007f7214051c39 gsignal + 57
4 libc.so.6 0x00007f7214053348 abort + 328
5 ldc2 0x000000000111dc3b
6 ldc2 0x00000000010f2f6c llvm::FPPassManager::runOnFunction(llvm::Function&) + 540
7 ldc2 0x00000000010f300b llvm::FPPassManager::runOnModule(llvm::Module&) + 43
8 ldc2 0x00000000010f2bbc llvm::legacy::PassManagerImpl::run(llvm::Module&) + 748
9 ldc2 0x000000000111ba71 llvm::verifyModule(llvm::Module const&, llvm::VerifierFailureAction, std::string
) + 913
10 ldc2 0x00000000006a206c Module::genLLVMModule(llvm::LLVMContext&) + 1724
11 ldc2 0x000000000055c898 main + 6200
12 libc.so.6 0x00007f721403dd65 __libc_start_main + 245
13 ldc2 0x000000000057566d

@dnadlinger
Copy link
Member

This is with a release build of LLVM, right?

Quite probably, we are generating invalid IR somewhere, which should be easy to catch with a debug build of LLVM. Unfortunately, I can't check this right now, as I am not at my dev machine.

@MartinNowak
Copy link
Contributor Author

This is with a release build of LLVM, right?

Sorry, should have written that. It happens on both 0.12.1 and 0.13.0-beta1.

@dnadlinger
Copy link
Member

Okay, thanks – we indeed build those against an LLVM build with assertions disabled.

@redstar
Copy link
Member

redstar commented Jun 11, 2014

I get the assertion, too.

I think the root cause is incompatible types but I still need to check this.

@redstar
Copy link
Member

redstar commented Jun 11, 2014

I added the returned attribute to the code generator. This is a hint to LLVM that the parameter marked with this attribute is returned as function result. This should be the case for ctors.
It looks that in this example the LLVM type of this is Value but the type of the return value is Value * which triggers the assertion.

@redstar
Copy link
Member

redstar commented Jun 12, 2014

This quick fix is disable adding the returned attribute.

redstar added a commit to redstar/ldc that referenced this issue Jun 13, 2014
redstar added a commit that referenced this issue Jun 13, 2014
@MartinNowak
Copy link
Contributor Author

Thanks for the quick fix.

@redstar
Copy link
Member

redstar commented Jun 23, 2014

Well, it was easy to prevent the crash. But now there is an unused optimization opportunity...

redstar pushed a commit that referenced this issue Sep 27, 2014
core.demangle.mangleFunc for different linkage types
redstar added a commit to redstar/ldc that referenced this issue Nov 13, 2014
In case of a ctor 'this' is passed to the function and is also the
return value. This is the perfect case for the 'Returned' attribute.
But the x86_64 ABI missed the fact that the return value was a pointer
to a struct and did a struct rewrite, resulting in an bitcast
incompatible type.
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

3 participants