[Bug ipa/105682] [12/13 Regression] Both `-Wsuggest-attribute=pure` and `-Wsuggest-attribute=const` on same function since r12-5177-g494bdadf28d0fb35

hubicka at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Jul 18 09:53:22 GMT 2022


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

--- Comment #6 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
gcc-12.1.0 (bogus warning: `caller()` has no right to be const; it calls a pure
function, and that function even contains inline assembly):

I think the conlcusion here is correct.  callee has pure attribute and that
means that it has no side effects except for reading global memory. So whatever
volatile assembly does has to satisfy this.

Now since assembly is not declared as reading memory, GCC concludes that the
function has no side effects and does not read global memory and this can be
uprgraded to const.

Now as optimization goes we first realize that function is pure and only later
realize that it is also const. This could have happened with older GCC versions
as well. This triggers the duplicated warning on older compilers as well with 
-Wsuggest-attribute=pure -Wsuggest-attribute=const -O2 -fno-early-inlining
:

__attribute__ ((pure)) int q(int);
__attribute__ ((pure)) int t(int a)
{
        if (a)
                return q(2);
}
__attribute__ ((pure)) int q(int a)
{
        if (!a)
                return t(1);
}
int a;
int
test()
{
        return t(a);
}

 I guess if we want to avoid such warnings we need to hold all the information
until the end of late ltrans optimization.


More information about the Gcc-bugs mailing list