From patchwork Thu Nov 28 17:14:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 294977 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [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 6146D2C008E for ; Fri, 29 Nov 2013 04:14:23 +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:subject:message-id:mime-version:content-type; q=dns; s= default; b=VZKX1HuUJpgSe0WwOXpQSLd1JT5VXz9yzlRD8UA716Auy0NPBdcqC vZfzgy27IUUbDjXddOzMQq6j/+Q4kw6wrQAkZc+0wfFNfbL790jdzBjYxDfw3PS8 bzzOzdqvNea2pUK3NVEDKrmvSh+HxVmhLVlLlOohyGGwvM1U1DGXYw= 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:subject:message-id:mime-version:content-type; s= default; bh=Rw+d91s5ln8R2Ghaj0nQVlPddYM=; b=byXN8nn6WoiV3l5A0tC6 6cY7reRfattFCa3WNs2MIdSuAUm0CYsl2JSAOEGbAPuYoBR5jigPUfRArjnM76/j lXVT0V4CwPLrKOx5RLJ6QjP1dhWvZxHpR+BF0oRu+V2hNezGU8lrDEMa73koEwRm btMBqvmfdvQM9kG6lfG95tM= Received: (qmail 24881 invoked by alias); 28 Nov 2013 17:14:13 -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 24871 invoked by uid 89); 28 Nov 2013 17:14:13 -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; Thu, 28 Nov 2013 17:14:11 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rASHE4k9014949 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 28 Nov 2013 12:14:04 -0500 Received: from redhat.com (ovpn-116-18.ams2.redhat.com [10.36.116.18]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rASHE1Lm012304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 28 Nov 2013 12:14:03 -0500 Date: Thu, 28 Nov 2013 18:14:00 +0100 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] Fix up bogus warning (PR sanitizer/59331) Message-ID: <20131128171400.GI31608@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) We wrongly warned on instrumented VLAs that the size expression's value is not used (with cc1plus only). Unfortunately, this hasn't been detected before due to disabled warnings in the VLA tests. This patch adds a (void) cast to suppress the warning as well as enables the warnings in the VLA tests to detect unwanted warnings next time. Tested x86_64-linux, ok for trunk? 2013-11-28 Marek Polacek PR sanitizer/59331 cp/ * decl.c (compute_array_index_type): Cast the expression to void. 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-28 17:49:44.120202587 +0100 @@ -8435,7 +8435,9 @@ compute_array_index_type (tree name, tre 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); + ubsan_instrument_vla (input_location, t), + /* Cast to void to prevent bogus warning. */ + build1 (CONVERT_EXPR, void_type_node, 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 17:59:49.578744756 +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:03:45.627715609 +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:04:34.796900021 +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:04:07.666798731 +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)