From patchwork Tue Aug 13 09:53:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 266763 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 24EDF2C0100 for ; Tue, 13 Aug 2013 19:53:28 +1000 (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:reply-to:mime-version :content-type; q=dns; s=default; b=qurQ356V3IJgeQR5a5FewqqvxtlMS JCva0o9MisJIVAU5jP7RrtFhTDAlGX69UNWdSJTVZ5vr7fIY8etszit2PGjb4YVJ vuu6UqXLaRIs/xdbJ+n7p3ceRZW+zzFvN8BoKC29KX4Z4txvjyif5LGrHHlnRdZF ahXAQc2xZkAsvU= 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:reply-to:mime-version :content-type; s=default; bh=VB3xl/Wz8UhcPMajhJcixYnOtf4=; b=PiS f6v+gRgJD6sEactL2Zp+pVLfdkbrjKfhet76L9iFqOSg5qAO9n4dSsCszgQpHMjA pfKKHzyUbfNyVB5P6+f3TELTMrPpkvrmTR7W/P/LyXDKVWONdheO6RgtHh/0qBaZ 1XklV6JYhsTSfIyTU+c2sqtAALRkdAZ94X719L3w= Received: (qmail 28723 invoked by alias); 13 Aug 2013 09:53:20 -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 28696 invoked by uid 89); 13 Aug 2013 09:53:17 -0000 X-Spam-SWARE-Status: No, score=-7.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 13 Aug 2013 09:53:17 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r7D9rF90022269 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 13 Aug 2013 05:53:16 -0400 Received: from zalov.cz (vpn1-7-152.ams2.redhat.com [10.36.7.152]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r7D9rEw1010619 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 13 Aug 2013 05:53:15 -0400 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.cz (8.14.5/8.14.5) with ESMTP id r7D9rD7Q025431; Tue, 13 Aug 2013 11:53:13 +0200 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r7D9rD4l025430; Tue, 13 Aug 2013 11:53:13 +0200 Date: Tue, 13 Aug 2013 11:53:13 +0200 From: Jakub Jelinek To: Dodji Seketeli Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix asan ICE with strlen instrumentation (PR sanitizer/56417) Message-ID: <20130813095313.GC1814@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Hi! On the following (nonsensical) testcase we ICE because of pointer type mismatch. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.8? 2013-08-13 Jakub Jelinek PR sanitizer/56417 * asan.c (instrument_strlen_call): Fix typo in comment. Use char * type even for the lhs of POINTER_PLUS_EXPR. * gcc.dg/asan/pr56417.c: New test. Jakub --- gcc/asan.c.jj 2013-06-03 18:11:44.000000000 +0200 +++ gcc/asan.c 2013-07-22 22:28:11.467415676 +0200 @@ -1648,7 +1648,7 @@ instrument_mem_region_access (tree base, access to the last byte of the argument; it uses the result of the call to deduce the offset of that last byte. - Upon completion, iff the call has actullay been instrumented, this + Upon completion, iff the call has actually been instrumented, this function returns TRUE and *ITER points to the statement logically following the built-in strlen function call *ITER was initially pointing to. Otherwise, the function returns FALSE and *ITER @@ -1679,10 +1679,10 @@ instrument_strlen_call (gimple_stmt_iter /* Instrument the access to the first byte of str_arg. i.e: _1 = str_arg; instrument (_1); */ + tree cptr_type = build_pointer_type (char_type_node); gimple str_arg_ssa = gimple_build_assign_with_ops (NOP_EXPR, - make_ssa_name (build_pointer_type - (char_type_node), NULL), + make_ssa_name (cptr_type, NULL), str_arg, NULL); gimple_set_location (str_arg_ssa, loc); gimple_stmt_iterator gsi = *iter; @@ -1701,8 +1701,7 @@ instrument_strlen_call (gimple_stmt_iter pointer_plus expr: (_1 + len). */ gimple stmt = gimple_build_assign_with_ops (POINTER_PLUS_EXPR, - make_ssa_name (TREE_TYPE (str_arg), - NULL), + make_ssa_name (cptr_type, NULL), gimple_assign_lhs (str_arg_ssa), len); gimple_set_location (stmt, loc); --- gcc/testsuite/gcc.dg/asan/pr56417.c.jj 2013-07-22 22:34:39.376469948 +0200 +++ gcc/testsuite/gcc.dg/asan/pr56417.c 2013-07-22 21:36:39.000000000 +0200 @@ -0,0 +1,9 @@ +/* PR sanitizer/56417 */ +/* { dg-do compile } */ +/* { dg-options "-w" } */ + +int +foo (void) +{ + return __builtin_strlen (&foo); +}