www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Weird DMD codegen issue

reply Stanislav Blinov <stanislav.blinov gmail.com> writes:
So I have a function:

```d
auto foo(C, K)(Strukt1* s, Strukt2 a, uint b, scope C c, scope K 
k, out Strukt3 r)
{ /* ... */ }
```

Where return type is `Strukt4`. dmd borks the first argument on 
call (at least on Linux). Workarounds so far I found:

1) adding `extern(C)`
2) reducing number of parameters - five is fine, as soon as I add 
the sixth or more - it breaks (but not with `extern(C)`).

Problem is, I tried reproducing it outside of codebase, with no 
success :( Does that sound familiar to anyone? Maybe there's 
already a report about this on bugzilla? Any pointers on tracking 
this down?
Nov 04 2021
next sibling parent Temtaime <temtaime gmail.com> writes:
On Thursday, 4 November 2021 at 16:32:54 UTC, Stanislav Blinov 
wrote:
 So I have a function:

 ```d
 auto foo(C, K)(Strukt1* s, Strukt2 a, uint b, scope C c, scope 
 K k, out Strukt3 r)
 { /* ... */ }
 ```

 Where return type is `Strukt4`. dmd borks the first argument on 
 call (at least on Linux). Workarounds so far I found:

 1) adding `extern(C)`
 2) reducing number of parameters - five is fine, as soon as I 
 add the sixth or more - it breaks (but not with `extern(C)`).

 Problem is, I tried reproducing it outside of codebase, with no 
 success :( Does that sound familiar to anyone? Maybe there's 
 already a report about this on bugzilla? Any pointers on 
 tracking this down?
Just don't use dmd, go with ldc
Nov 04 2021
prev sibling next sibling parent user1234 <user1234 12.de> writes:
On Thursday, 4 November 2021 at 16:32:54 UTC, Stanislav Blinov 
wrote:
 So I have a function:

 ```d
 auto foo(C, K)(Strukt1* s, Strukt2 a, uint b, scope C c, scope 
 K k, out Strukt3 r)
 { /* ... */ }
 ```

 Where return type is `Strukt4`. dmd borks the first argument on 
 call (at least on Linux). Workarounds so far I found:

 1) adding `extern(C)`
 2) reducing number of parameters - five is fine, as soon as I 
 add the sixth or more - it breaks (but not with `extern(C)`).

 Problem is, I tried reproducing it outside of codebase, with no 
 success :( Does that sound familiar to anyone? Maybe there's 
 already a report about this on bugzilla? Any pointers on 
 tracking this down?
As you cannot reduce I suggest to try with every .0 DMD version, degressively, to see if it's a regression. Is it only with -O and are the structure very small? that could be a SROA problem then. Otherwise I have a specific PR in mind, that is [the big backend](https://github.com/dlang/dmd/pull/10200) one that fixed system V ABI. If it's the culprit, manually checking with different DMD version will be useful (unless it did work previously either)
Nov 04 2021
prev sibling parent reply max haughton <maxhaton gmail.com> writes:
On Thursday, 4 November 2021 at 16:32:54 UTC, Stanislav Blinov 
wrote:
 So I have a function:

 ```d
 auto foo(C, K)(Strukt1* s, Strukt2 a, uint b, scope C c, scope 
 K k, out Strukt3 r)
 { /* ... */ }
 ```

 Where return type is `Strukt4`. dmd borks the first argument on 
 call (at least on Linux). Workarounds so far I found:

 1) adding `extern(C)`
 2) reducing number of parameters - five is fine, as soon as I 
 add the sixth or more - it breaks (but not with `extern(C)`).

 Problem is, I tried reproducing it outside of codebase, with no 
 success :( Does that sound familiar to anyone? Maybe there's 
 already a report about this on bugzilla? Any pointers on 
 tracking this down?
Dustmite? At very least can you give the definitions of the types used at the call site where it breaks.
Nov 04 2021
parent Stanislav Blinov <stanislav.blinov gmail.com> writes:
On Thursday, 4 November 2021 at 17:46:02 UTC, max haughton wrote:

 At very least can you give the definitions of the types used at 
 the call site where it breaks.
Narrowed it down somewhat. Thanks guys! https://issues.dlang.org/show_bug.cgi?id=22484
Nov 05 2021