https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69971
Bug ID: 69971 Summary: repetitive code with __builtin_return_address with a large level Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- Calling __builtin_return_address with a large argument (say due to a coding bug obscured by macros or template arguments) can result in resource exhaustion by the compiler as it emits at least one instruction for each level. It seems that for levels greater some threshold GCC could emit a loop instead to avoid this problem (as unlikely as it may be). The following is an example run on powerpc64le where GCC emits a stream of ld 9,0(9) instructions, one for each level: $ cat t.c && /build/gcc-trunk/gcc/xgcc -B /build/gcc-trunk/gcc -S -Wall -Wextra -Wpedantic -o/dev/stdout t.c | grep "ld 9" | wc -l void* foo (void) { void *p = __builtin_return_address (1024); return p; } t.c: In function ‘foo’: t.c:3:11: warning: calling ‘__builtin_return_address’ with a nonzero argument is unsafe [-Wframe-address] void *p = __builtin_return_address (1024); ^ 1027