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

            Bug ID: 114772
           Summary: pragma GCC target applied to earlier template function
                    with __attribute__((warn_unused_result))
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mjires at gcc dot gnu.org
                CC: jamborm at gcc dot gnu.org
  Target Milestone: ---

Following minimized testcase fails depending on warn_unused_result attribute.
Fails at least since GCC 10.

$ cat simdjson.cpp
template<typename V, bool STREAMING>
inline __attribute__((always_inline))
#ifdef FAIL
__attribute__((warn_unused_result))
#endif
int walk_document(V visitor) {return 0;}

template<bool STREAMING>
void parse_document() {
    int r = walk_document<bool, STREAMING>(false);
}

void stage2_next() {
    parse_document<true>();
}

#pragma GCC target("pclmul")



$ gcc simdjson.cpp -DFAIL
simdjson.cpp: In function ‘void parse_document() [with bool STREAMING = true]’:
simdjson.cpp:6:5: error: inlining failed in call to ‘always_inline’ ‘int
walk_document(V) [with V = bool; bool STREAMING = true]’: target specific
option mismatch
    6 | int walk_document(V visitor) {return 0;}
      |     ^~~~~~~~~~~~~
simdjson.cpp:10:43: note: called from here
   10 |     int r = walk_document<bool, STREAMING>(false);
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~



Without __attribute__((warn_unused_result)) it compiles without problems.

Inlining is denied in ix86_can_inline_p, because:
caller: void parse_document() [with bool STREAMING = true]/1
callee: int walk_document(V) [with V = bool; bool STREAMING = true]/2
caller_opts->x_ix86_isa_flags: 000c001100000012
callee_opts->x_ix86_isa_flags: 000c009100000012
So they differ by OPTION_MASK_ISA_PCLMUL

Source of this difference seems to be attribs.cc:decl_attributes, which is
called during template instantiation, but uses global_options.

Reply via email to