wrong-code if stdcall is applied via template parameters
| Affects | Status | Importance | Assigned to | Milestone | |
|---|---|---|---|---|---|
| gcc-9 (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned | ||
Bug Description
g++ 9.3.0-17ubuntu1
>>>>>>>>>>>>>>>
// g++-9 -c -O0 simple.cpp -m32
//
// objdump -S simple.o
template<bool bIsStdcall, typename T> struct func_ptr_t;
template<typename T> struct func_ptr_t<false,T> {
using type = void(*)(T);
};
template<typename T> struct func_ptr_t<true,T> {
#if 1
using type = void(__
#else
using type = void(__
#endif
};
#if 1
using foo_stdcall_ptr = func_ptr_
using foo_cdecl_ptr = func_ptr_
#else
using foo_stdcall_ptr = void(__
using foo_cdecl_ptr = void(*)(int,int);
#endif
foo_stdcall_ptr foo_stdcall;
foo_cdecl_ptr foo_cdecl;
void bar_stdcall() {
foo_stdcall(1);
}
void bar_cdecl() {
foo_cdecl(1);
}
>>>>>>>>>>>>>>>
--- bar_cdecl.S 2021-03-09 00:54:58.404022904 +0000
+++ bar_stdcall.S 2021-03-09 00:52:07.900015002 +0000
@@ -1,15 +1,15 @@
-<bar_cdecl()>:
+<bar_stdcall()>:
0: f3 0f 1e fb endbr32
4: 55 push %ebp
5: 89 e5 mov %esp,%ebp
7: 83 ec 08 sub $0x8,%esp
- a: e8 fc ff ff ff call 32 <bar_cdecl()+0xb>
+ a: e8 fc ff ff ff call b <bar_stdcall()+0xb>
f: 05 01 00 00 00 add $0x1,%eax
14: 8b 80 00 00 00 00 mov 0x0(%eax),%eax
1a: 83 ec 0c sub $0xc,%esp
1d: 6a 01 push $0x1
1f: ff d0 call *%eax
- 21: 83 c4 10 add $0x10,%esp
+ 21: 83 c4 0c add $0xc,%esp
24: 90 nop
25: c9 leave
26: c3 ret
```
Upstream gcc-9.3.0 does not have this bug (See https:/
I don't think it was realized (when the was found/fixed upstream) that it could also cause wrong-code, so I'm just posting this to make you aware that ubuntu has backported a regression and not the fix. I assume you'll want to align with upstream on whether gcc-9 branch ends up getting this fixed or not.

9.4.0 and 10.5.0 have been backported to 20.04 LTS