From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18073 invoked by alias); 4 May 2015 18:16:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 18059 invoked by uid 89); 4 May 2015 18:16:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 04 May 2015 18:16:47 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t44IGjBM020615 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 4 May 2015 14:16:46 -0400 Received: from tucnak.zalov.cz (ovpn-116-89.ams2.redhat.com [10.36.116.89]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t44IGhBI002580 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 4 May 2015 14:16:44 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.9/8.14.9) with ESMTP id t44IGfpP030955; Mon, 4 May 2015 20:16:42 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.9/8.14.9/Submit) id t44IGevH030954; Mon, 4 May 2015 20:16:40 +0200 Date: Mon, 04 May 2015 18:16:00 -0000 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ubsan non-call-exceptions ICE (PR tree-optimization/65984) Message-ID: <20150504181640.GF1751@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2015-05/txt/msg00245.txt.bz2 Hi! The code I've added in r217755 was assuming that stmt_could_throw_p memory read will always end a bb, but that is clearly not the case. Thus, the following patch uses stmt_ends_bb_p instead. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/5? 2015-05-04 Jakub Jelinek PR tree-optimization/65984 * ubsan.c: Include tree-cfg.h. (instrument_bool_enum_load): Use stmt_ends_bb_p instead of stmt_could_throw_p test, rename can_throw variable to ends_bb. * c-c++-common/ubsan/pr65984.c: New test. --- gcc/ubsan.c.jj 2015-04-09 21:49:59.000000000 +0200 +++ gcc/ubsan.c 2015-05-04 17:17:34.273661884 +0200 @@ -87,6 +87,7 @@ along with GCC; see the file COPYING3. #include "builtins.h" #include "tree-object-size.h" #include "tree-eh.h" +#include "tree-cfg.h" /* Map from a tree to a VAR_DECL tree. */ @@ -1420,7 +1421,7 @@ instrument_bool_enum_load (gimple_stmt_i || TREE_CODE (gimple_assign_lhs (stmt)) != SSA_NAME) return; - bool can_throw = stmt_could_throw_p (stmt); + bool ends_bb = stmt_ends_bb_p (stmt); location_t loc = gimple_location (stmt); tree lhs = gimple_assign_lhs (stmt); tree ptype = build_pointer_type (TREE_TYPE (rhs)); @@ -1432,7 +1433,7 @@ instrument_bool_enum_load (gimple_stmt_i tree mem = build2 (MEM_REF, utype, gimple_assign_lhs (g), build_int_cst (atype, 0)); tree urhs = make_ssa_name (utype); - if (can_throw) + if (ends_bb) { gimple_assign_set_lhs (stmt, urhs); g = gimple_build_assign (lhs, NOP_EXPR, urhs); @@ -1469,7 +1470,7 @@ instrument_bool_enum_load (gimple_stmt_i gimple_set_location (g, loc); gsi_insert_after (gsi, g, GSI_NEW_STMT); - if (!can_throw) + if (!ends_bb) { gimple_assign_set_rhs_with_ops (&gsi2, NOP_EXPR, urhs); update_stmt (stmt); --- gcc/testsuite/c-c++-common/ubsan/pr65984.c.jj 2015-05-04 14:16:59.655378975 +0200 +++ gcc/testsuite/c-c++-common/ubsan/pr65984.c 2015-05-04 17:19:55.875447821 +0200 @@ -0,0 +1,23 @@ +/* PR tree-optimization/65984 */ +/* { dg-do compile } */ +/* { dg-options "-fnon-call-exceptions -fsanitize=bool,enum" } */ + +#ifndef __cplusplus +#define bool _Bool +#endif + +enum E { E0, E1, E2 }; +enum E e[2]; +bool *b; + +int +foo (int i) +{ + return e[i]; +} + +int +bar (int i) +{ + return b[i]; +} Jakub