From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 3D468383A600 for ; Tue, 14 Jun 2022 10:49:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3D468383A600 Received: by mail-wr1-x42a.google.com with SMTP id c21so10737172wrb.1 for ; Tue, 14 Jun 2022 03:49:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M/3ePKa5f+zMSy9nhi1KAF0qkM8JzTwSq3B1jARKAiA=; b=2YSADGcPvoBs2Pc5kZgnfxMx0hT1DDUG5WC/kDN/ZKqUDKaKlghdJpA33HGj5KBSOb PzZB89wTf2fX1N3jVn8zwkwQgWM+YZTd1DHopichW//0fHBNbSLgWugPZvMnkcWrrwOU 0/WMYbgf4EmFVSCYS12vl2ottt6unXQ1WRypnmio/7IGN1wXuy5WEJpa2HLjSr4yMshh ScE35GJVchiZw27MBugarXJ8QtadgymuZcYEWkk9oQ70h3y0zQtttutnB8xI+iN7eOjq gcFQjeF9otCfQHpQ9J+hFKP5y3rFu1++olngNxH4UPLrYup3uAJUWyHMjlRCvE3DPNBW 5ppQ== X-Gm-Message-State: AJIora+hfrExwBIlezFm52zncZUrM3m4fanTy+EAeyIChszDI+w0fit8 4ZEuhi9K35XRMmyuNmgjPUeRtw== X-Google-Smtp-Source: AGRyM1sVR0XNK+TJTz/aFq99DXpU0cxwCAxhXP+q6fTzdvQKwgIAXyLPXK4meXlMEDdeaGL2Cfjefw== X-Received: by 2002:a5d:69c9:0:b0:213:aba0:68e4 with SMTP id s9-20020a5d69c9000000b00213aba068e4mr4183047wrw.439.1655203782839; Tue, 14 Jun 2022 03:49:42 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:bf38:f508:6f40:de1d]) by smtp.gmail.com with ESMTPSA id p1-20020a05600c204100b0039aef592ca0sm12265347wmg.35.2022.06.14.03.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 03:49:42 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: Richard Biener Cc: Martin Sebor , gcc-patches@gcc.gnu.org, GCC Patches Subject: Re: [PATCH] Do not erase warning data in gimple_set_location Date: Tue, 14 Jun 2022 12:49:40 +0200 Message-ID: <2514895.Lt9SDvczpP@fomalhaut> In-Reply-To: References: <7390933.EvYhyI6sBW@fomalhaut> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart4193594.ejJDZkT8p0" Content-Transfer-Encoding: 7Bit X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Tue, 14 Jun 2022 10:49:46 -0000 This is a multi-part message in MIME format. --nextPart4193594.ejJDZkT8p0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" > Hmm, I think instead of special-casing UNKNOWN_LOCATION > what gimple_set_location should probably do is either not copy > warnings at all or union them. Btw, gimple_set_location also > removes a previously set BLOCK (but gimple_set_block preserves > the location locus and diagnostic override). >=20 > So I'd be tempted to axe the copy_warning () completely here.=20 The first thing I tried, but it regressed the original testcase IIRC. Even my minimal patch manages to break bootstrap on ARM: buildslave/workspace/tcwg_gnu_1/abe/snapshots/gcc.git~master/libcpp/lex.cc: 1523:9: error: pointer used after =E2=80=98void operator delete(void*, std:= :size_t)=E2=80=99=20 [-Werror=3Duse-after-free] # 00:31:04 make[3]: *** [Makefile:227: lex.o] Error 1 # 00:31:04 make[2]: *** [Makefile:9527: all-stage3-libcpp] Error 2 # 00:31:35 make[1]: *** [Makefile:25887: stage3-bubble] Error 2 # 00:31:35 make: *** [Makefile:1072: all] Error 2 /* Don't warn for cases like when a cdtor returns 'this' on ARM. */ else if (warning_suppressed_p (var, OPT_Wuse_after_free)) return; because warning-control.cc:copy_warning also clobbers the warning data of t= he=20 destination. We have in cp/decl.cc:maybe_return_this the lines: /* Return the address of the object. */ tree val =3D DECL_ARGUMENTS (current_function_decl); suppress_warning (val, OPT_Wuse_after_free); =2DWuse-after-free is suppressed for the location of VAL and the TREE_NO_WA= RNING=20 bit set on it. But other expressions may have the same location as VAL and= =20 the TREE_NO_WARNING bit _not_ set, so when you call copy_warning (expr, exp= r)=20 (we do that a lot after failed folding) for them, copy_warning erases the=20 warning data of the location. I have installed the obvious fixlet after testing on x86-64/Linux, but the= =20 decoupling between TREE_NO_WARNING bit and location looks a bit problematic. * warning-control.cc (copy_warning) [generic version]: Do not erase the warning data of the destination location when the no-warning bit is not set on the source. (copy_warning) [tree version]: Return early if TO is equal to FROM. (copy_warning) [gimple version]: Likewise. testsuite/ * g++.dg/warn/Wuse-after-free5.C: New test. =2D-=20 Eric Botcazou --nextPart4193594.ejJDZkT8p0 Content-Disposition: attachment; filename="p.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="utf-8"; name="p.diff" diff --git a/gcc/warning-control.cc b/gcc/warning-control.cc index 0cbb4f079fa..7e9e701cfbe 100644 --- a/gcc/warning-control.cc +++ b/gcc/warning-control.cc @@ -191,7 +191,7 @@ void copy_warning (ToType to, FromType from) { const location_t to_loc = get_location (to); - bool supp = get_no_warning_bit (from); + const bool supp = get_no_warning_bit (from); nowarn_spec_t *from_spec = get_nowarn_spec (from); if (RESERVED_LOCATION_P (to_loc)) @@ -209,7 +209,7 @@ void copy_warning (ToType to, FromType from) nowarn_spec_t tem = *from_spec; nowarn_map->put (to_loc, tem); } - else + else if (supp) { if (nowarn_map) nowarn_map->remove (to_loc); @@ -226,6 +226,8 @@ void copy_warning (ToType to, FromType from) void copy_warning (tree to, const_tree from) { + if (to == from) + return; copy_warning(to, from); } @@ -250,5 +252,7 @@ copy_warning (gimple *to, const_tree from) void copy_warning (gimple *to, const gimple *from) { + if (to == from) + return; copy_warning(to, from); } --nextPart4193594.ejJDZkT8p0 Content-Disposition: attachment; filename="Wuse-after-free5.C" Content-Transfer-Encoding: 7Bit Content-Type: text/x-c++src; charset="utf-8"; name="Wuse-after-free5.C" // Check the suppression of -Wuse-after-free for destructors on ARM // { dg-do compile } // { dg-options "-Wuse-after-free" } struct range_label { virtual ~range_label(); }; struct unpaired_bidi_rich_location { struct custom_range_label : range_label {}; unpaired_bidi_rich_location(int); custom_range_label m_custom_label; }; void maybe_warn_bidi_on_close() { unpaired_bidi_rich_location(0); } --nextPart4193594.ejJDZkT8p0--