From patchwork Tue Nov 27 18:40:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 202280 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]) by ozlabs.org (Postfix) with SMTP id B5FAD2C0093 for ; Wed, 28 Nov 2012 05:41:19 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1354646480; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=n8qEhInbaHujVcMgMnuo 7ezFCx4=; b=q8tmEkzQW3t+zN4vd8GoFErG9aEYvRBtSujVH3/ySxbewV70p6La BVkRvFWWsJgf0hduq9mUUjDquGVR8OCsFqirdJkQeR8BmfhFeEb1aIPAfqdbQg1Y MvUSDzPFYSS5ZuKOYBjSagtcC3FfKqciNTeHO4YzWFk87hYInbv1g+A= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=ncZOZ3p+Hk5oXRyEB40kBKL2LmYrZAXkP8TKxcQV7LvbQVozUGQ9RznNH1W7o0 ig8QCEBJcSWpouZy3OJqG7o4tTLfzrpX1tSTb1A6LpTn2YQUVUfZe662uuFhnE3A il9EfcsWVHN3CQJKw8jLVVZNlnvEVZ5PVvdzk9g1YKlLM=; Received: (qmail 3533 invoked by alias); 27 Nov 2012 18:41:12 -0000 Received: (qmail 3415 invoked by uid 22791); 27 Nov 2012 18:41:10 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_TM X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 27 Nov 2012 18:40:58 +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 qARIendQ006866 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 27 Nov 2012 13:40:58 -0500 Received: from zalov.redhat.com (vpn1-7-172.ams2.redhat.com [10.36.7.172]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qARIeTpX023014 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 27 Nov 2012 13:40:45 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id qARIeSl0029302; Tue, 27 Nov 2012 19:40:28 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id qARIeSON029301; Tue, 27 Nov 2012 19:40:28 +0100 Date: Tue, 27 Nov 2012 19:40:28 +0100 From: Jakub Jelinek To: Dodji Seketeli Cc: gcc-patches@gcc.gnu.org Subject: [asan] Fix some asan ICEs Message-ID: <20121127184028.GE2315@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! This fixes a couple of asan ICEs found while running make check with RUNTESTFLAGS='unix/-fsanitize=address'. The last two hunks fix ICEs while instrumenting atomics with non-standard sizes, those are always turned into library calls, and the first argument is the length, not a pointer. The other issues fixed are if one uses non-prototyped builtins with wrong types of arguments, it can result in verify_gimple ICEs (e.g. if last argument to non-prototyped memcmp is int), or worse (say if instead of pointer it is a double). The patch just punts for bogus builtins, and when len is integral, but not of the right type, it casts it to the right type (for constant just builds the right offset as constant, otherwise adds extra stmts as needed). Ok for trunk? 2012-11-27 Jakub Jelinek * asan.c (instrument_mem_region_access): Don't instrument if base doesn't have pointer type or len integral type. Add cast if len doesn't have size_t compatible type. (instrument_builtin_call): Don't instrument BUILT_IN_ATOMIC_LOAD, BUILT_IN_ATOMIC_TEST_AND_SET, BUILT_IN_ATOMIC_CLEAR, BUILT_IN_ATOMIC_EXCHANGE, BUILT_IN_ATOMIC_COMPARE_EXCHANGE and BUILT_IN_ATOMIC_STORE. Jakub --- gcc/asan.c.jj 2012-11-23 15:21:49.000000000 +0100 +++ gcc/asan.c 2012-11-27 17:37:10.948281831 +0100 @@ -849,7 +849,9 @@ instrument_mem_region_access (tree base, gimple_stmt_iterator *iter, location_t location, bool is_store) { - if (integer_zerop (len)) + if (!POINTER_TYPE_P (TREE_TYPE (base)) + || !INTEGRAL_TYPE_P (TREE_TYPE (len)) + || integer_zerop (len)) return; gimple_stmt_iterator gsi = *iter; @@ -902,20 +904,41 @@ instrument_mem_region_access (tree base, /* offset = len - 1; */ len = unshare_expr (len); - gimple offset = - gimple_build_assign_with_ops (TREE_CODE (len), - make_ssa_name (TREE_TYPE (len), NULL), - len, NULL); - gimple_set_location (offset, location); - gsi_insert_before (&gsi, offset, GSI_NEW_STMT); - - offset = - gimple_build_assign_with_ops (MINUS_EXPR, - make_ssa_name (size_type_node, NULL), - gimple_assign_lhs (offset), - build_int_cst (size_type_node, 1)); - gimple_set_location (offset, location); - gsi_insert_after (&gsi, offset, GSI_NEW_STMT); + tree offset; + gimple_seq seq = NULL; + if (TREE_CODE (len) == INTEGER_CST) + offset = fold_build2 (MINUS_EXPR, size_type_node, + fold_convert (size_type_node, len), + build_int_cst (size_type_node, 1)); + else + { + gimple g; + tree t; + + if (TREE_CODE (len) != SSA_NAME) + { + t = make_ssa_name (TREE_TYPE (len), NULL); + g = gimple_build_assign_with_ops (TREE_CODE (len), t, len, NULL); + gimple_set_location (g, location); + gimple_seq_add_stmt_without_update (&seq, g); + len = t; + } + if (!useless_type_conversion_p (size_type_node, TREE_TYPE (len))) + { + t = make_ssa_name (size_type_node, NULL); + g = gimple_build_assign_with_ops (NOP_EXPR, t, len, NULL); + gimple_set_location (g, location); + gimple_seq_add_stmt_without_update (&seq, g); + len = t; + } + + t = make_ssa_name (size_type_node, NULL); + g = gimple_build_assign_with_ops (MINUS_EXPR, t, len, + build_int_cst (size_type_node, 1)); + gimple_set_location (g, location); + gimple_seq_add_stmt_without_update (&seq, g); + offset = gimple_assign_lhs (g); + } /* _1 = base; */ base = unshare_expr (base); @@ -924,14 +947,16 @@ instrument_mem_region_access (tree base, make_ssa_name (TREE_TYPE (base), NULL), base, NULL); gimple_set_location (region_end, location); - gsi_insert_after (&gsi, region_end, GSI_NEW_STMT); + gimple_seq_add_stmt_without_update (&seq, region_end); + gsi_insert_seq_before (&gsi, seq, GSI_SAME_STMT); + gsi_prev (&gsi); /* _2 = _1 + offset; */ region_end = gimple_build_assign_with_ops (POINTER_PLUS_EXPR, make_ssa_name (TREE_TYPE (base), NULL), gimple_assign_lhs (region_end), - gimple_assign_lhs (offset)); + offset); gimple_set_location (region_end, location); gsi_insert_after (&gsi, region_end, GSI_NEW_STMT); @@ -1089,7 +1114,6 @@ instrument_builtin_call (gimple_stmt_ite These are handled differently from the classical memory memory access builtins above. */ - case BUILT_IN_ATOMIC_LOAD: case BUILT_IN_ATOMIC_LOAD_1: case BUILT_IN_ATOMIC_LOAD_2: case BUILT_IN_ATOMIC_LOAD_4: @@ -1192,23 +1216,18 @@ instrument_builtin_call (gimple_stmt_ite case BUILT_IN_SYNC_LOCK_RELEASE_8: case BUILT_IN_SYNC_LOCK_RELEASE_16: - case BUILT_IN_ATOMIC_TEST_AND_SET: - case BUILT_IN_ATOMIC_CLEAR: - case BUILT_IN_ATOMIC_EXCHANGE: case BUILT_IN_ATOMIC_EXCHANGE_1: case BUILT_IN_ATOMIC_EXCHANGE_2: case BUILT_IN_ATOMIC_EXCHANGE_4: case BUILT_IN_ATOMIC_EXCHANGE_8: case BUILT_IN_ATOMIC_EXCHANGE_16: - case BUILT_IN_ATOMIC_COMPARE_EXCHANGE: case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_1: case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_2: case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_4: case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_8: case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_16: - case BUILT_IN_ATOMIC_STORE: case BUILT_IN_ATOMIC_STORE_1: case BUILT_IN_ATOMIC_STORE_2: case BUILT_IN_ATOMIC_STORE_4: