This patch checks that an argument passed to either of the builtins __builtin_frame_address or __builtin_return_address is at least 0. This patch resolves the issue where these builtins would cause an infinite loop ( 25497 ).
We usually prefer to generate error messages for incorrect parameters to builtins in SemaChecking.cpp.
I don't think there's really an infinite loop here. The parameter to __builtin_frame_address is an unsigned integer; values greater than 0x7FFFFFFU aren't special. The reason it takes a very long time is that we try to unroll the implied loop; generating an object file with four billion load instructions takes essentially forever. We could impose a smaller limit, but it would be sort of arbitrary.
In the context of __builtin_frame_address, an arbitrary limit is probably okay. Maybe something like 0xFFFF, which is larger than anyone would realistically use, but doesn't take a crazy amount of time to compile.
I was using SemaBuiltinConstantArgRange incorrectly. I was returning an error for !SemaBuiltinConstantArgRange instead of SemaBuiltinConstantArgRange. Also, I only modified the fail tests so I wasn't able to catch the error. Updated and am running both the Sema and CodeGen tests now. Should fix the error.