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

            Bug ID: 93540
           Summary: Attributes pure and const not working with aggregate
                    return types, even trivial ones
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pskocik at gmail dot com
  Target Milestone: ---

Example:

#define SIMPLE 0
#include <stdlib.h>
#if SIMPLE
    typedef int TYPE;
#else
    typedef struct TYPE { int a; } TYPE;
#endif

//__attribute((pure))
__attribute((const))
TYPE get(void);

void TEST(void)
{
    #if !SIMPLE  // :( generates repeated calls
    if(get().a==0) abort();
    if(get().a==0) abort();
    if(get().a==0) abort();
    if(get().a==0) abort();
    #else  //OK, 1 call
    if(get()==0) abort();
    if(get()==0) abort();
    if(get()==0) abort();
    if(get()==0) abort();
    #endif
}
///////////////////////////////////

https://gcc.godbolt.org/z/N79MCx

Reply via email to