[PATCH 5/5] x86/CET: Remove the -mcet command-lint option

2018-04-22 Thread H.J. Lu
With revision 259496:

commit b1384095a7c1d06a44b70853372ebe037b2f7867
Author: hjl 
Date:   Thu Apr 19 15:15:04 2018 +

x86: Enable -fcf-protection with multi-byte NOPs

-fcf-protection no longer depens on -mcet and with revision 259522:

commit d59cfa9a4064339cf2bd2da828c4c133f13e57f0
Author: hjl 
Date:   Fri Apr 20 13:30:13 2018 +

Define __CET__ for -fcf-protection and remove -mibt

-mcet becomes an alias for -mshstk.  Since all usages of -mcet and
-mno-cet have either been removed or replaced, we can remove the -mcet
command-lint option.

PR target/85485
* common/config/i386/i386-common.c (ix86_handle_option): Don't
handle OPT_mcet.
* config/i386/i386.opt (mcet): Removed.
* doc/install.texi: Remove -mcet documentation.
* doc/invoke.texi: Likewise.
---
 gcc/common/config/i386/i386-common.c |  1 -
 gcc/config/i386/i386.opt |  5 -
 gcc/doc/install.texi |  2 +-
 gcc/doc/invoke.texi  | 10 ++
 4 files changed, 3 insertions(+), 15 deletions(-)

diff --git a/gcc/common/config/i386/i386-common.c 
b/gcc/common/config/i386/i386-common.c
index 74a3490f7a3..2629ae62a28 100644
--- a/gcc/common/config/i386/i386-common.c
+++ b/gcc/common/config/i386/i386-common.c
@@ -543,7 +543,6 @@ ix86_handle_option (struct gcc_options *opts,
}
   return true;
 
-case OPT_mcet:
 case OPT_mshstk:
   if (value)
{
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index 815eceb713d..d9bd909a885 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -1006,11 +1006,6 @@ mgeneral-regs-only
 Target Report RejectNegative Mask(GENERAL_REGS_ONLY) Var(ix86_target_flags) 
Save
 Generate code which uses only the general registers.
 
-mcet
-Target Report Var(flag_cet) Init(0)
-Enable shadow stack built-in functions from Control-flow Enforcement
-Technology (CET).
-
 mshstk
 Target Report Mask(ISA_SHSTK) Var(ix86_isa_flags) Save
 Enable shadow stack built-in functions from Control-flow Enforcement
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 511e146f023..2f4f608e268 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -2107,7 +2107,7 @@ The option is disabled by default.  When 
@code{--enable-cet=auto}
 is used, it is enabled on Linux/x86 if target binutils
 supports @code{Intel CET} instructions and disabled otherwise.
 In this case the target libraries are configured to get additional
-@option{-fcf-protection} and @option{-mcet} options.
+@option{-fcf-protection} option.
 @end table
 
 @subheading Cross-Compiler-Specific Options
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index b6784b75fa2..9c7fe187f48 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1261,7 +1261,7 @@ See RS/6000 and PowerPC Options.
 -msse4a  -m3dnow  -m3dnowa  -mpopcnt  -mabm  -mbmi  -mtbm  -mfma4  -mxop @gol
 -mlzcnt  -mbmi2  -mfxsr  -mxsave  -mxsaveopt  -mrtm  -mlwp  -mmpx  @gol
 -mmwaitx  -mclzero  -mpku  -mthreads -mgfni  -mvaes  @gol
--mcet -mshstk -mforce-indirect-call -mavx512vbmi2 @gol
+-mshstk -mforce-indirect-call -mavx512vbmi2 @gol
 -mvpclmulqdq -mavx512bitalg -mmovdiri -mmovdir64b -mavx512vpopcntdq @gol
 -mms-bitfields  -mno-align-stringops  -minline-all-stringops @gol
 -minline-stringops-dynamically  -mstringop-strategy=@var{alg} @gol
@@ -27300,9 +27300,6 @@ preferred alignment to 
@option{-mpreferred-stack-boundary=2}.
 @itemx -mpku
 @opindex mpku
 @need 200
-@itemx -mcet
-@opindex mcet
-@need 200
 @itemx -mavx512vbmi2
 @opindex mavx512vbmi2
 @need 200
@@ -27447,12 +27444,9 @@ This option enables use of the @code{movbe} 
instruction to implement
 @code{__builtin_bswap32} and @code{__builtin_bswap64}.
 
 @item -mshstk
-@itemx -mcet
 @opindex mshstk
-@opindex mcet
 The @option{-mshstk} option enables shadow stack built-in functions
-from x86 Control-flow Enforcement Technology (CET).  The @option{-mcet}
-option is an alias for the @option{-mshstk} option.
+from x86 Control-flow Enforcement Technology (CET).
 
 @item -mcrc32
 @opindex mcrc32
-- 
2.14.3



[PATCH 2/5] Regenerate configure of target libraries

2018-04-22 Thread H.J. Lu
* configure: Regenerated.
---
 libatomic/configure| 2 +-
 libbacktrace/configure | 2 +-
 libgcc/configure   | 2 +-
 libgfortran/configure  | 2 +-
 libgomp/configure  | 2 +-
 libitm/configure   | 2 +-
 libmpx/configure   | 2 +-
 libobjc/configure  | 2 +-
 libquadmath/configure  | 2 +-
 libsanitizer/configure | 2 +-
 libssp/configure   | 2 +-
 libstdc++-v3/configure | 2 +-
 libvtv/configure   | 2 +-
 13 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/libatomic/configure b/libatomic/configure
index 67a2c9269a3..b902e2c9606 100755
--- a/libatomic/configure
+++ b/libatomic/configure
@@ -15373,7 +15373,7 @@ rm -f core conftest.err conftest.$ac_objext 
conftest.$ac_ext
 ;;
 esac
 if test x$enable_cet = xyes; then
-  CET_FLAGS="-fcf-protection -mcet"
+  CET_FLAGS="-fcf-protection -mshstk"
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 else
diff --git a/libbacktrace/configure b/libbacktrace/configure
index b1e3adedda0..87cadda6c8c 100755
--- a/libbacktrace/configure
+++ b/libbacktrace/configure
@@ -11861,7 +11861,7 @@ rm -f core conftest.err conftest.$ac_objext 
conftest.$ac_ext
 ;;
 esac
 if test x$enable_cet = xyes; then
-  CET_FLAGS="-fcf-protection -mcet"
+  CET_FLAGS="-fcf-protection -mshstk"
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 else
diff --git a/libgcc/configure b/libgcc/configure
index fa024134668..b2f3f870844 100644
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -4849,7 +4849,7 @@ rm -f core conftest.err conftest.$ac_objext 
conftest.$ac_ext
 ;;
 esac
 if test x$enable_cet = xyes; then
-  CET_FLAGS="-fcf-protection -mcet"
+  CET_FLAGS="-fcf-protection -mshstk"
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 else
diff --git a/libgfortran/configure b/libgfortran/configure
index d3e323c11a7..91fce8fecd0 100755
--- a/libgfortran/configure
+++ b/libgfortran/configure
@@ -5863,7 +5863,7 @@ rm -f core conftest.err conftest.$ac_objext 
conftest.$ac_ext
 ;;
 esac
 if test x$enable_cet = xyes; then
-  CET_FLAGS="-fcf-protection -mcet"
+  CET_FLAGS="-fcf-protection -mshstk"
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 else
diff --git a/libgomp/configure b/libgomp/configure
index 5d8412c5f19..ced7606b355 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -16692,7 +16692,7 @@ rm -f core conftest.err conftest.$ac_objext 
conftest.$ac_ext
 ;;
 esac
 if test x$enable_cet = xyes; then
-  CET_FLAGS="-fcf-protection -mcet"
+  CET_FLAGS="-fcf-protection -mshstk"
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 else
diff --git a/libitm/configure b/libitm/configure
index 10db435d01c..dbf386db434 100644
--- a/libitm/configure
+++ b/libitm/configure
@@ -17662,7 +17662,7 @@ rm -f core conftest.err conftest.$ac_objext 
conftest.$ac_ext
 ;;
 esac
 if test x$enable_cet = xyes; then
-  CET_FLAGS="-fcf-protection -mcet"
+  CET_FLAGS="-fcf-protection -mshstk"
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 else
diff --git a/libmpx/configure b/libmpx/configure
index 5a4d7f49e0e..70856596425 100644
--- a/libmpx/configure
+++ b/libmpx/configure
@@ -11657,7 +11657,7 @@ rm -f core conftest.err conftest.$ac_objext 
conftest.$ac_ext
 ;;
 esac
 if test x$enable_cet = xyes; then
-  CET_FLAGS="-fcf-protection -mcet"
+  CET_FLAGS="-fcf-protection -mshstk"
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 else
diff --git a/libobjc/configure b/libobjc/configure
index 699f3773a21..d1a032fbf6a 100755
--- a/libobjc/configure
+++ b/libobjc/configure
@@ -3428,7 +3428,7 @@ rm -f core conftest.err conftest.$ac_objext 
conftest.$ac_ext
 ;;
 esac
 if test x$enable_cet = xyes; then
-  CET_FLAGS="-fcf-protection -mcet"
+  CET_FLAGS="-fcf-protection -mshstk"
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 else
diff --git a/libquadmath/configure b/libquadmath/configure
index 4ad6e3d682b..14610d66238 100755
--- a/libquadmath/configure
+++ b/libquadmath/configure
@@ -12896,7 +12896,7 @@ rm -f core conftest.err conftest.$ac_objext 
conftest.$ac_ext
 ;;
 esac
 if test x$enable_cet = xyes; then
-  CET_FLAGS="-fcf-protection -mcet"
+  CET_FLAGS="-fcf-protection -mshstk"
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 else
diff --git a/libsanitizer/configure b/libsanitizer/configure
index 5fdc5126478..4695bc7d4f7 100755
--- a/libsanitizer/configure
+++ b/libsanitizer/configure
@@ -16598,7 +16598,7 @@ rm -f core conftest.err conftest.$ac_objext 
conftest.$ac_ext
 ;;
 esac
 if test x$enable_cet = xyes; then
-  CET_FLAGS="-fcf-protection -mcet"
+  CET_FLAGS="-fcf-protection -mshstk"
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 else
diff --git a/libssp/configure b/libssp/configure
index f60b7d7

[PATCH 1/5] x86/CET: Build target libraries with -mshstk

2018-04-22 Thread H.J. Lu
With revision 259522:

commit d59cfa9a4064339cf2bd2da828c4c133f13e57f0
Author: hjl 
Date:   Fri Apr 20 13:30:13 2018 +

Define __CET__ for -fcf-protection and remove -mibt

-mcet becomes an alias for -mshstk.

PR target/85485
* cet.m4 (GCC_CET_FLAGS): Replace -mcet with -mshstk.
---
 config/cet.m4 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/config/cet.m4 b/config/cet.m4
index 04a0e05d2ff..b53c1bbd5cd 100644
--- a/config/cet.m4
+++ b/config/cet.m4
@@ -42,7 +42,7 @@ asm ("setssbsy");
 ;;
 esac
 if test x$enable_cet = xyes; then
-  $1="-fcf-protection -mcet"
+  $1="-fcf-protection -mshstk"
   AC_MSG_RESULT([yes])
 else
   AC_MSG_RESULT([no])
-- 
2.14.3



[PATCH 3/5] Don't bootstrap GCC with -mcet

2018-04-22 Thread H.J. Lu
With revision 259496:

commit b1384095a7c1d06a44b70853372ebe037b2f7867
Author: hjl 
Date:   Thu Apr 19 15:15:04 2018 +

x86: Enable -fcf-protection with multi-byte NOPs

-fcf-protection no longer requires -mcet.

config/

PR target/85485
* bootstrap-cet.mk (STAGE2_CFLAGS): Remove -mcet.
(STAGE3_CFLAGS): Likewise.

gcc/

PR target/85485
* doc/install.texi: Remove -mcet from bootstrap-cet.
---
 config/bootstrap-cet.mk | 6 +++---
 gcc/doc/install.texi| 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/config/bootstrap-cet.mk b/config/bootstrap-cet.mk
index f09193a6dea..b5dee601a3f 100644
--- a/config/bootstrap-cet.mk
+++ b/config/bootstrap-cet.mk
@@ -1,4 +1,4 @@
-# This option enables -fcf-protection -mcet for stage2 and stage3.
+# This option enables -fcf-protection for stage2 and stage3.
 
-STAGE2_CFLAGS += -fcf-protection -mcet
-STAGE3_CFLAGS += -fcf-protection -mcet
+STAGE2_CFLAGS += -fcf-protection
+STAGE3_CFLAGS += -fcf-protection
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 73030a2281a..511e146f023 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -2519,7 +2519,7 @@ must be used along with @code{bootstrap-debug-lean} and
 @item @samp{bootstrap-cet}
 This option enables Intel CET for host tools during bootstrapping.
 @samp{BUILD_CONFIG=bootstrap-cet} is equivalent to adding
-@option{-fcf-protection -mcet} to @samp{BOOT_CFLAGS}.  This option
+@option{-fcf-protection} to @samp{BOOT_CFLAGS}.  This option
 assumes that the host supports Intel CET (e.g. GNU assembler version
 2.30 or later).
 
-- 
2.14.3



[PATCH 4/5] x86/CET tests: Remove -mcet/-mno-cet or replace -mcet with -mshstk

2018-04-22 Thread H.J. Lu
With revision 259496:

commit b1384095a7c1d06a44b70853372ebe037b2f7867
Author: hjl 
Date:   Thu Apr 19 15:15:04 2018 +

x86: Enable -fcf-protection with multi-byte NOPs

-fcf-protection no longer depens on -mcet and with revision 259522:

commit d59cfa9a4064339cf2bd2da828c4c133f13e57f0
Author: hjl 
Date:   Fri Apr 20 13:30:13 2018 +

Define __CET__ for -fcf-protection and remove -mibt

-mcet becomes an alias for -mshstk.

We can remove -mcet/-mno-cet where they are unused and replace -mcet
with -mshstk where -mcet is used as an alias for -mshstk.

PR target/85485
* g++.dg/cet-notrack-1.C (dg-options): Remove -mcet.
* g++.dg/torture/pr85334.C (dg-additional-options): Likwise.
* gcc.dg/pr85388-1.c (dg-options): Likwise.
* gcc.dg/pr85388-2.c (dg-options): Likwise.
* gcc.dg/pr85388-3.c (dg-options): Likwise.
* gcc.dg/pr85388-4.c (dg-options): Likwise.
* gcc.dg/pr85388-5.c (dg-options): Likwise.
* gcc.dg/pr85388-6.c (dg-options): Likwise.
* gcc.dg/torture/pr85397-1.c (dg-additional-options): Likwise.
* gcc.target/i386/attr-nocf-check-1a.c (dg-options): Likwise.
* gcc.target/i386/attr-nocf-check-3a.c (dg-options): Likwise.
* gcc.target/i386/cet-label.c (dg-options): Likwise.
* gcc.target/i386/cet-label-2.c (dg-options): Likwise.
* gcc.target/i386/cet-notrack-1b.c (dg-options): Likwise.
* gcc.target/i386/cet-notrack-2a.c (dg-options): Likwise.
* gcc.target/i386/cet-notrack-2b.c (dg-options): Likwise.
* gcc.target/i386/cet-notrack-3.c (dg-options): Likwise.
* gcc.target/i386/cet-notrack-4b.c (dg-options): Likwise.
* gcc.target/i386/cet-notrack-5a.c (dg-options): Likwise.
* gcc.target/i386/cet-notrack-5b.c (dg-options): Likwise.
* gcc.target/i386/cet-notrack-6a.c (dg-options): Likwise.
* gcc.target/i386/cet-notrack-6b.c (dg-options): Likwise.
* gcc.target/i386/cet-notrack-7.c (dg-options): Likwise.
* gcc.target/i386/cet-notrack-icf-2.c (dg-options): Likwise.
* gcc.target/i386/cet-notrack-icf-4.c (dg-options): Likwise.
* gcc.target/i386/cet-property-1.c (dg-options): Likwise.
* gcc.target/i386/cet-property-2.c (dg-options): Likwise.
* gcc.target/i386/cet-sjlj-1.c (dg-options): Likwise.
* gcc.target/i386/cet-sjlj-2.c (dg-options): Likwise.
* gcc.target/i386/cet-sjlj-3.c (dg-options): Likwise.
* gcc.target/i386/cet-sjlj-4.c (dg-options): Likwise.
* gcc.target/i386/cet-sjlj-5.c (dg-options): Likwise.
* gcc.target/i386/cet-sjlj-6a.c (dg-options): Likwise.
* gcc.target/i386/cet-sjlj-6b.c (dg-options): Likwise.
* gcc.target/i386/cet-switch-1.c (dg-options): Likwise.
* gcc.target/i386/cet-switch-2.c (dg-options): Likwise.
* gcc.target/i386/cet-switch-3.c (dg-options): Likwise.
* gcc.target/i386/indirect-thunk-11.c (dg-options): Likwise.
* gcc.target/i386/indirect-thunk-12.c (dg-options): Likwise.
* gcc.target/i386/indirect-thunk-attr-12.c (dg-options): Likwise.
* gcc.target/i386/indirect-thunk-attr-13.c (dg-options): Likwise.
* gcc.target/i386/indirect-thunk-attr-14.c (dg-options): Likwise.
* gcc.target/i386/indirect-thunk-attr-15.c (dg-options): Likwise.
* gcc.target/i386/indirect-thunk-attr-16.c (dg-options): Likwise.
* gcc.target/i386/indirect-thunk-extern-8.c (dg-options): Likwise.
* gcc.target/i386/indirect-thunk-extern-9.c (dg-options): Likwise.
* gcc.target/i386/indirect-thunk-extern-10.c (dg-options): Likwise.
* gcc.target/i386/pr82659-1.c (dg-options): Likwise.
* gcc.target/i386/pr82659-2.c (dg-options): Likwise.
* gcc.target/i386/pr82659-3.c (dg-options): Likwise.
* gcc.target/i386/pr82659-4.c (dg-options): Likwise.
* gcc.target/i386/pr82659-5.c (dg-options): Likwise.
* gcc.target/i386/pr82659-6.c (dg-options): Likwise.
* gcc.target/i386/pr84146.c (dg-options): Likwise.
* gcc.target/i386/pr85345.c (dg-options): Likwise.
* gcc.target/i386/pr85403.c (dg-options): Likwise.
* gcc.target/i386/pr85404.c (dg-options): Likwise.
* gcc.target/i386/cet-intrin-3.c (dg-options): Replace -mcet
with -mshstk.
* gcc.target/i386/cet-intrin-5.c (dg-options): Likwise.
* gcc.target/i386/cet-intrin-6.c (dg-options): Likwise.
* gcc.target/i386/cet-intrin-7.c (dg-options): Likwise.
* gcc.target/i386/cet-intrin-8.c (dg-options): Likwise.
* gcc.target/i386/cet-intrin-9.c (dg-options): Likwise.
* gcc.target/i386/cet-intrin-10.c (dg-options): Likwise.
* gcc.target/i386/cet-rdssp-1.c (dg-options): Likwise.
* (dg-options): Likwise.
* gcc.target/i386/cet-notrack-1a.c (dg-options): Remove
-mno-cet.
* gcc.target/i386/cet-notrack-4a.c (dg-options): Likwise.
* gcc.ta

[PATCH 0/5] x86/CET: Remove the -mcet command-lint option

2018-04-22 Thread H.J. Lu
With revision 259496:

commit b1384095a7c1d06a44b70853372ebe037b2f7867
Author: hjl 
Date:   Thu Apr 19 15:15:04 2018 +

x86: Enable -fcf-protection with multi-byte NOPs

-fcf-protection no longer depens on -mcet and with revision 259522:

commit d59cfa9a4064339cf2bd2da828c4c133f13e57f0
Author: hjl 
Date:   Fri Apr 20 13:30:13 2018 +

Define __CET__ for -fcf-protection and remove -mibt

-mcet becomes an alias for -mshstk.

To enable shadow stack protection in a program, -fcf-protection=return
must be used to compile the program.  -mcet/-mshstk are used to enable
shadow stack intrinsics to IMPLEMENT shadow stack, not to ENABLE shadow
stack protection.  Since -mcet won't get any shadow stack protection,
-mcet will only lead user confusions.  This set of patches removes -mcet
from GCC 8.

H.J. Lu (5):
  x86/CET: Build target libraries with -mshstk
  Regenerate configure of target libraries
  Don't bootstrap GCC with -mcet
  x86/CET tests: Remove -mcet/-mno-cet or replace -mcet with -mshstk
  x86/CET: Remove the -mcet command-lint option

 config/bootstrap-cet.mk|  6 +--
 config/cet.m4  |  2 +-
 gcc/common/config/i386/i386-common.c   |  1 -
 gcc/config/i386/i386.opt   |  5 ---
 gcc/doc/install.texi   |  4 +-
 gcc/doc/invoke.texi| 10 +
 gcc/testsuite/g++.dg/cet-notrack-1.C   |  2 +-
 gcc/testsuite/g++.dg/torture/pr85334.C |  2 +-
 gcc/testsuite/gcc.dg/pr85388-1.c   |  2 +-
 gcc/testsuite/gcc.dg/pr85388-2.c   |  2 +-
 gcc/testsuite/gcc.dg/pr85388-3.c   |  2 +-
 gcc/testsuite/gcc.dg/pr85388-4.c   |  2 +-
 gcc/testsuite/gcc.dg/pr85388-5.c   |  2 +-
 gcc/testsuite/gcc.dg/pr85388-6.c   |  4 +-
 gcc/testsuite/gcc.dg/torture/pr85397-1.c   |  2 +-
 gcc/testsuite/gcc.target/i386/attr-nocf-check-1a.c |  2 +-
 gcc/testsuite/gcc.target/i386/attr-nocf-check-3a.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-intrin-10.c  |  2 +-
 gcc/testsuite/gcc.target/i386/cet-intrin-3.c   |  2 +-
 gcc/testsuite/gcc.target/i386/cet-intrin-5.c   |  2 +-
 gcc/testsuite/gcc.target/i386/cet-intrin-6.c   |  2 +-
 gcc/testsuite/gcc.target/i386/cet-intrin-7.c   |  2 +-
 gcc/testsuite/gcc.target/i386/cet-intrin-8.c   |  2 +-
 gcc/testsuite/gcc.target/i386/cet-intrin-9.c   |  2 +-
 gcc/testsuite/gcc.target/i386/cet-label-2.c|  2 +-
 gcc/testsuite/gcc.target/i386/cet-label-3.c| 16 
 gcc/testsuite/gcc.target/i386/cet-label.c  |  4 +-
 gcc/testsuite/gcc.target/i386/cet-notrack-1a.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-notrack-1b.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-notrack-2a.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-notrack-2b.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-notrack-3.c  |  2 +-
 gcc/testsuite/gcc.target/i386/cet-notrack-4a.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-notrack-4b.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-notrack-5a.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-notrack-5b.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-notrack-6a.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-notrack-6b.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-notrack-7.c  |  2 +-
 gcc/testsuite/gcc.target/i386/cet-notrack-icf-2.c  |  2 +-
 gcc/testsuite/gcc.target/i386/cet-notrack-icf-4.c  |  2 +-
 gcc/testsuite/gcc.target/i386/cet-property-1.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-property-2.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-property-3.c | 11 -
 gcc/testsuite/gcc.target/i386/cet-rdssp-1.c|  2 +-
 gcc/testsuite/gcc.target/i386/cet-sjlj-1.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-sjlj-2.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-sjlj-3.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-sjlj-4.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-sjlj-5.c |  2 +-
 gcc/testsuite/gcc.target/i386/cet-sjlj-6a.c|  2 +-
 gcc/testsuite/gcc.target/i386/cet-sjlj-6b.c|  2 +-
 gcc/testsuite/gcc.target/i386/cet-sjlj-7.c | 48 --
 gcc/testsuite/gcc.target/i386/cet-switch-1.c   |  2 +-
 gcc/testsuite/gcc.target/i386/cet-switch-2.c   |  2 +-
 gcc/testsuite/gcc.target/i386/cet-switch-3.c   |  2 +-
 gcc/testsuite/gcc.target/i386/indirect-thunk-11.c  |  2 +-
 gcc/testsuite/gcc.target/i386/indirect-thunk-12.c  |  2 +-
 .../gcc.target/i386/indirect-thunk-attr-12.c   |  2 +-
 .../gcc.target/i386/indirect-thunk-attr-13.c   |  2 +-
 .../gcc.target/i386/indirect-thunk-attr-14.c   |  2 +-
 .../gcc.target/i386/indirect-thunk-attr-15.c   |  2 +-
 .../gcc.target/i386/indirect-thunk-attr-16.c   |  2 +-
 .../gcc.target/i386/indirect-thunk-extern-10.c |  2 +-
 .../gcc.target/i386/indirect-thunk-extern-8.c  |  2 +-

[PATCH] c/55976 -Werror=return-type should error on returning a value from a void function

2018-04-22 Thread dave . pagan
This patch fixes handling of -Werror=return-type as well as 
-Wno-return-type. Currently, -Werror=return-type does not turn the 
warnings into errors and -Wno-return-type does not turn off 
warning/error. Now they both work as expected.


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

Initialize warn_return_type only for C++/C++ with ObjC extensions. In C, 
this allows us to differentiate between default (no option), or cases 
where -Wreturn-type/-Wno-return-type are specified. Elsewhere, update 
references to warn_return_type (for C) to reflect change in initialization.


Patch was successfully bootstrapped and tested on x86_64-linux.

--Dave

/c
2018-04-22  David Pagan  

PR c/55976
* c-decl.c (grokdeclarator): Update check for return type warnings.
(start_function): Likewise.
(finish_function): Likewise.
* c-typeck.c (c_finish_return): Update check for return type warnings.
Pass OPT_Wreturn_type to pedwarn when appropriate.
* c-opts.c (c_common_post_options): Set default for warn_return_type
for C++/C++ with ObjC extensions only. For C, makes it possible to 
differentiate between default (no option), -Wreturn-type, and
-Wno-return-type.

/testsuite
2018-04-22  David Pagan  

PR c/55976
* gcc.dg/noncompile/pr55976-1.c: New test.
* gcc.dg/noncompile/pr55976-2.c: New test.
Index: gcc/c/c-decl.c
===
--- gcc/c/c-decl.c  (revision 259017)
+++ gcc/c/c-decl.c  (working copy)
@@ -5745,7 +5745,7 @@ grokdeclarator (const struct c_declarator *declara
   /* Issue a warning if this is an ISO C 99 program or if
 -Wreturn-type and this is a function, or if -Wimplicit;
 prefer the former warning since it is more explicit.  */
-  if ((warn_implicit_int || warn_return_type || flag_isoc99)
+  if ((warn_implicit_int || warn_return_type > 0 || flag_isoc99)
  && funcdef_flag)
warn_about_return_type = 1;
   else
@@ -8739,7 +8739,7 @@ start_function (struct c_declspecs *declspecs, str
 
   if (warn_about_return_type)
 warn_defaults_to (loc, flag_isoc99 ? OPT_Wimplicit_int
-  : (warn_return_type ? OPT_Wreturn_type
+  : (warn_return_type > 0 ? OPT_Wreturn_type
  : OPT_Wimplicit_int),
  "return type defaults to %");
 
@@ -9450,8 +9450,9 @@ finish_function (void)
 
   finish_fname_decls ();
 
-  /* Complain if there's just no return statement.  */
-  if (warn_return_type
+  /* Complain if there's no return statement only if option specified on
+ command line.  */
+  if (warn_return_type > 0
   && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
   && !current_function_returns_value && !current_function_returns_null
   /* Don't complain if we are no-return.  */
Index: gcc/c/c-typeck.c
===
--- gcc/c/c-typeck.c(revision 259017)
+++ gcc/c/c-typeck.c(working copy)
@@ -10129,13 +10129,13 @@ c_finish_return (location_t loc, tree retval, tree
   if (!retval)
 {
   current_function_returns_null = 1;
-  if ((warn_return_type || flag_isoc99)
+  if ((warn_return_type >= 0 || flag_isoc99)
  && valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE)
{
  bool warned_here;
  if (flag_isoc99)
warned_here = pedwarn
- (loc, 0,
+ (loc, warn_return_type >= 0 ? OPT_Wreturn_type : 0,
   "% with no value, in function returning non-void");
  else
warned_here = warning_at
@@ -10153,7 +10153,7 @@ c_finish_return (location_t loc, tree retval, tree
   bool warned_here;
   if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
warned_here = pedwarn
- (xloc, 0,
+ (xloc, warn_return_type >= 0 ? OPT_Wreturn_type : 0,
   "% with a value, in function returning void");
   else
warned_here = pedwarn
Index: gcc/c-family/c-opts.c
===
--- gcc/c-family/c-opts.c   (revision 259017)
+++ gcc/c-family/c-opts.c   (working copy)
@@ -994,8 +994,9 @@ c_common_post_options (const char **pfilename)
flag_extern_tls_init = 1;
 }
 
-  if (warn_return_type == -1)
-warn_return_type = c_dialect_cxx ();
+  /* Enable by default only for C++ and C++ with ObjC extensions.  */
+  if (warn_return_type == -1 && c_dialect_cxx ())
+warn_return_type = 1;
 
   if (num_in_fnames > 1)
 error ("too many filenames given.  Type %s --help for usage",
Index: gcc/testsuite/gcc.dg/noncompile/pr55976-1.c
===
--- gcc/testsuite/gcc.dg/noncompile/pr55976-1.c (revision 0)
+++ gcc/testsuite/gcc.dg/noncompile/pr55976-1.c (working copy)
@@ -0,0 +1,14 @@
+/* PR c/55976 */
+/* { dg-d