15.4.6 Stack Example

For this simple example:

test.c

int max(int a, int b){
        if (a < b)
               return b;
        return a;
}
 
int main() {
        int a[10], i, j;
 
        for (i =0; i < 10; i++)
               a[i] = i;
        for (i = 0; i < 10; i++)
               a[i] = max(a[i], a[10-i/2]);
        return a[0];
}

when built with

xc32-gcc -mprocessor=ATSAMD51N20A -mchp-stack-usage -O0 test.c

the stack-usage report shows

Stack Usage Report

============= STACK USAGE GUIDANCE =============
In the call graph beginning at Reset_Handler,
	72 bytes of stack are required.

However, the following cautions exists:

1. Indeterminate stack adjustment has been detected:
	_init uses 24 bytes
	_fini uses 24 bytes
No stack usage predictions can be made.

2. The following functions cannot be connected to the main call graph.
This is usually caused by some indirection:
	_init uses 24 bytes
	_fini uses 24 bytes
	__do_global_dtors_aux uses 8 bytes
	frame_dummy uses 8 bytes
	Dummy_Handler uses 0 bytes
You must add stack allowances for those functions.
================================================