From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 1A875385843F for ; Fri, 29 Oct 2021 08:06:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1A875385843F Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 0A9811FD39; Fri, 29 Oct 2021 08:06:39 +0000 (UTC) Received: from murzim.suse.de (murzim.suse.de [10.160.4.192]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 0427EA3B87; Fri, 29 Oct 2021 08:06:39 +0000 (UTC) Date: Fri, 29 Oct 2021 10:06:38 +0200 (CEST) From: Richard Biener To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Preserve location in gimple_fold_builtin_memset In-Reply-To: <20211029075017.GW304296@tucnak> Message-ID: <81qnp433-5o12-ss80-3260-onq595623264@fhfr.qr> References: <20211029075017.GW304296@tucnak> MIME-Version: 1.0 X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8BIT X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: Fri, 29 Oct 2021 08:06:41 -0000 On Fri, 29 Oct 2021, Jakub Jelinek wrote: > Hi! > > As mentioned yesterday, gimple_fold_builtin_memset doesn't preserve > locus which means e.g. the -Wstringop-overflow warnings are emitted as: > In function 'test_max': > cc1: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] > The function emits up to 2 new statements, but the latter (asgn) is added > through gsi_replace and therefore the locus is copied over from the call. > But store is emitted before the call and optionally the call removed > afterwards, so locus needs to be copied over manually. > > Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for > trunk? OK. Thanks, Richard. > 2021-10-29 Jakub Jelinek > > * gimple-fold.c (gimple_fold_builtin_memset): Copy over location from > call to store. > > * gcc.dg/Wstringop-overflow-62.c: Adjust expected diagnostics. > > --- gcc/gimple-fold.c.jj 2021-10-12 09:36:57.728450483 +0200 > +++ gcc/gimple-fold.c 2021-10-28 12:42:07.638741783 +0200 > @@ -1505,6 +1505,7 @@ gimple_fold_builtin_memset (gimple_stmt_ > var = fold_build2 (MEM_REF, etype, dest, build_int_cst (ptr_type_node, 0)); > gimple *store = gimple_build_assign (var, build_int_cst_type (etype, cval)); > gimple_move_vops (store, stmt); > + gimple_set_location (store, gimple_location (stmt)); > gsi_insert_before (gsi, store, GSI_SAME_STMT); > if (gimple_call_lhs (stmt)) > { > --- gcc/testsuite/gcc.dg/Wstringop-overflow-62.c.jj 2021-10-28 12:24:21.909780099 +0200 > +++ gcc/testsuite/gcc.dg/Wstringop-overflow-62.c 2021-10-28 12:43:52.023273297 +0200 > @@ -223,7 +223,7 @@ void test_max (void) > > char *q = MAX (pi, pj); > > - memset (q, 0, 1); // { dg-warning "writing 1 byte into a region of size 0 " "" { target *-*-* } 0 } > + memset (q, 0, 1); // { dg-warning "writing 1 byte into a region of size 0 " } > memset (q, 0, 2); // { dg-warning "writing 2 bytes into a region of size 0 " } > } > > @@ -345,7 +345,7 @@ void test_max (void) > not reflected in the determaxed offset). */ > char *q = MAX (p1, p2); > > - memset (q, 0, 1); > + memset (q, 0, 1); // { dg-warning "writing 1 byte into a region of size 0 " } > } > > { > > Jakub > > -- Richard Biener SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)