[Bug c/93047] New: frename-registers does not work well with __builtin_return

guojiufu at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Dec 23 08:18:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93047

            Bug ID: 93047
           Summary: frename-registers does not work well with
                    __builtin_return
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: guojiufu at gcc dot gnu.org
  Target Milestone: ---

There is a case builtin-return-1.c which is checking __builtin_return and
__builtin_apply. Which this case fail with -frename-registers. 
It seems rnreg rename a register to 'return register' after function call.

gcc $GCC_SRC/gcc/testsuite/gcc.dg/torture/stackalign/builtin-return-1.c -O3
-frename-registers -o ./builtin-return-1.exe

./builtin-return-1.exe
Aborted (core dumped)

[Tested on powerpc64le.]

Dump asm code, there is code like:

        bl foo
        addi 3,31,128 #this line is using r3 which should be return reg of
previous call foo
        addi 12,31,304
        addi 10,31,336
        addi 6,31,352
        xxpermdi 0,1,1,2
        xxpermdi 9,35,35,2
        std 3,96(31) #here r3 (return value of foo) is saved

Without -frename-registers
        bl foo
        addi 0,31,128
        addi 11,31,240
        addi 4,31,256
        addi 5,31,272
        std 3,96(31) #here
        xxpermdi 1,1,1,2
        xxpermdi 2,2,2,2

rnreg should not rename r0 for instruction "addi 0,31,128" to r3.
r3 should not be used as 'rename source register' after "bl xx" untill "std
3,..."

source code:
#ifdef __MMIX__
/* No parameters on stack for bar.  */
#define STACK_ARGUMENTS_SIZE 0
#else
#define STACK_ARGUMENTS_SIZE 64
#endif

extern void abort(void);

int foo(int n)
{
  return n+1;
}

int bar(int n)
{
  __builtin_return(__builtin_apply((void (*)(void))foo, __builtin_apply_args(),
                                   STACK_ARGUMENTS_SIZE));
}

int main(void)
{
  /* Allocate 64 bytes on the stack to make sure that __builtin_apply           
     can read at least 64 bytes above the return address.  */
  char dummy[64];

  __asm__ ("" : : "" (dummy));

  if (bar(1) != 2)
    abort();

  return 0;
}


More information about the Gcc-bugs mailing list