http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57756
Bug ID: 57756 Summary: Function target attribute is retaining state of previously seen function Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: tmsriram at google dot com Simple repro: foo.cc: ------- __attribute__((always_inline,target("sse4.2"))) inline int callee () { return 0; } __attribute__((target("sse4.1"))) inline int caller () { return callee(); } int main () { return caller(); } $ g++ foo.cc callee is inlined into caller. This is incorrect, the callee's target ISA is higher and GCC must complain. Digging deeper, the x_ix86_isa_flags of both caller and callee are the same. The problem is in ix86_set_current_function in i386.c where else if (new_tree) { cl_target_option_restore (&global_options, TREE_TARGET_OPTION (new_tree)); target_reinit (); } where the restore, restores the previous decl's target options to global. It is not clear to me how to fix this. Replace the target attributes in the above source with the equivalent #pragma GCC push_options .... and the program will fail as expected.