From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 87CD93858D37 for ; Wed, 2 Mar 2022 10:18:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 87CD93858D37 Received: by mail-ej1-x62f.google.com with SMTP id a23so2666662eju.3 for ; Wed, 02 Mar 2022 02:18:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=tI2Jb5K7VHc86039gukOhiwSOJQmDfH1Mx4sZkofN3c=; b=D2L+pGmvWxW2B36eSL0gTOJiwockIJrxrTGvPlcZo8vqKuG5KR6vTdbPm4QMqRwGcT VyujCyUy/qgVh5r5zRchZmn1ayjiU/6NKKKUA09z2eNFCCwnXBaV7tI9bk+auYYjaIgm 0U+dovipcBeL0fwsG3ML8U1AQTfgSkRD1Aded7GWx3p3ZgFcCdVlDwMPUNrl6Mv37ngO 0kaKY5Ma8WU6OLbwUm3ddQ5DuYQFcnX+gn/FWBioyILFS7QvslWFrorF+IZ2CYK89oeo GW8BYEsV4Y6e3yp7b4gYv9eDI9PCOgqi8ly0y/WN6k4IAt/f+lS2gMA+MhPrrTWjFCO2 sj9w== X-Gm-Message-State: AOAM533hxBWz8Y6fzd2jvsQOgHVHQnmF6mKU0KCHa+FMsn6EP4QkZ5gc iPJM6o6kUBj2ptb4VK6PPLq5RRrWY9gaGdID31P285qt3nA= X-Google-Smtp-Source: ABdhPJysWF1tw4XGLnOdfHyx/NkoWWq4Yo2hhEN+ZJWf83H5FHIxHfB9T2enScB7Muki5FHHgk9QY56tWg0iO8rw20E= X-Received: by 2002:a17:907:6e01:b0:6d0:562c:e389 with SMTP id sd1-20020a1709076e0100b006d0562ce389mr22937539ejc.497.1646216280677; Wed, 02 Mar 2022 02:18:00 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Wed, 2 Mar 2022 11:17:49 +0100 Message-ID: Subject: Re: [PATCH] c, c++, c-family: -Wshift-negative-value and -Wshift-overflow* tweaks for -fwrapv and C++20+ [PR104711] To: Jakub Jelinek Cc: "Joseph S. Myers" , Jason Merrill , GCC Patches Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_LOTSOFHASH, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Mar 2022 10:18:13 -0000 On Wed, Mar 2, 2022 at 10:23 AM Jakub Jelinek via Gcc-patches wrote: > > Hi! > > As mentioned in the PR, different standards have different definition > on what is an UB left shift. They all agree on out of bounds (including > negative) shift count. > The rules used by ubsan are: > C99-C2x ((unsigned) x >> (uprecm1 - y)) !=3D 0 then UB > C++11-C++17 x < 0 || ((unsigned) x >> (uprecm1 - y)) > 1 then UB > C++20 and later everything is well defined > Now, for C++20, I've in the P1236R1 implementation added an early > exit for -Wshift-overflow* warning so that it never warns, but apparently > -Wshift-negative-value remained as is. As it is well defined in C++20, > the following patch doesn't enable -Wshift-negative-value from -Wextra > anymore for C++20 and later, if users want for compatibility with C++17 > and earlier get the warning, they still can by using -Wshift-negative-val= ue > explicitly. > Another thing is -fwrapv, that is an extension to the standards, so it is= up > to us how exactly we define that case. Our ubsan code treats > TYPE_OVERFLOW_WRAPS (type0) and cxx_dialect >=3D cxx20 the same as only > diagnosing out of bounds shift count and nothing else and IMHO it is most > sensical to treat -fwrapv signed left shifts the same as C++20 treats > them, https://eel.is/c++draft/expr.shift#2 > "The value of E1 << E2 is the unique value congruent to E1=C3=972^E2 modu= lo 2^N, > where N is the width of the type of the result. > [Note 1: E1 is left-shifted E2 bit positions; vacated bits are zero-fille= d. > =E2=80=94 end note]" > with no UB dependent on the E1 values. The UB is only > "The behavior is undefined if the right operand is negative, or greater > than or equal to the width of the promoted left operand." > Under the hood (except for FEs and ubsan from FEs) GCC middle-end doesn't > consider UB in left shifts dependent on the first operand's value, only > the out of bounds shifts. Indeed the obvious place, tree_binary_nonnegative_warnv_p does not consider LSHIFT nonnegative if the first operand is. Not sure about ranger, but at least void foo (int i, int n) { if (i > 0) { int j =3D i << n; if (j < 0) __builtin_abort (); } } is not optimized but it seems it could be (but not in C++20?). Leaving review of the patch to FE maintainers. > > While this change isn't a regression, I'd think it is useful for GCC 12, > it doesn't add new warnings, but just removes warnings that aren't > appropriate. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2022-03-02 Jakub Jelinek > > PR c/104711 > gcc/ > * doc/invoke.texi (-Wextra): Document that -Wshift-negative-value > is enabled by it only for C++11 to C++17 rather than for C++03 or > later. > (-Wshift-negative-value): Similarly (except here we stated > that it is enabled for C++11 or later). > gcc/c-family/ > * c-opts.cc (c_common_post_options): Don't enable > -Wshift-negative-value from -Wextra for C++20 or later. > * c-ubsan.cc (ubsan_instrument_shift): Adjust comments. > * c-warn.cc (maybe_warn_shift_overflow): Use TYPE_OVERFLOW_WRAPS > instead of TYPE_UNSIGNED. > gcc/c/ > * c-fold.cc (c_fully_fold_internal): Don't emit > -Wshift-negative-value warning if TYPE_OVERFLOW_WRAPS. > * c-typeck.cc (build_binary_op): Likewise. > gcc/cp/ > * constexpr.cc (cxx_eval_check_shift_p): Use TYPE_OVERFLOW_WRAPS > instead of TYPE_UNSIGNED. > * typeck.cc (cp_build_binary_op): Don't emit > -Wshift-negative-value warning if TYPE_OVERFLOW_WRAPS. > gcc/testsuite/ > * c-c++-common/Wshift-negative-value-1.c: Remove > dg-additional-options, instead in target selectors of each diagno= stic > check for exact C++ versions where it should be diagnosed. > * c-c++-common/Wshift-negative-value-2.c: Likewise. > * c-c++-common/Wshift-negative-value-3.c: Likewise. > * c-c++-common/Wshift-negative-value-4.c: Likewise. > * c-c++-common/Wshift-negative-value-7.c: New test. > * c-c++-common/Wshift-negative-value-8.c: New test. > * c-c++-common/Wshift-negative-value-9.c: New test. > * c-c++-common/Wshift-negative-value-10.c: New test. > * c-c++-common/Wshift-overflow-1.c: Remove > dg-additional-options, instead in target selectors of each diagno= stic > check for exact C++ versions where it should be diagnosed. > * c-c++-common/Wshift-overflow-2.c: Likewise. > * c-c++-common/Wshift-overflow-5.c: Likewise. > * c-c++-common/Wshift-overflow-6.c: Likewise. > * c-c++-common/Wshift-overflow-7.c: Likewise. > * c-c++-common/Wshift-overflow-8.c: New test. > * c-c++-common/Wshift-overflow-9.c: New test. > * c-c++-common/Wshift-overflow-10.c: New test. > * c-c++-common/Wshift-overflow-11.c: New test. > * c-c++-common/Wshift-overflow-12.c: New test. > > --- gcc/doc/invoke.texi.jj 2022-02-25 10:46:53.085181500 +0100 > +++ gcc/doc/invoke.texi 2022-03-01 09:59:15.040855224 +0100 > @@ -5809,7 +5809,7 @@ name is still supported, but the newer n > -Wredundant-move @r{(only for C++)} @gol > -Wtype-limits @gol > -Wuninitialized @gol > --Wshift-negative-value @r{(in C++03 and in C99 and newer)} @gol > +-Wshift-negative-value @r{(in C++11 to C++17 and in C99 and newer)} @go= l > -Wunused-parameter @r{(only with} @option{-Wunused} @r{or} @option{-Wall= }@r{)} @gol > -Wunused-but-set-parameter @r{(only with} @option{-Wunused} @r{or} @opti= on{-Wall}@r{)}} > > @@ -6839,7 +6839,7 @@ of the type. This warning is enabled by > @opindex Wshift-negative-value > @opindex Wno-shift-negative-value > Warn if left shifting a negative value. This warning is enabled by > -@option{-Wextra} in C99 and C++11 modes (and newer). > +@option{-Wextra} in C99 (and newer) and C++11 to C++17 modes. > > @item -Wno-shift-overflow > @itemx -Wshift-overflow=3D@var{n} > --- gcc/c-family/c-opts.cc.jj 2022-01-18 11:58:58.884992028 +0100 > +++ gcc/c-family/c-opts.cc 2022-03-01 09:57:34.880253831 +0100 > @@ -934,10 +934,12 @@ c_common_post_options (const char **pfil > if (warn_shift_overflow =3D=3D -1) > warn_shift_overflow =3D cxx_dialect >=3D cxx11 || flag_isoc99; > > - /* -Wshift-negative-value is enabled by -Wextra in C99 and C++11 modes= . */ > + /* -Wshift-negative-value is enabled by -Wextra in C99 and C++11 to C+= +17 > + modes. */ > if (warn_shift_negative_value =3D=3D -1) > warn_shift_negative_value =3D (extra_warnings > - && (cxx_dialect >=3D cxx11 || flag_isoc9= 9)); > + && (cxx_dialect >=3D cxx11 || flag_isoc9= 9) > + && cxx_dialect < cxx20); > > /* -Wregister is enabled by default in C++17. */ > SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_regist= er, > --- gcc/c-family/c-ubsan.cc.jj 2022-02-09 15:15:59.288840032 +0100 > +++ gcc/c-family/c-ubsan.cc 2022-03-01 09:55:51.779693845 +0100 > @@ -173,7 +173,7 @@ ubsan_instrument_shift (location_t loc, > || cxx_dialect >=3D cxx20) > ; > > - /* For signed x << y, in C99/C11, the following: > + /* For signed x << y, in C99 and later, the following: > (unsigned) x >> (uprecm1 - y) > if non-zero, is undefined. */ > else if (code =3D=3D LSHIFT_EXPR && flag_isoc99 && cxx_dialect < cxx11= ) > @@ -186,7 +186,7 @@ ubsan_instrument_shift (location_t loc, > build_int_cst (TREE_TYPE (tt), 0)); > } > > - /* For signed x << y, in C++11 and later, the following: > + /* For signed x << y, in C++11 to C++17, the following: > x < 0 || ((unsigned) x >> (uprecm1 - y)) > if > 1, is undefined. */ > else if (code =3D=3D LSHIFT_EXPR && cxx_dialect >=3D cxx11) > --- gcc/c-family/c-warn.cc.jj 2022-01-18 11:58:58.922991486 +0100 > +++ gcc/c-family/c-warn.cc 2022-03-01 10:02:41.634971050 +0100 > @@ -2605,7 +2605,7 @@ maybe_warn_shift_overflow (location_t lo > unsigned int prec0 =3D TYPE_PRECISION (type0); > > /* Left-hand operand must be signed. */ > - if (TYPE_UNSIGNED (type0) || cxx_dialect >=3D cxx20) > + if (TYPE_OVERFLOW_WRAPS (type0) || cxx_dialect >=3D cxx20) > return false; > > unsigned int min_prec =3D (wi::min_precision (wi::to_wide (op0), SIGNE= D) > --- gcc/c/c-fold.cc.jj 2022-02-09 20:45:24.253211303 +0100 > +++ gcc/c/c-fold.cc 2022-03-01 11:39:32.153859825 +0100 > @@ -382,6 +382,7 @@ c_fully_fold_internal (tree expr, bool i > && TREE_CODE (TREE_TYPE (orig_op0)) =3D=3D INTEGER_TYPE > && TREE_CODE (op0) =3D=3D INTEGER_CST > && c_inhibit_evaluation_warnings =3D=3D 0 > + && !TYPE_OVERFLOW_WRAPS (TREE_TYPE (orig_op0)) > && tree_int_cst_sgn (op0) < 0) > warning_at (loc, OPT_Wshift_negative_value, > "left shift of negative value"); > --- gcc/c/c-typeck.cc.jj 2022-02-11 00:19:22.135067293 +0100 > +++ gcc/c/c-typeck.cc 2022-03-01 10:04:20.925584897 +0100 > @@ -12213,7 +12213,8 @@ build_binary_op (location_t location, en > { > doing_shift =3D true; > if (TREE_CODE (op0) =3D=3D INTEGER_CST > - && tree_int_cst_sgn (op0) < 0) > + && tree_int_cst_sgn (op0) < 0 > + && !TYPE_OVERFLOW_WRAPS (type0)) > { > /* Don't reject a left shift of a negative value in a conte= xt > where a constant expression is needed in C90. */ > --- gcc/cp/constexpr.cc.jj 2022-02-18 12:37:51.081601299 +0100 > +++ gcc/cp/constexpr.cc 2022-03-01 11:56:12.874890444 +0100 > @@ -3165,7 +3165,7 @@ cxx_eval_check_shift_p (location_t loc, > The value of E1 << E2 is the unique value congruent to E1 x 2^E2 mo= dulo > 2^N, where N is the range exponent of the type of the result. */ > if (code =3D=3D LSHIFT_EXPR > - && !TYPE_UNSIGNED (lhstype) > + && !TYPE_OVERFLOW_WRAPS (lhstype) > && cxx_dialect >=3D cxx11 > && cxx_dialect < cxx20) > { > --- gcc/cp/typeck.cc.jj 2022-02-18 12:38:06.065393230 +0100 > +++ gcc/cp/typeck.cc 2022-03-01 10:04:57.726071137 +0100 > @@ -5382,6 +5382,7 @@ cp_build_binary_op (const op_location_t > doing_shift =3D true; > if (TREE_CODE (const_op0) =3D=3D INTEGER_CST > && tree_int_cst_sgn (const_op0) < 0 > + && !TYPE_OVERFLOW_WRAPS (type0) > && (complain & tf_warning) > && c_inhibit_evaluation_warnings =3D=3D 0) > warning_at (location, OPT_Wshift_negative_value, > --- gcc/testsuite/c-c++-common/Wshift-negative-value-1.c.jj 2020-01-1= 2 11:54:36.995404628 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-negative-value-1.c 2022-03-0= 1 11:43:47.217299318 +0100 > @@ -1,13 +1,12 @@ > /* PR c/65179 */ > /* { dg-do compile } */ > /* { dg-options "-O -Wextra" } */ > -/* { dg-additional-options "-std=3Dc++11" { target c++ } } */ > > enum E { > A =3D 0 << 1, > B =3D 1 << 1, > - C =3D -1 << 1, /* { dg-warning "10:left shift of negative value|not an= integer constant" } */ > - /* { dg-error "left operand of shift expression" "shift" { target c++ = } .-1 } */ > + C =3D -1 << 1, /* { dg-warning "10:left shift of negative value|not an= integer constant" "" { target { c || { c++11 && c++17_down } } } } */ > + /* { dg-error "left operand of shift expression" "shift" { target { c+= +11 && c++17_down } } .-1 } */ > D =3D 0 >> 1, > E =3D 1 >> 1, > F =3D -1 >> 1 > @@ -23,10 +22,10 @@ left (int x) > int r =3D 0; > r +=3D z << x; > r +=3D o << x; > - r +=3D m << x; /* { dg-warning "10:left shift of negative value" } */ > + r +=3D m << x; /* { dg-warning "10:left shift of negative value" "" { = target { c || { c++11 && c++17_down } } } } */ > r +=3D 0 << x; > r +=3D 1 << x; > - r +=3D -1 << x; /* { dg-warning "11:left shift of negative value" } */ > + r +=3D -1 << x; /* { dg-warning "11:left shift of negative value" "" {= target { c || { c++11 && c++17_down } } } } */ > r +=3D -1U << x; > return r; > } > --- gcc/testsuite/c-c++-common/Wshift-negative-value-2.c.jj 2020-01-1= 2 11:54:36.995404628 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-negative-value-2.c 2022-03-0= 1 11:47:41.695026169 +0100 > @@ -1,14 +1,13 @@ > /* PR c/65179 */ > /* { dg-do compile } */ > /* { dg-options "-O -Wshift-negative-value" } */ > -/* { dg-additional-options "-std=3Dc++11" { target c++ } } */ > > enum E { > A =3D 0 << 1, > B =3D 1 << 1, > C =3D -1 << 1, /* { dg-warning "10:left shift of negative value" } */ > - /* { dg-error "not an integer constant" "no constant" { target c++ } .= -1 } */ > - /* { dg-error "left operand of shift expression" "shift" { target c++ = } .-2 } */ > + /* { dg-error "not an integer constant" "no constant" { target { c++11= && c++17_down } } .-1 } */ > + /* { dg-error "left operand of shift expression" "shift" { target { c+= +11 && c++17_down } } .-2 } */ > D =3D 0 >> 1, > E =3D 1 >> 1, > F =3D -1 >> 1 > --- gcc/testsuite/c-c++-common/Wshift-negative-value-3.c.jj 2020-01-1= 2 11:54:36.995404628 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-negative-value-3.c 2022-03-0= 1 11:48:01.029756269 +0100 > @@ -1,14 +1,13 @@ > /* PR c/65179 */ > /* { dg-do compile } */ > /* { dg-options "-O -Wextra -Wno-shift-negative-value" } */ > -/* { dg-additional-options "-std=3Dc++11" { target c++ } } */ > > enum E { > A =3D 0 << 1, > B =3D 1 << 1, > C =3D -1 << 1, > - /* { dg-error "not an integer constant" "no constant" { target c++ } .= -1 } */ > - /* { dg-error "left operand of shift expression" "shift" { target c++ = } .-2 } */ > + /* { dg-error "not an integer constant" "no constant" { target { c++11= && c++17_down } } .-1 } */ > + /* { dg-error "left operand of shift expression" "shift" { target { c+= +11 && c++17_down } } .-2 } */ > D =3D 0 >> 1, > E =3D 1 >> 1, > F =3D -1 >> 1 > --- gcc/testsuite/c-c++-common/Wshift-negative-value-4.c.jj 2020-01-1= 2 11:54:36.995404628 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-negative-value-4.c 2022-03-0= 1 11:48:46.740118184 +0100 > @@ -1,14 +1,13 @@ > /* PR c/65179 */ > /* { dg-do compile } */ > /* { dg-options "-O" } */ > -/* { dg-additional-options "-std=3Dc++11" { target c++ } } */ > > enum E { > A =3D 0 << 1, > B =3D 1 << 1, > C =3D -1 << 1, > - /* { dg-error "not an integer constant" "no constant" { target c++ } .= -1 } */ > - /* { dg-error "left operand of shift expression" "shift" { target c++ = } .-2 } */ > + /* { dg-error "not an integer constant" "no constant" { target { c++11= && c++17_down } } .-1 } */ > + /* { dg-error "left operand of shift expression" "shift" { target { c+= +11 && c++17_down } } .-2 } */ > D =3D 0 >> 1, > E =3D 1 >> 1, > F =3D -1 >> 1 > --- gcc/testsuite/c-c++-common/Wshift-negative-value-7.c.jj 2022-03-0= 1 11:00:56.877179511 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-negative-value-7.c 2022-03-0= 1 11:59:32.535103327 +0100 > @@ -0,0 +1,5 @@ > +/* PR c/65179 */ > +/* { dg-do compile } */ > +/* { dg-options "-O -Wextra -fwrapv" } */ > + > +#include "Wshift-negative-value-1.c" > --- gcc/testsuite/c-c++-common/Wshift-negative-value-8.c.jj 2022-03-0= 1 11:01:41.087562363 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-negative-value-8.c 2022-03-0= 1 11:59:43.084956059 +0100 > @@ -0,0 +1,5 @@ > +/* PR c/65179 */ > +/* { dg-do compile } */ > +/* { dg-options "-O -Wshift-negative-value -fwrapv" } */ > + > +#include "Wshift-negative-value-1.c" > --- gcc/testsuite/c-c++-common/Wshift-negative-value-9.c.jj 2022-03-0= 1 11:02:38.837756210 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-negative-value-9.c 2022-03-0= 1 11:59:51.733835326 +0100 > @@ -0,0 +1,5 @@ > +/* PR c/65179 */ > +/* { dg-do compile } */ > +/* { dg-options "-O -fwrapv" } */ > + > +#include "Wshift-negative-value-1.c" > --- gcc/testsuite/c-c++-common/Wshift-negative-value-10.c.jj 2022-03-0= 1 11:03:28.922057068 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-negative-value-10.c 2022-03-0= 1 11:03:44.101845168 +0100 > @@ -0,0 +1,7 @@ > +/* PR c/65179 */ > +/* { dg-do compile } */ > +/* { dg-options "-O -Wshift-negative-value -fwrapv" } */ > +/* { dg-additional-options "-std=3Dc++03" { target c++ } } */ > +/* { dg-additional-options "-std=3Dc90" { target c } } */ > + > +#include "Wshift-negative-value-1.c" > --- gcc/testsuite/c-c++-common/Wshift-overflow-1.c.jj 2020-01-12 11:54:= 36.995404628 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-overflow-1.c 2022-03-01 12:01:= 33.792410660 +0100 > @@ -1,7 +1,6 @@ > /* PR c++/55095 */ > /* { dg-do compile { target int32 } } */ > /* { dg-options "-O" } */ > -/* { dg-additional-options "-std=3Dc++11" { target c++ } } */ > > #define INTM1 (sizeof (int) * __CHAR_BIT__ - 1) > #define INTM2 (sizeof (int) * __CHAR_BIT__ - 2) > @@ -12,16 +11,16 @@ > #define LONG_LONG_MIN (-__LONG_LONG_MAX__-1) > > int i1 =3D 1 << INTM1; > -int i2 =3D 9 << INTM1; /* { dg-warning "requires 36 bits to represent" }= */ > -int i3 =3D 10 << INTM2; /* { dg-warning "requires 35 bits to represent" = } */ > -int i4 =3D __INT_MAX__ << 2; /* { dg-warning "requires 34 bits to repres= ent" } */ > -int i5 =3D __INT_MAX__ << INTM1; /* { dg-warning "requires 63 bits to re= present" } */ > +int i2 =3D 9 << INTM1; /* { dg-warning "requires 36 bits to represent" "= " { target { c || { c++11 && c++17_down } } } } */ > +int i3 =3D 10 << INTM2; /* { dg-warning "requires 35 bits to represent" = "" { target { c || { c++11 && c++17_down } } } } */ > +int i4 =3D __INT_MAX__ << 2; /* { dg-warning "requires 34 bits to repres= ent" "" { target { c || { c++11 && c++17_down } } } } */ > +int i5 =3D __INT_MAX__ << INTM1; /* { dg-warning "requires 63 bits to re= present" "" { target { c || { c++11 && c++17_down } } } } */ > int i6 =3D -1 << INTM1; > -int i7 =3D -9 << INTM1; /* { dg-warning "requires 36 bits to represent" = } */ > -int i8 =3D -10 << INTM2; /* { dg-warning "requires 35 bits to represent"= } */ > -int i9 =3D -__INT_MAX__ << 2; /* { dg-warning "requires 34 bits to repre= sent" } */ > -int i10 =3D -__INT_MAX__ << INTM1; /* { dg-warning "requires 63 bits to = represent" } */ > -int i11 =3D INT_MIN << 1; /* { dg-warning "requires 33 bits to represent= " } */ > +int i7 =3D -9 << INTM1; /* { dg-warning "requires 36 bits to represent" = "" { target { c || { c++11 && c++17_down } } } } */ > +int i8 =3D -10 << INTM2; /* { dg-warning "requires 35 bits to represent"= "" { target { c || { c++11 && c++17_down } } } } */ > +int i9 =3D -__INT_MAX__ << 2; /* { dg-warning "requires 34 bits to repre= sent" "" { target { c || { c++11 && c++17_down } } } } */ > +int i10 =3D -__INT_MAX__ << INTM1; /* { dg-warning "requires 63 bits to = represent" "" { target { c || { c++11 && c++17_down } } } } */ > +int i11 =3D INT_MIN << 1; /* { dg-warning "requires 33 bits to represent= " "" { target { c || { c++11 && c++17_down } } } } */ > > int r1 =3D 1 >> INTM1; > int r2 =3D 9 >> INTM1; > @@ -35,29 +34,29 @@ int r9 =3D -__INT_MAX__ >> 2; > int r10 =3D -__INT_MAX__ >> INTM1; > > unsigned u1 =3D 1 << INTM1; > -unsigned u2 =3D 9 << INTM1; /* { dg-warning "requires 36 bits to represe= nt" } */ > +unsigned u2 =3D 9 << INTM1; /* { dg-warning "requires 36 bits to represe= nt" "" { target { c || { c++11 && c++17_down } } } } */ > unsigned u3 =3D 2U << INTM1; > unsigned u4 =3D 9U << INTM1; > unsigned u5 =3D 10U << INTM2; > > long long int l1 =3D 1LL << LLONGM1; > -long long int l2 =3D 9LL << LLONGM1; /* { dg-warning "requires 68 bits t= o represent" } */ > -long long int l3 =3D 10LL << LLONGM2; /* { dg-warning "requires 67 bits = to represent" } */ > -long long int l4 =3D __LONG_LONG_MAX__ << 2; /* { dg-warning "requires 6= 6 bits to represent" } */ > -long long int l5 =3D __LONG_LONG_MAX__ << LLONGM1; /* { dg-warning "requ= ires 127 bits to represent" } */ > +long long int l2 =3D 9LL << LLONGM1; /* { dg-warning "requires 68 bits t= o represent" "" { target { c || { c++11 && c++17_down } } } } */ > +long long int l3 =3D 10LL << LLONGM2; /* { dg-warning "requires 67 bits = to represent" "" { target { c || { c++11 && c++17_down } } } } */ > +long long int l4 =3D __LONG_LONG_MAX__ << 2; /* { dg-warning "requires 6= 6 bits to represent" "" { target { c || { c++11 && c++17_down } } } } */ > +long long int l5 =3D __LONG_LONG_MAX__ << LLONGM1; /* { dg-warning "requ= ires 127 bits to represent" "" { target { c || { c++11 && c++17_down } } } = } */ > long long int l6 =3D -1LL << LLONGM1; > -long long int l7 =3D -9LL << LLONGM1; /* { dg-warning "requires 68 bits = to represent" } */ > -long long int l8 =3D -10LL << LLONGM2; /* { dg-warning "requires 67 bits= to represent" } */ > -long long int l9 =3D -__LONG_LONG_MAX__ << 2; /* { dg-warning "requires = 66 bits to represent" } */ > -long long int l10 =3D -__LONG_LONG_MAX__ << LLONGM1; /* { dg-warning "re= quires 127 bits to represent" } */ > -long long int l11 =3D LONG_LONG_MIN << 1; /* { dg-warning "requires 65 b= its to represent" } */ > +long long int l7 =3D -9LL << LLONGM1; /* { dg-warning "requires 68 bits = to represent" "" { target { c || { c++11 && c++17_down } } } } */ > +long long int l8 =3D -10LL << LLONGM2; /* { dg-warning "requires 67 bits= to represent" "" { target { c || { c++11 && c++17_down } } } } */ > +long long int l9 =3D -__LONG_LONG_MAX__ << 2; /* { dg-warning "requires = 66 bits to represent" "" { target { c || { c++11 && c++17_down } } } } */ > +long long int l10 =3D -__LONG_LONG_MAX__ << LLONGM1; /* { dg-warning "re= quires 127 bits to represent" "" { target { c || { c++11 && c++17_down } } = } } */ > +long long int l11 =3D LONG_LONG_MIN << 1; /* { dg-warning "requires 65 b= its to represent" "" { target { c || { c++11 && c++17_down } } } } */ > > void > fn (void) > { > const int a =3D 10; > const __SIZE_TYPE__ b =3D INTM1; > - int k1 =3D a << b; /* { dg-warning "requires 36 bits to represent" } *= / > - int k2 =3D 10 << b; /* { dg-warning "requires 36 bits to represent" } = */ > - int k3 =3D a << INTM1; /* { dg-warning "requires 36 bits to represent"= } */ > + int k1 =3D a << b; /* { dg-warning "requires 36 bits to represent" "" = { target { c || { c++11 && c++17_down } } } } */ > + int k2 =3D 10 << b; /* { dg-warning "requires 36 bits to represent" ""= { target { c || { c++11 && c++17_down } } } } */ > + int k3 =3D a << INTM1; /* { dg-warning "requires 36 bits to represent"= "" { target { c || { c++11 && c++17_down } } } } */ > } > --- gcc/testsuite/c-c++-common/Wshift-overflow-2.c.jj 2020-01-12 11:54:= 36.995404628 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-overflow-2.c 2022-03-01 11:20:= 16.498991992 +0100 > @@ -1,7 +1,6 @@ > /* PR c++/55095 */ > /* { dg-do compile { target int32 } } */ > /* { dg-options "-O -Wno-shift-overflow" } */ > -/* { dg-additional-options "-std=3Dc++11" { target c++ } } */ > > #define INTM1 (sizeof (int) * __CHAR_BIT__ - 1) > #define INTM2 (sizeof (int) * __CHAR_BIT__ - 2) > --- gcc/testsuite/c-c++-common/Wshift-overflow-5.c.jj 2020-01-12 11:54:= 36.995404628 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-overflow-5.c 2022-03-01 12:05:= 27.955141905 +0100 > @@ -1,11 +1,10 @@ > /* PR c++/55095 */ > /* { dg-do compile { target int32 } } */ > /* { dg-options "-O -Wshift-overflow=3D2" } */ > -/* { dg-additional-options "-std=3Dc++11" { target c++ } } */ > > #define INTM1 (sizeof (int) * __CHAR_BIT__ - 1) > #define LLONGM1 (sizeof (long long) * __CHAR_BIT__ - 1) > > -int i1 =3D 1 << INTM1; /* { dg-warning "requires 33 bits to represent" }= */ > -unsigned u1 =3D 1 << INTM1; /* { dg-warning "requires 33 bits to represe= nt" } */ > -long long int l1 =3D 1LL << LLONGM1; /* { dg-warning "requires 65 bits t= o represent" } */ > +int i1 =3D 1 << INTM1; /* { dg-warning "requires 33 bits to represent" "= " { target { c || c++11_down } } } */ > +unsigned u1 =3D 1 << INTM1; /* { dg-warning "requires 33 bits to represe= nt" "" { target { c || c++11_down } } } */ > +long long int l1 =3D 1LL << LLONGM1; /* { dg-warning "requires 65 bits t= o represent" "" { target { c || c++11_down } } } */ > --- gcc/testsuite/c-c++-common/Wshift-overflow-6.c.jj 2020-01-12 11:54:= 36.995404628 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-overflow-6.c 2022-03-01 12:06:= 15.950471922 +0100 > @@ -1,7 +1,6 @@ > /* PR c++/55095 */ > /* { dg-do compile { target int32 } } */ > /* { dg-options "-Wshift-overflow=3D1" } */ > -/* { dg-additional-options "-std=3Dc++11" { target c++ } } */ > > int i00 =3D 0b1 << 31; > int i01 =3D 0b10 << 30; > @@ -34,4 +33,4 @@ int i27 =3D 0b1000000000000000000000000000 > int i28 =3D 0b10000000000000000000000000000 << 3; > int i29 =3D 0b100000000000000000000000000000 << 2; > int i30 =3D 0b1000000000000000000000000000000 << 1; > -int i31 =3D (int) 0b10000000000000000000000000000000u << 1; /* { dg-warn= ing "requires 33 bits to represent" } */ > +int i31 =3D (int) 0b10000000000000000000000000000000u << 1; /* { dg-warn= ing "requires 33 bits to represent" "" { target { c || c++17_down } } } */ > --- gcc/testsuite/c-c++-common/Wshift-overflow-7.c.jj 2020-01-12 11:54:= 36.995404628 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-overflow-7.c 2022-03-01 12:08:= 09.738883507 +0100 > @@ -1,37 +1,36 @@ > /* PR c++/55095 */ > /* { dg-do compile { target int32 } } */ > /* { dg-options "-Wshift-overflow=3D2" } */ > -/* { dg-additional-options "-std=3Dc++11" { target c++ } } */ > > -int i00 =3D 0b1 << 31; /* { dg-warning "requires 33 bits to represent" }= */ > -int i01 =3D 0b10 << 30; /* { dg-warning "requires 33 bits to represent" = } */ > -int i02 =3D 0b100 << 29; /* { dg-warning "requires 33 bits to represent"= } */ > -int i03 =3D 0b1000 << 28; /* { dg-warning "requires 33 bits to represent= " } */ > -int i04 =3D 0b10000 << 27; /* { dg-warning "requires 33 bits to represen= t" } */ > -int i05 =3D 0b100000 << 26; /* { dg-warning "requires 33 bits to represe= nt" } */ > -int i06 =3D 0b1000000 << 25; /* { dg-warning "requires 33 bits to repres= ent" } */ > -int i07 =3D 0b10000000 << 24; /* { dg-warning "requires 33 bits to repre= sent" } */ > -int i08 =3D 0b100000000 << 23; /* { dg-warning "requires 33 bits to repr= esent" } */ > -int i09 =3D 0b1000000000 << 22; /* { dg-warning "requires 33 bits to rep= resent" } */ > -int i10 =3D 0b10000000000 << 21; /* { dg-warning "requires 33 bits to re= present" } */ > -int i11 =3D 0b100000000000 << 20; /* { dg-warning "requires 33 bits to r= epresent" } */ > -int i12 =3D 0b1000000000000 << 19; /* { dg-warning "requires 33 bits to = represent" } */ > -int i13 =3D 0b10000000000000 << 18; /* { dg-warning "requires 33 bits to= represent" } */ > -int i14 =3D 0b100000000000000 << 17; /* { dg-warning "requires 33 bits t= o represent" } */ > -int i15 =3D 0b1000000000000000 << 16; /* { dg-warning "requires 33 bits = to represent" } */ > -int i16 =3D 0b10000000000000000 << 15; /* { dg-warning "requires 33 bits= to represent" } */ > -int i17 =3D 0b100000000000000000 << 14; /* { dg-warning "requires 33 bit= s to represent" } */ > -int i18 =3D 0b1000000000000000000 << 13; /* { dg-warning "requires 33 bi= ts to represent" } */ > -int i19 =3D 0b10000000000000000000 << 12; /* { dg-warning "requires 33 b= its to represent" } */ > -int i20 =3D 0b100000000000000000000 << 11; /* { dg-warning "requires 33 = bits to represent" } */ > -int i21 =3D 0b1000000000000000000000 << 10; /* { dg-warning "requires 33= bits to represent" } */ > -int i22 =3D 0b10000000000000000000000 << 9; /* { dg-warning "requires 33= bits to represent" } */ > -int i23 =3D 0b100000000000000000000000 << 8; /* { dg-warning "requires 3= 3 bits to represent" } */ > -int i24 =3D 0b1000000000000000000000000 << 7; /* { dg-warning "requires = 33 bits to represent" } */ > -int i25 =3D 0b10000000000000000000000000 << 6; /* { dg-warning "requires= 33 bits to represent" } */ > -int i26 =3D 0b100000000000000000000000000 << 5; /* { dg-warning "require= s 33 bits to represent" } */ > -int i27 =3D 0b1000000000000000000000000000 << 4; /* { dg-warning "requir= es 33 bits to represent" } */ > -int i28 =3D 0b10000000000000000000000000000 << 3; /* { dg-warning "requi= res 33 bits to represent" } */ > -int i29 =3D 0b100000000000000000000000000000 << 2; /* { dg-warning "requ= ires 33 bits to represent" } */ > -int i30 =3D 0b1000000000000000000000000000000 << 1; /* { dg-warning "req= uires 33 bits to represent" } */ > -int i31 =3D (int) 0b10000000000000000000000000000000u << 1; /* { dg-warn= ing "requires 33 bits to represent" } */ > +int i00 =3D 0b1 << 31; /* { dg-warning "requires 33 bits to represent" "= " { target { c || c++11_down } } } */ > +int i01 =3D 0b10 << 30; /* { dg-warning "requires 33 bits to represent" = "" { target { c || c++11_down } } } */ > +int i02 =3D 0b100 << 29; /* { dg-warning "requires 33 bits to represent"= "" { target { c || c++11_down } } } */ > +int i03 =3D 0b1000 << 28; /* { dg-warning "requires 33 bits to represent= " "" { target { c || c++11_down } } } */ > +int i04 =3D 0b10000 << 27; /* { dg-warning "requires 33 bits to represen= t" "" { target { c || c++11_down } } } */ > +int i05 =3D 0b100000 << 26; /* { dg-warning "requires 33 bits to represe= nt" "" { target { c || c++11_down } } } */ > +int i06 =3D 0b1000000 << 25; /* { dg-warning "requires 33 bits to repres= ent" "" { target { c || c++11_down } } } */ > +int i07 =3D 0b10000000 << 24; /* { dg-warning "requires 33 bits to repre= sent" "" { target { c || c++11_down } } } */ > +int i08 =3D 0b100000000 << 23; /* { dg-warning "requires 33 bits to repr= esent" "" { target { c || c++11_down } } } */ > +int i09 =3D 0b1000000000 << 22; /* { dg-warning "requires 33 bits to rep= resent" "" { target { c || c++11_down } } } */ > +int i10 =3D 0b10000000000 << 21; /* { dg-warning "requires 33 bits to re= present" "" { target { c || c++11_down } } } */ > +int i11 =3D 0b100000000000 << 20; /* { dg-warning "requires 33 bits to r= epresent" "" { target { c || c++11_down } } } */ > +int i12 =3D 0b1000000000000 << 19; /* { dg-warning "requires 33 bits to = represent" "" { target { c || c++11_down } } } */ > +int i13 =3D 0b10000000000000 << 18; /* { dg-warning "requires 33 bits to= represent" "" { target { c || c++11_down } } } */ > +int i14 =3D 0b100000000000000 << 17; /* { dg-warning "requires 33 bits t= o represent" "" { target { c || c++11_down } } } */ > +int i15 =3D 0b1000000000000000 << 16; /* { dg-warning "requires 33 bits = to represent" "" { target { c || c++11_down } } } */ > +int i16 =3D 0b10000000000000000 << 15; /* { dg-warning "requires 33 bits= to represent" "" { target { c || c++11_down } } } */ > +int i17 =3D 0b100000000000000000 << 14; /* { dg-warning "requires 33 bit= s to represent" "" { target { c || c++11_down } } } */ > +int i18 =3D 0b1000000000000000000 << 13; /* { dg-warning "requires 33 bi= ts to represent" "" { target { c || c++11_down } } } */ > +int i19 =3D 0b10000000000000000000 << 12; /* { dg-warning "requires 33 b= its to represent" "" { target { c || c++11_down } } } */ > +int i20 =3D 0b100000000000000000000 << 11; /* { dg-warning "requires 33 = bits to represent" "" { target { c || c++11_down } } } */ > +int i21 =3D 0b1000000000000000000000 << 10; /* { dg-warning "requires 33= bits to represent" "" { target { c || c++11_down } } } */ > +int i22 =3D 0b10000000000000000000000 << 9; /* { dg-warning "requires 33= bits to represent" "" { target { c || c++11_down } } } */ > +int i23 =3D 0b100000000000000000000000 << 8; /* { dg-warning "requires 3= 3 bits to represent" "" { target { c || c++11_down } } } */ > +int i24 =3D 0b1000000000000000000000000 << 7; /* { dg-warning "requires = 33 bits to represent" "" { target { c || c++11_down } } } */ > +int i25 =3D 0b10000000000000000000000000 << 6; /* { dg-warning "requires= 33 bits to represent" "" { target { c || c++11_down } } } */ > +int i26 =3D 0b100000000000000000000000000 << 5; /* { dg-warning "require= s 33 bits to represent" "" { target { c || c++11_down } } } */ > +int i27 =3D 0b1000000000000000000000000000 << 4; /* { dg-warning "requir= es 33 bits to represent" "" { target { c || c++11_down } } } */ > +int i28 =3D 0b10000000000000000000000000000 << 3; /* { dg-warning "requi= res 33 bits to represent" "" { target { c || c++11_down } } } */ > +int i29 =3D 0b100000000000000000000000000000 << 2; /* { dg-warning "requ= ires 33 bits to represent" "" { target { c || c++11_down } } } */ > +int i30 =3D 0b1000000000000000000000000000000 << 1; /* { dg-warning "req= uires 33 bits to represent" "" { target { c || c++11_down } } } */ > +int i31 =3D (int) 0b10000000000000000000000000000000u << 1; /* { dg-warn= ing "requires 33 bits to represent" "" { target { c || c++17_down } } } */ > --- gcc/testsuite/c-c++-common/Wshift-overflow-8.c.jj 2022-03-01 11:06:= 15.451732430 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-overflow-8.c 2022-03-01 11:21:= 43.500777502 +0100 > @@ -0,0 +1,5 @@ > +/* PR c++/55095 */ > +/* { dg-do compile { target int32 } } */ > +/* { dg-options "-O -fwrapv" } */ > + > +#include "Wshift-overflow-1.c" > --- gcc/testsuite/c-c++-common/Wshift-overflow-9.c.jj 2022-03-01 11:07:= 04.998040795 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-overflow-9.c 2022-03-01 11:07:= 30.015691566 +0100 > @@ -0,0 +1,7 @@ > +/* PR c++/55095 */ > +/* { dg-do compile { target int32 } } */ > +/* { dg-options "-O -Wshift-overflow -fwrapv" } */ > +/* { dg-additional-options "-std=3Dgnu90" { target c } } */ > +/* { dg-additional-options "-std=3Dc++03" { target c++ } } */ > + > +#include "Wshift-overflow-1.c" > --- gcc/testsuite/c-c++-common/Wshift-overflow-10.c.jj 2022-03-01 11:09:= 17.167195807 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-overflow-10.c 2022-03-01 11:21:= 54.518623704 +0100 > @@ -0,0 +1,5 @@ > +/* PR c++/55095 */ > +/* { dg-do compile { target int32 } } */ > +/* { dg-options "-O -Wshift-overflow=3D2 -fwrapv" } */ > + > +#include "Wshift-overflow-5.c" > --- gcc/testsuite/c-c++-common/Wshift-overflow-11.c.jj 2022-03-01 11:09:= 46.991779477 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-overflow-11.c 2022-03-01 11:21:= 59.235557860 +0100 > @@ -0,0 +1,5 @@ > +/* PR c++/55095 */ > +/* { dg-do compile { target int32 } } */ > +/* { dg-options "-Wshift-overflow=3D1 -fwrapv" } */ > + > +#include "Wshift-overflow-6.c" > --- gcc/testsuite/c-c++-common/Wshift-overflow-12.c.jj 2022-03-01 11:10:= 19.121330974 +0100 > +++ gcc/testsuite/c-c++-common/Wshift-overflow-12.c 2022-03-01 11:22:= 04.561483512 +0100 > @@ -0,0 +1,5 @@ > +/* PR c++/55095 */ > +/* { dg-do compile { target int32 } } */ > +/* { dg-options "-Wshift-overflow=3D2 -fwrapv" } */ > + > +#include "Wshift-overflow-7.c" > > Jakub >