Issue 109987
Summary clang fastcall x86 abi does not match gcc on unix
Labels clang
Assignees
Reporter m-lw
    Some uses of fastcall in the x86 abi no longer match what gcc has always generated on unix.  This changed in llvm 16 and is probably the result of the fix for #57737.  Possibly this fix should have only applied to MS Windows targets?

E.g. compiling this code with the -O option on FreeBSD 13.3 with clang version 19.0.0git (snapshot from 2024-05-10):
```
typedef union { long long l ; double d ; } res_val_union;
#define FASTCALL_ATTRIBUTE  __attribute__ ((fastcall))

static res_val_union fastcall_results_vector[100] ;

res_val_union* fastcall_type_results_5(void) { return fastcall_results_vector ;}

int FASTCALL_ATTRIBUTE  fastcall_ilc_5(long long arg_1, signed char arg_2)
{
  fastcall_results_vector[0].l = (long long)arg_1;
 fastcall_results_vector[1].l = (long long)arg_2;
  return 50;
}
```
gives this code:
```
fastcall_ilc_5: # @fastcall_ilc_5
	.cfi_startproc
# %bb.0: # %entry
	pushl	%ebp
	.cfi_def_cfa_offset 8
	.cfi_offset %ebp, -8
	movl	%esp, %ebp
	.cfi_def_cfa_register %ebp
	movl	8(%ebp), %eax
	movl	12(%ebp), %edx
	movl	%edx, fastcall_results_vector+4
	movl	%eax, fastcall_results_vector
	movsbl	%cl, %eax
	movl	%eax, fastcall_results_vector+8
	sarl	$31, %eax
	movl	%eax, fastcall_results_vector+12
	movl	$50, %eax
	popl	%ebp
	.cfi_def_cfa %esp, 4
	retl	$8
```
whereas in gcc version 15.0.0 20240630 (experimental) it gives:
```
fastcall_ilc_5:
	pushl	%ebp
	movl	%esp, %ebp
	movl	8(%ebp), %eax
	movl	12(%ebp), %edx
	movl	%eax, fastcall_results_vector
	movl	%edx, fastcall_results_vector+4
	movsbl	16(%ebp), %eax
	movl	%eax, fastcall_results_vector+8
	cltd
	movl	%edx, fastcall_results_vector+12
	movl	$50, %eax
	popl	%ebp
	ret	$12
```
Note that the second argument is in `%cl` in clang but is on the stack in gcc.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to