https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93491

Alexander Monakov <amonakov at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW
                 CC|                            |amonakov at gcc dot gnu.org

--- Comment #4 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
(In reply to Alexander Cherepanov from comment #2)
> > Do you have a testcase were gcc does this optimize without the user adding
> > const and still traps?
> 
> No. I'll file a separate bug if I stumble upon one, so please disregard this
> possibility for now.

GCC will deduce that g is const just fine, it even tells you so with
-Wsuggest-attribute=const

__attribute__((noipa))
void f(int i)
{
    __builtin_exit(i);
}

__attribute__((noinline))
int g(int i)
{
    return 1 / i;
}

int main()
{
    while (1) {
        f(0);

        f(g(0));
    }
}

Thus removing WAITING and confirming.

Reply via email to