May 19, 2012
Hi,

I seem to have discovered a bug in the D compiler which is causing it to emit incompatible code with gcc on Ubuntu 11.04 x86_64. I have minimised the code required to reproduce this problem and uploaded it to github, here is the link https://github.com/SDX2000/CFromDTest1.

Once you have downloaded it run build to generate the executables. You'll see that the output produced by the d program is different from the output produced by the equivalent c code. I have spent some time on analysing the generated assembly. You'll find annotated assembly code main.d etc highlighting the problem.

Basically the problem is that dmd generates code which is not compatible with gcc when a C function returns a struct.

Please do let me know if this is a legitimate bug and if I need to file a bug report.

Regards,
Sandeep Datta.
May 19, 2012
On Saturday, 19 May 2012 at 18:31:45 UTC, Sandeep Datta wrote:
> Please do let me know if this is a legitimate bug and if I need to file a bug report.

x86_64 struct ABI differences are a known problem and being worked on, a fix will likely be included with the next release.

David
May 19, 2012
On Saturday, 19 May 2012 at 18:37:20 UTC, David Nadlinger wrote:
> On Saturday, 19 May 2012 at 18:31:45 UTC, Sandeep Datta wrote:
>> Please do let me know if this is a legitimate bug and if I need to file a bug report.
>
> x86_64 struct ABI differences are a known problem and being worked on, a fix will likely be included with the next release.
>
> David

Hmm, are there any known work arounds? I am in a fix as I need to use the demios/libclang wrapper but it has several functions which return structs.
May 19, 2012
On Saturday, 19 May 2012 at 18:41:28 UTC, Sandeep Datta wrote:
> On Saturday, 19 May 2012 at 18:37:20 UTC, David Nadlinger wrote:
>> On Saturday, 19 May 2012 at 18:31:45 UTC, Sandeep Datta wrote:
>>> Please do let me know if this is a legitimate bug and if I need to file a bug report.
>>
>> x86_64 struct ABI differences are a known problem and being worked on, a fix will likely be included with the next release.
>>
>> David
>
> Hmm, are there any known work arounds? I am in a fix as I need to use the demios/libclang wrapper but it has several functions which return structs.

Oops...hit send a little too early...I guess building with -m32 should fix this problem, no?
May 20, 2012
On 2012-05-19 20:42, Sandeep Datta wrote:

> Oops...hit send a little too early...I guess building with -m32 should
> fix this problem, no?

Yes that will fix the problem.

-- 
/Jacob Carlborg
May 20, 2012
On 2012-05-19 20:41, Sandeep Datta wrote:

> Hmm, are there any known work arounds? I am in a fix as I need to use
> the demios/libclang wrapper but it has several functions which return
> structs.

There are bindings that are more up to date in my DStep project. It also contains some useful wrappers:

https://github.com/jacob-carlborg/dstep/tree/master/clang

The bindings are in the "c" directory.

-- 
/Jacob Carlborg
May 20, 2012
On Sunday, 20 May 2012 at 11:40:35 UTC, Jacob Carlborg wrote:
> On 2012-05-19 20:41, Sandeep Datta wrote:
>
>> Hmm, are there any known work arounds? I am in a fix as I need to use
>> the demios/libclang wrapper but it has several functions which return
>> structs.
>
> There are bindings that are more up to date in my DStep project. It also contains some useful wrappers:
>
> https://github.com/jacob-carlborg/dstep/tree/master/clang
>
> The bindings are in the "c" directory.

Thanks but will your bindings work in 64bit mode? It seems to me some functions are still returning a struct. I think I will have to rebuild llvm+clang in 32bit, right?
May 20, 2012
On 2012-05-20 19:00, Sandeep Datta wrote:

> Thanks but will your bindings work in 64bit mode? It seems to me some
> functions are still returning a struct. I think I will have to rebuild
> llvm+clang in 32bit, right?

The bindings will work for both 32 and 64bit. It's impossible to change the bindings in any way to have it work on 64bit. The bug is with DMD, not the bindings.

Yes you need to rebuild LLVM and Clang in 32bit mode. When the DMD bug is fixed my bindings should work in 64bit as well.

-- 
/Jacob Carlborg
Top | Discussion index | About this forum | D home