On 2/18/19 4:12 PM, Joseph Myers wrote:
On Sat, 16 Feb 2019, Jakub Jelinek wrote:
Hi!
Both the C and C++ standard guarantee that the argc argument to main is
non-negative, the following patch sets (or adjusts) the corresponding
SSA_NAME_RANGE_INFO. While main is just one, with IPA VRP it can also
propagate etc. I had to change one testcase because it started optimizing
it better (the test has been folded away), so no sinking was done.
In C, unlike in C++, it's valid to call main recursively. I think the
requirements on argc and argv must be understood to apply only to their
values on entry to the initial call to main, not to any recursive calls.
What do you base that interpretation on? The C constraints aren't
qualified as applying only to the initial call. The text simply
says that
If they are declared, the parameters to the main function shall
obey the following constraints:
-- The value of argc shall be nonnegative.
-- argv[argc] shall be a null pointer.
Sure, the text is in a section named Program startup, but that doesn't
imply that the constraints apply only at program startup. If they did,
there would be no constraints on the parameters in any other calls to
main, which would make the parameters unusable in general (because
there is no way for main to tell if it's the fist invocation).
Martin
So I don't think this optimization is valid for C (in the absence of
whole-program information that can prove the absence of any recursive
calls).