Bug 24264 – ImportC: inliner trips on _Bool return
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-11-28T16:39:41Z
Last change time
2023-12-08T10:01:37Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
Dennis
Comments
Comment #0 by dkorpel — 2023-11-28T16:39:41Z
```C
typedef struct
{
int small;
int symbol;
} S;
inline int getSym(S self)
{
return self.symbol;
}
_Bool symIs0(S self)
{
return getSym(self) == 0;
}
void main(void)
{
S s = {0, 0};
__check(symIs0(s));
}
```
The assert fails, while it passes when removing `inline` or changing `_Bool` to `int`.
Comment #1 by bugzilla — 2023-12-08T07:09:20Z
The code generated for symIso() is wrong:
0000: 55 push RBP
0001: 48 8B EC mov RBP,RSP
0004: 48 83 EC 10 sub RSP,010h
0008: 48 89 7D F8 mov -8[RBP],RDI
000c: 83 7D FC 00 cmp dword ptr -4[RBP],0
0010: 0F 95 C0 setnz AL // !!!
0013: C9 leave
0014: C3 ret
It should be setz. Curiously, the same code in D gets it right:
0000: 55 push RBP
0001: 48 8B EC mov RBP,RSP
0004: 48 83 EC 10 sub RSP,010h
0008: 48 89 7D F8 mov -8[RBP],RDI
000c: 83 7D FC 00 cmp dword ptr -4[RBP],0
0010: 0F 94 C0 setz AL // correct
0013: C9 leave
0014: C3 ret
Comment #2 by dlang-bot — 2023-12-08T08:34:02Z
@WalterBright created dlang/dmd pull request #15892 "fix Issue 24264 - ImportC: inliner trips on _Bool return" fixing this issue:
- fix Issue 24264 - ImportC: inliner trips on _Bool return
https://github.com/dlang/dmd/pull/15892
Comment #3 by dlang-bot — 2023-12-08T10:01:37Z
dlang/dmd pull request #15892 "fix Issue 24264 - ImportC: inliner trips on _Bool return" was merged into master:
- 0a2b4e474a7146579d2c5a5155a66bbea2824d21 by Walter Bright:
fix Issue 24264 - ImportC: inliner trips on _Bool return
https://github.com/dlang/dmd/pull/15892