On Thu, Nov 17, 2016 at 04:53:03PM +0100, Dominik Vogt wrote: > The following two patches fix PR 77822 on s390x for gcc-7. As the > macro doing the argument range checks can be used on other targets > as well, I've put it in system.h (couldn't think of a better > place; maybe rtl.h?). > > Bootstrapped on s390x biarch, regression tested on s390x biarch > and s390, all on a zEC12 with -march=zEC12. > > Please check the commit messages for details.
Common code patch. Ciao Dominik ^_^ ^_^ -- Dominik Vogt IBM Germany
gcc/ChangeLog * system.h (SIZE_POS_IN_RANGE): New.
>From 44654374a0d62e7bc91356fc2189fac5cd99ae12 Mon Sep 17 00:00:00 2001 From: Dominik Vogt <v...@linux.vnet.ibm.com> Date: Thu, 17 Nov 2016 14:49:18 +0100 Subject: [PATCH 1/2] PR target/77822: Add helper macro SIZE_POS_IN_RANGE to system.h. The macro can be used to validate the arguments of zero_extract and sign_extract to fix this problem: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77822 --- gcc/system.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gcc/system.h b/gcc/system.h index 8c6127c..cc68f07 100644 --- a/gcc/system.h +++ b/gcc/system.h @@ -316,6 +316,14 @@ extern int errno; ((unsigned HOST_WIDE_INT) (VALUE) - (unsigned HOST_WIDE_INT) (LOWER) \ <= (unsigned HOST_WIDE_INT) (UPPER) - (unsigned HOST_WIDE_INT) (LOWER)) +/* A convenience macro to determine whether a SIZE lies inclusively + within [1, RANGE], POS lies inclusively within between + [0, RANGE - 1] and the sum lies inclusively within [1, RANGE]. */ +#define SIZE_POS_IN_RANGE(SIZE, POS, RANGE) \ + (IN_RANGE (POS, 0, (RANGE) - 1) \ + && IN_RANGE (SIZE, 1, RANGE) \ + && IN_RANGE ((SIZE) + (POS), 1, RANGE)) + /* Infrastructure for defining missing _MAX and _MIN macros. Note that macros defined with these cannot be used in #if. */ -- 2.3.0