From 1d9335766d86262f8335d63d99b328bb44543b01 Mon Sep 17 00:00:00 2001 From: Bernd Edlinger Date: Fri, 15 Sep 2017 17:21:50 +0000 Subject: common.opt (Wcast-align=strict): New warning option. 2017-09-15 Bernd Edlinger * common.opt (Wcast-align=strict): New warning option. * doc/invoke.texi: Document -Wcast-align=strict. c: 2017-09-15 Bernd Edlinger * c-typeck.c (build_c_cast): Implement -Wcast-align=strict. cp: 2017-09-15 Bernd Edlinger * typeck.c (build_reinterpret_cast_1, build_const_cast_1): Implement -Wcast-align=strict. testsuite: 2017-09-15 Bernd Edlinger * c-c++-common/Wcast-align.c: New test. From-SVN: r252832 --- gcc/c/ChangeLog | 4 ++++ gcc/c/c-typeck.c | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'gcc/c') diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 957daeb..e8e0fb0 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,7 @@ +2017-09-15 Bernd Edlinger + + * c-typeck.c (build_c_cast): Implement -Wcast-align=strict. + 2017-09-13 Marek Polacek PR c/82167 diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index f45fd3c..1956d45 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -5578,7 +5578,7 @@ build_c_cast (location_t loc, tree type, tree expr) } /* Warn about possible alignment problems. */ - if (STRICT_ALIGNMENT + if ((STRICT_ALIGNMENT || warn_cast_align == 2) && TREE_CODE (type) == POINTER_TYPE && TREE_CODE (otype) == POINTER_TYPE && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE @@ -5587,7 +5587,8 @@ build_c_cast (location_t loc, tree type, tree expr) restriction is unknown. */ && !(RECORD_OR_UNION_TYPE_P (TREE_TYPE (otype)) && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode) - && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype))) + && min_align_of_type (TREE_TYPE (type)) + > min_align_of_type (TREE_TYPE (otype))) warning_at (loc, OPT_Wcast_align, "cast increases required alignment of target type"); -- cgit v1.1