This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/26724] New: __builtin_constant_p fails to recognise function with constant return


We noticed that __builtin_constant_p() sometimes fails to recognise a function
that always returns 0 as being constant.

The code snippet below shows that gcc can work it out if we force the
evaluation into an inline function. It looks like this postpones the evaluation
of __builtin_constant_p to a later stage when we know the function always
returns 0.

static inline int baz(void)
{
        return 0;
}

void inline foo(int A)
{
        if (!__builtin_constant_p(A))
                FAIL();
}

void good()
{
        foo(baz());
}

void bad()
{
        if (!__builtin_constant_p(baz()))
                FAIL();
}


-- 
           Summary: __builtin_constant_p fails to recognise function with
                    constant return
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: anton at samba dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26724


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]