diff --git a/gcc/attribs.c b/gcc/attribs.c index 01a9ed66485..29703e75fba 100644 --- a/gcc/attribs.c +++ b/gcc/attribs.c @@ -605,7 +605,8 @@ decl_attributes (tree *node, tree attributes, int flags, } if (TREE_CODE (*node) == FUNCTION_DECL - && optimization_current_node != optimization_default_node + && (optimization_current_node != optimization_default_node + || target_option_current_node != target_option_default_node) && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node)) { DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node) = optimization_current_node; diff --git a/gcc/testsuite/g++.target/i386/pr103696.C b/gcc/testsuite/g++.target/i386/pr103696.C new file mode 100644 index 00000000000..de7d5c68be9 --- /dev/null +++ b/gcc/testsuite/g++.target/i386/pr103696.C @@ -0,0 +1,25 @@ +// PR c++/103696 +// { dg-options "-O2 -std=c++14 -fdump-tree-optimized" } + +int global_var; + +void fn() { +} + +#pragma GCC optimize("finite-math-only") +#pragma GCC target("sse3") + +void fn2() { +} + +void fn3() { +} + +int solve() { + auto nested = []() { + return global_var; + }; + return nested(); +} + +/* { dg-final { scan-tree-dump-not "lambda" "optimized" } } */