From patchwork Fri Nov 29 11:39:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 295276 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (unknown [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 57F2B2C0333 for ; Fri, 29 Nov 2013 22:43:10 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=qs6wTVfpS2E3andTI QxDYocWS1+c4/SWpya+gTtp3XmQD2Ka8mpEkbr9swGY3Fu19DlCP3RYkJKRKGuYy 5QxpYpPjtOSdW3J1uyxZdDWDxa0PkPRFhpwZwMROkE5Jk0vUlMa05R4zZBoFhsLi zeBdD24+5fiPBE6XMkFj5c5xUg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=wjlQ4xVXsYrqOQbNX+/lr4h jV9Q=; b=yAyivdw8lIaT0eKzhJsDANj5nP6ABhyya2OLpOi+sKWSnB/QCK//9pn i3db5ZQaSZWl+VbEFEh0xfWdLIqJvBnAay2LjPaEAaMBT/AxCd/GI7bNzYSbiwnc sXEpuRivba9A6GrqovLEmq7eY3i5USCDJ5FNZMhMa6DpoBHdereE= Received: (qmail 4707 invoked by alias); 29 Nov 2013 11:39:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 4697 invoked by uid 89); 29 Nov 2013 11:39:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_50, RDNS_NONE, SPF_HELO_PASS, SPF_PASS autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from Unknown (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 29 Nov 2013 11:39:14 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rATBd7Bn023631 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 29 Nov 2013 06:39:07 -0500 Received: from redhat.com (ovpn-116-18.ams2.redhat.com [10.36.116.18]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id rATBd3v1011637 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 29 Nov 2013 06:39:06 -0500 Date: Fri, 29 Nov 2013 12:39:03 +0100 From: Marek Polacek To: Jason Merrill Cc: GCC Patches Subject: Re: [PATCH] Fix up bogus warning (PR sanitizer/59331) Message-ID: <20131129113903.GJ31608@redhat.com> References: <20131128171400.GI31608@redhat.com> <5297DA1B.4080101@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5297DA1B.4080101@redhat.com> User-Agent: Mutt/1.5.20 (2009-06-14) On Thu, Nov 28, 2013 at 07:04:43PM -0500, Jason Merrill wrote: > On 11/28/2013 12:14 PM, Marek Polacek wrote: > > t = fold_build2 (COMPOUND_EXPR, TREE_TYPE (t), > >- ubsan_instrument_vla (input_location, t), t); > >+ ubsan_instrument_vla (input_location, t), > >+ /* Cast to void to prevent bogus warning. */ > >+ build1 (CONVERT_EXPR, void_type_node, t)); > > finish_expr_stmt (t); > > Why do you need the COMPOUND_EXPR at all? Why can't you just do > > t = ubsan_instrument_vla (input_location, t); > > ? You're right, I don't need it at all here. It was needed in the C FE and I lived under wrong impression that I'll need it in the C++ as well. And of course the warning goes away... Thanks a lot. Tested x86_64-unknown-linux-gnu. Ok now? 2013-11-29 Marek Polacek PR sanitizer/59331 cp/ * decl.c (compute_array_index_type): Don't build COMPOUND_EXPR for instrumentation. testsuite/ * g++.dg/ubsan/pr59331.C: New test. * g++.dg/ubsan/cxx1y-vla.C: Enable -Wall -Wno-unused-variable. Disable the -w option. * c-c++-common/ubsan/vla-1.c: Likewise. * c-c++-common/ubsan/vla-2.c: Likewise. * c-c++-common/ubsan/vla-3.c: Don't use the -w option. Marek --- gcc/cp/decl.c.mp5 2013-11-28 16:15:42.606690956 +0100 +++ gcc/cp/decl.c 2013-11-29 12:31:17.032996706 +0100 @@ -8434,8 +8434,7 @@ compute_array_index_type (tree name, tre LE_EXPR rather than LT_EXPR. */ tree t = fold_build2 (PLUS_EXPR, TREE_TYPE (itype), itype, build_one_cst (TREE_TYPE (itype))); - t = fold_build2 (COMPOUND_EXPR, TREE_TYPE (t), - ubsan_instrument_vla (input_location, t), t); + t = ubsan_instrument_vla (input_location, t); finish_expr_stmt (t); } } --- gcc/testsuite/g++.dg/ubsan/pr59331.C.mp5 2013-11-28 16:29:13.967882392 +0100 +++ gcc/testsuite/g++.dg/ubsan/pr59331.C 2013-11-28 17:54:24.125451857 +0100 @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=vla-bound -Wall -Wno-unused-variable" } */ + +void foo(int i) +{ + /* Don't warn here with "value computed is not used". */ + char a[i]; +} --- gcc/testsuite/g++.dg/ubsan/cxx1y-vla.C.mp5 2013-11-28 17:51:51.066755487 +0100 +++ gcc/testsuite/g++.dg/ubsan/cxx1y-vla.C 2013-11-28 18:28:33.411162834 +0100 @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-fsanitize=vla-bound -w -std=c++1y" } */ +/* { dg-options "-fsanitize=vla-bound -Wall -Wno-unused-variable -std=c++1y" } */ /* { dg-shouldfail "ubsan" } */ int --- gcc/testsuite/c-c++-common/ubsan/vla-1.c.mp5 2013-11-28 18:03:32.318664603 +0100 +++ gcc/testsuite/c-c++-common/ubsan/vla-1.c 2013-11-28 18:28:33.410162830 +0100 @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-fsanitize=vla-bound -w" } */ +/* { dg-options "-fsanitize=vla-bound -Wall -Wno-unused-variable" } */ static int bar (void) --- gcc/testsuite/c-c++-common/ubsan/vla-3.c.mp5 2013-11-28 18:04:25.737865780 +0100 +++ gcc/testsuite/c-c++-common/ubsan/vla-3.c 2013-11-28 18:28:33.411162834 +0100 @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-fsanitize=vla-bound -w" } */ +/* { dg-options "-fsanitize=vla-bound" } */ /* Don't instrument the arrays here. */ int --- gcc/testsuite/c-c++-common/ubsan/vla-2.c.mp5 2013-11-28 18:03:54.249748290 +0100 +++ gcc/testsuite/c-c++-common/ubsan/vla-2.c 2013-11-28 18:28:33.410162830 +0100 @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-fsanitize=vla-bound -w" } */ +/* { dg-options "-fsanitize=vla-bound -Wall -Wno-unused-variable" } */ int main (void)