From: Richard Sandiford Date: Tue, 15 Jan 2019 16:46:54 +0000 (+0000) Subject: PR inline-asm/52813 revisited X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=99063eeecbfb15fece3c72747a9dd14077c41afd;p=gcc.git PR inline-asm/52813 revisited The original patch for this PR made it an error to list the stack pointer in the clobber list of an inline asm. However, the general feeling seemed to be that going straight to a hard error was too harsh, since there's quite a bit of existing code that has the clobber. This patch implements the compromise discussed on IRC of making it a -Wdeprecated warning instead. 2019-01-15 Richard Sandiford gcc/ PR inline-asm/52813 * doc/extend.texi: Document that listing the stack pointer in the clobber list of an asm is a deprecated feature. * common.opt (Wdeprecated): Moved from c-family/c.opt. * cfgexpand.c (asm_clobber_reg_is_valid): Issue a -Wdeprecated warning instead of an error for clobbers of the stack pointer. Add a note explaining why. gcc/c-family/ PR inline-asm/52813 * c.opt (Wdeprecated): Move documentation and variable to common.opt. gcc/d/ PR inline-asm/52813 * lang.opt (Wdeprecated): Reference common.opt instead of c.opt. gcc/testsuite/ PR inline-asm/52813 * gcc.target/i386/pr52813.c (test1): Turn the diagnostic into a -Wdeprecated warning and expect a following note:. From-SVN: r267941 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c3b9f14de52..83d4fa4af0c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2019-01-15 Richard Sandiford + + PR inline-asm/52813 + * doc/extend.texi: Document that listing the stack pointer in the + clobber list of an asm is a deprecated feature. + * common.opt (Wdeprecated): Moved from c-family/c.opt. + * cfgexpand.c (asm_clobber_reg_is_valid): Issue a -Wdeprecated + warning instead of an error for clobbers of the stack pointer. + Add a note explaining why. + 2019-01-15 Richard Biener PR debug/88046 diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 10e5cc131e9..03ea65b4bce 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2019-01-15 Richard Sandiford + + PR inline-asm/52813 + * c.opt (Wdeprecated): Move documentation and variable to common.opt. + 2019-01-14 Jakub Jelinek * c-cppbuiltin.c (c_cpp_builtin): Define __cpp_guaranteed_copy_elision diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 858beff53d6..88c72c51c21 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -477,8 +477,8 @@ C++ ObjC++ Var(warn_delnonvdtor) Warning LangEnabledBy(C++ ObjC++,Wall || Weffc+ Warn about deleting polymorphic objects with non-virtual destructors. Wdeprecated -C C++ ObjC ObjC++ CPP(cpp_warn_deprecated) CppReason(CPP_W_DEPRECATED) Var(warn_deprecated) Init(1) Warning -Warn if a deprecated compiler feature, class, method, or field is used. +C C++ ObjC ObjC++ CPP(cpp_warn_deprecated) CppReason(CPP_W_DEPRECATED) +; Documented in common.opt Wdeprecated-copy C++ ObjC++ Var(warn_deprecated_copy) Warning LangEnabledBy(C++ ObjC++, Wextra) diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 3b7a6e59c3b..2337c6312d0 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -2872,12 +2872,16 @@ asm_clobber_reg_is_valid (int regno, int nregs, const char *regname) error ("PIC register clobbered by %qs in %", regname); is_valid = false; } - /* Clobbering the STACK POINTER register is an error. */ - if (overlaps_hard_reg_set_p (regset, Pmode, STACK_POINTER_REGNUM)) - { - error ("Stack Pointer register clobbered by %qs in %", regname); - is_valid = false; - } + /* Clobbering the stack pointer register is deprecated. GCC expects + the value of the stack pointer after an asm statement to be the same + as it was before, so no asm can validly clobber the stack pointer in + the usual sense. Adding the stack pointer to the clobber list has + traditionally had some undocumented and somewhat obscure side-effects. */ + if (overlaps_hard_reg_set_p (regset, Pmode, STACK_POINTER_REGNUM) + && warning (OPT_Wdeprecated, "listing the stack pointer register" + " %qs in a clobber list is deprecated", regname)) + inform (input_location, "the value of the stack pointer after an %" + " statement must be the same as it was before the statement"); return is_valid; } diff --git a/gcc/common.opt b/gcc/common.opt index 035f2ba7dec..9a5e9af06ca 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -579,6 +579,10 @@ Wattribute-warning Common Var(warn_attribute_warning) Init(1) Warning Warn about uses of __attribute__((warning)) declarations. +Wdeprecated +Common Var(warn_deprecated) Init(1) Warning +Warn if a deprecated compiler feature, class, method, or field is used. + Wdeprecated-declarations Common Var(warn_deprecated_decl) Init(1) Warning Warn about uses of __attribute__((deprecated)) declarations. diff --git a/gcc/d/ChangeLog b/gcc/d/ChangeLog index 6fa01f57897..974b0982268 100644 --- a/gcc/d/ChangeLog +++ b/gcc/d/ChangeLog @@ -1,3 +1,8 @@ +2019-01-15 Richard Sandiford + + PR inline-asm/52813 + * lang.opt (Wdeprecated): Reference common.opt instead of c.opt. + 2019-01-12 Iain Buclaw * README.gcc: New file. diff --git a/gcc/d/lang.opt b/gcc/d/lang.opt index 52ddd77f2ca..83d3d21a1a6 100644 --- a/gcc/d/lang.opt +++ b/gcc/d/lang.opt @@ -124,7 +124,7 @@ Warn about casts that will produce a null result. Wdeprecated D -; Documented in C +; Documented in common.opt Werror D diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index c81092dfe0c..eb1cde492c8 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -9441,6 +9441,15 @@ When the compiler selects which registers to use to represent input and output operands, it does not use any of the clobbered registers. As a result, clobbered registers are available for any use in the assembler code. +Another restriction is that the clobber list should not contain the +stack pointer register. This is because the compiler requires the +value of the stack pointer to be the same after an @code{asm} +statement as it was on entry to the statement. However, previous +versions of GCC did not enforce this rule and allowed the stack +pointer to appear in the list, with unclear semantics. This behavior +is deprecated and listing the stack pointer may become an error in +future versions of GCC@. + Here is a realistic example for the VAX showing the use of clobbered registers: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1b0689d5ea2..e4fbb15dfef 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-01-15 Richard Sandiford + + PR inline-asm/52813 + * gcc.target/i386/pr52813.c (test1): Turn the diagnostic into a + -Wdeprecated warning and expect a following note:. + 2019-01-15 Richard Biener PR debug/88046 diff --git a/gcc/testsuite/gcc.target/i386/pr52813.c b/gcc/testsuite/gcc.target/i386/pr52813.c index 154ebbfc423..8772cfb0aee 100644 --- a/gcc/testsuite/gcc.target/i386/pr52813.c +++ b/gcc/testsuite/gcc.target/i386/pr52813.c @@ -5,5 +5,6 @@ void test1 (void) { - asm volatile ("" : : : "%esp"); /* { dg-error "Stack Pointer register clobbered" } */ + asm volatile ("" : : : "%esp"); /* { dg-warning "listing the stack pointer register '%esp' in a clobber list is deprecated" } */ + /* { dg-message "note: the value of the stack pointer after an 'asm' statement must be the same as it was before the statement" "" { target *-*-* } .-1 } */ }