[Bug tree-optimization/85509] fails to promote local static to const

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Apr 25 07:23:00 GMT 2018


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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to ASA from comment #3)
> (In reply to Richard Biener from comment #2)
> > The issue is you fail to make PerformQuickly and PerformSafely const and GCC
> > doesn't have local analysis to promote it so and IPA analysis is too late
> > for that since it is also the last inlining point.
> > 
> > Slight complication is nested functions and OMP outlining which may refer to
> > these variables.  But even the initial cgraph build should be able to figure
> > out the const-ness, no?
> > 
> > Workaround: make the vars const.
> 
> 
> I stated that const solves the issue in the description.  If the auto
> variables have automatic duration (remove the keyword static), the compiler
> is able to inline the invocation without the const qualifier.  As stated,
> LLVM (clang++) does inline the invocation even if it has static duration.
> 
> I would expect this is likely true for any non-const static duration
> function pointer, not just the case when the auto type specifier is used,
> but I have not confirmed it.

But it is the case for any non-const static duration function pointer.
This has nothing to do with 'auto', changing the testcase to

static inline bool
RunTest( void ) {
    static bool (*PerformQuickly)(int &, const int &) = Perform< SumQuickly >;
    static bool (*PerformSafely)(int &, const int &) = Perform< SumSafely >;
    int i = 0;
    return PerformQuickly( i, 1 ) && !PerformSafely( i, INT_MAX );
}

has no effect.


More information about the Gcc-bugs mailing list