https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71585
--- Comment #4 from Martin Liška <marxin at gcc dot gnu.org> ---
Hello
The problem can be seen on both GCC 6.x and current trunk, where we show
following warning message:
pr71585.c:2:9: warning: bad option ‘-fno-stack-protector’ to pragma ‘optimize’
[-Wpragmas]
#pragma GCC optimize ("-fno-stack-protector")
^~~
pr71585.c:7:1: warning: bad option ‘-fno-stack-protector’ to attribute
‘optimize’ [-Wattributes]
{
^
The problem is that '-fstack-protect' is not marked as Optimize option.
Following patch fixed that:
diff --git a/gcc/common.opt b/gcc/common.opt
index 5d90385..a7c5125 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2221,19 +2221,19 @@ Common RejectNegative Joined
Var(common_deferred_options) Defer
-fstack-limit-symbol=<name> Trap if the stack goes past symbol <name>.
fstack-protector
-Common Report Var(flag_stack_protect, 1) Init(-1)
+Common Report Var(flag_stack_protect, 1) Init(-1) Optimization
Use propolice as a stack protection method.
fstack-protector-all
-Common Report RejectNegative Var(flag_stack_protect, 2) Init(-1)
+Common Report RejectNegative Var(flag_stack_protect, 2) Init(-1) Optimization
Use a stack protection method for every function.
fstack-protector-strong
-Common Report RejectNegative Var(flag_stack_protect, 3) Init(-1)
+Common Report RejectNegative Var(flag_stack_protect, 3) Init(-1) Optimization
Use a smart stack protection method for certain functions.
fstack-protector-explicit
-Common Report RejectNegative Var(flag_stack_protect, 4)
+Common Report RejectNegative Var(flag_stack_protect, 4) Optimization
Use stack protection method only for functions with the stack_protect
attribute.
The only question is whether we can add the flag to optimize flags? If so, I'll
send the patch to mailing list.
Btw. I've come to a misleading hint related to the option: PR69265 and
accidentally I hit also this: PR71652.
Another possible problem I can see is that some i386 target attributes are not
handled,
for instance:
pr71585.c:3:9: error: attribute(target("stack-protector-guard=tls")) is unknown
#pragma GCC target ("stack-protector-guard=tls")
^~~
Following hunk is necessary to enable the parsing:
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index f7944f9..73f2149 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -6458,6 +6458,7 @@ ix86_valid_target_attribute_inner_p (tree args, char
*p_strings[],
/* enum options */
IX86_ATTR_ENUM ("fpmath=", OPT_mfpmath_),
+ IX86_ATTR_ENUM ("stack-protector-guard=", OPT_mstack_protector_guard_),
/* string options */
IX86_ATTR_STR ("arch=", IX86_FUNCTION_SPECIFIC_ARCH),
I'll write a test-case for that.
Martin