https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108919
Bug ID: 108919 Summary: pure nested function may clobber its static chain pointer in windowed ABI on xtensa Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: jcmvbkbc at gcc dot gnu.org Target Milestone: --- Created attachment 54525 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54525&action=edit test.c The following gfortran tests fail on windowed ABI xtensa target, but pass on call0 ABI: gfortran.dg/character_workout_1.f90 -O[123s] execution test gfortran.dg/character_workout_4.f90 -O[123s] execution test E.g. gfortran.dg/character_workout_1.f90 -O1 ends with the message 'STOP 209'. This happens because in these tests pure nested functions are generated for subroutines achar_cm and achar_am and the fwprop1 pass removes static chain pointer initialization between the calls to these functions: .L143: addi a3, sp, 108 movi a4, 0xd4 add.n a4, sp, a4 addi a8, sp, -20 s32i.n a4, a8, 0 movi.n a11, 7 mov.n a10, a3 call8 achar_cm.21 movi.n a11, 7 mov.n a10, a3 call8 achar_am.15 Windowed ABI for xtensa specifies that the static chain is passed on the stack, at offset -20 from the called function's CFA, i.e. outside the caller's stack frame. This location may be overwritten if the called function makes function calls that exceed certain depth. The issue may be reproduced with the attached small test case.