Skip to content

Conversation

@jayrm
Copy link
Member

@jayrm jayrm commented Apr 30, 2021

Builds on PR #303 (Add deleting destructor for c++ ABI) to add __thiscall keyword to specify the the thiscall calling convention and add additional tests for 32-bit windows gcc for the c++ ABI.

32-bit windows should be only target in need of the thiscall calling convention.

To allow some flexibility for testing code, fbc does not automatically apply the thiscall calling convention, though this could be changed in a later update. Currently __thiscall must be explicitly specified. For example:

#if defined(__FB_WIN32__) and not defined(__FB_64BIT__)
	#define thiscall __thiscall
#else
	#define thiscall
#endif

extern "c++"
	
type UDT
	value as long
	declare constructor thiscall ()
	declare constructor thiscall ( byval rhs as long )
	declare constructor thiscall ( byref rhs as const UDT )
	declare destructor thiscall ()
end type

end extern

Additionally, the fbc command line option -z no-thiscall is added to effectively disable (ignore) the __thiscall keyword to assist in moving between use and testing of the thiscall calling convention.

__thiscall is only implemented for the gcc backend. The gas backend needs many internal changes to support passing arguments in registers to support the thiscall calling convention. It seems prudent to build up the test cases in gcc before modifying the gas backend possible in a later update.

Some tests are disabled with a ENABLE_CHECK_BUGS guard because:

jayrm added 14 commits April 30, 2021 07:53
- internal changes
- rename FB_PROCATTRIB_DESTRUCTOR to FB_PROCATTRIB_DESTRUCTOR1 for the complete destructor
- add FB_PROCATTRIB_DESTRUCTOR0 for the deleting destructor
- add mangling for complete dtor (D1) and deleting dtor (D0)
- internal changes
- FB_STRUCTEXT - rename dtor to dtor1 and add dtor0
- SYMBDEFAULTMEMBERS - rename dtor to dtor1 and add dtor0
- symbSetCompDtor() - rename to symbSetCompDtor1() and add symbSetCompDtor0()
- symbGetCompDtor() - rename to symbGetCompDtor1() and add symbGetCompDtor0()
- emit the deleting destructor only in c++ mangling
- if type is in an extern "c++" block, implicitly generate and emit the deleting destructor (D0)
- adds the keyword '__thiscall'
- emits '__thiscall' or __'attribute__((thiscall))' in -gen gcc
- emits x86_thiscallcc in -gen llvm (not tested)
- ignored in -gen gas, (i.e. no change in emitted code even if thiscall is present)
- must be explicitly specified in the procedure declaration
- default use of "thiscall" calling convention still platform dependant (e.g. win x86 32-bit) compared to default usage in g++
- recommend user to '#define thiscall __thiscall' depending on target platform
- when '-z nothiscall' option is specified, fbc will not use 'thiscall' calling convention.
- test "__thiscall" calling convention
- test "cdecl" calling convetion
- test "stdcall" calling convetion
@jayrm jayrm merged commit 0540479 into freebasic:master Apr 30, 2021
@jayrm jayrm deleted the thiscall branch May 1, 2021 04:46
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

Successfully merging this pull request may close these issues.

1 participant