From patchwork Wed Nov 16 18:49:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 82596 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp319056qge; Wed, 16 Nov 2016 10:50:01 -0800 (PST) X-Received: by 10.99.47.7 with SMTP id v7mr11391742pgv.15.1479322201785; Wed, 16 Nov 2016 10:50:01 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id s28si33003464pfe.176.2016.11.16.10.50.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Nov 2016 10:50:01 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-441704-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-441704-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-441704-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=cBgS6Y97s+UX8lOt3Ly27xoVmvu5dkXI6itUW5CgSpPm7G jTeeLyREtNJzeamFoMh/MZXX/1iDM2Q6Pt799UAow2q44ZVeeoy1S5PFKoHacM+C n7kcL2Mr8do8y9fHu9tjvMr6xdCjAjziOf0DZK6Ad5VBxZwcneK+E32eLcQlw= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=DCMYReA9JDrSTTEnAd9kgXASMkU=; b=HtbtlyW+dtw3jU1booyk YZMd09c+pkaKg18L7FJneDkljwiWcmqseXA/0x6G/Z2yisA3tOTeDJ8IVOArAq1Q HgRxmQohmnpQ8ThzDcX2hlBLXVn7M0TurBldJi07WBPjaYezCEcgDMkWdOUs8mK8 eKf5SIRbT206qSra9Z8Ut5M= Received: (qmail 102211 invoked by alias); 16 Nov 2016 18:49:50 -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 102198 invoked by uid 89); 16 Nov 2016 18:49:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=20161117, 2016-11-17, Following, sk:pratham X-HELO: mail-it0-f49.google.com Received: from mail-it0-f49.google.com (HELO mail-it0-f49.google.com) (209.85.214.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 Nov 2016 18:49:39 +0000 Received: by mail-it0-f49.google.com with SMTP id l8so82311792iti.1 for ; Wed, 16 Nov 2016 10:49:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=541NDIsdD10y6Y1hCDfk/5YsZjTOS6F25oCzPJOqpGw=; b=HEs6gkxUyQaA2kCRn2uDaUldz4mQheHEdysFzQjlN4ZSJzKc6FDHhcyMl2uqnOi6Qn 15i8gkI4kwfTPCUNRTUuXYYQrSVS5c8K1hQPP03DRBOaKBG6uUfNsinC26dQsfggipMR hbxdMVJ+tlN63O26jcgnLEKGCJStn8PXa8GlpIJTGn5QjDrjMCtr3nU9dAgMOURoe8Cr kBXIO8C+UKrkR6yaBJv6ARe6eqdENyWV3CsCXpiRHqaFe3nVPLPJIDNol5I+mRnB1HLb cIOvW7MSoIAijMb2sngyo5ti1ZWm9MNSKEFEmY6NpcjRzlVkQPe3xA6U9ryjrm5ooBB0 eqag== X-Gm-Message-State: ABUngvcorOPvpxbeS3Q2psfyTnq3UBSMDNHOxUBO+62DGAguUuApiAebMuiFCZG2pBxSvAAe9nGxdAAKU6TocdoQ X-Received: by 10.36.200.10 with SMTP id w10mr8655534itf.21.1479322177519; Wed, 16 Nov 2016 10:49:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.12.169 with HTTP; Wed, 16 Nov 2016 10:49:37 -0800 (PST) From: Prathamesh Kulkarni Date: Thu, 17 Nov 2016 00:19:37 +0530 Message-ID: Subject: Fix PR78154 To: gcc Patches , Richard Biener , Martin Sebor X-IsSubscribed: yes Hi Richard, Following your suggestion in PR78154, the patch checks if stmt contains call to memmove (and friends) in gimple_stmt_nonzero_warnv_p and returns true in that case. Bootstrapped+tested on x86_64-unknown-linux-gnu. Cross-testing on arm*-*-*, aarch64*-*-* in progress. Would it be OK to commit this patch in stage-3 ? Thanks, Prathamesh 2016-11-17 Prathamesh Kulkarni * tree-vrp.c (gimple_str_nonzero_warnv_p): New function. (gimple_stmt_nonzero_warnv_p): Call gimple_str_nonzero_warnv_p. testsuite/ * gcc.dg/tree-ssa/pr78154.c: New test-case. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr78154.c b/gcc/testsuite/gcc.dg/tree-ssa/pr78154.c new file mode 100644 index 0000000..d3463f4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr78154.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-evrp-slim" } */ + +void f (void *d, const void *s, __SIZE_TYPE__ n) +{ + if (__builtin_memcpy (d, s, n) == 0) + __builtin_abort (); + + if (__builtin_memmove (d, s, n) == 0) + __builtin_abort (); + + if (__builtin_memset (d, 0, n) == 0) + __builtin_abort (); + + if (__builtin_strcpy (d, s) == 0) + __builtin_abort (); + + if (__builtin_strcat (d, s) == 0) + __builtin_abort (); + + if (__builtin_strncpy (d, s, n) == 0) + __builtin_abort (); + + if (__builtin_strncat (d, s, n) == 0) + __builtin_abort (); +} + +/* { dg-final { scan-tree-dump-not "__builtin_abort" "evrp" } } */ diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index c2a4133..b563a7f 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -1069,6 +1069,34 @@ gimple_assign_nonzero_warnv_p (gimple *stmt, bool *strict_overflow_p) } } +/* Return true if STMT is known to contain call to a string-builtin function + that is known to return nonnull. */ + +static bool +gimple_str_nonzero_warnv_p (gimple *stmt) +{ + if (!is_gimple_call (stmt)) + return false; + + tree fndecl = gimple_call_fndecl (stmt); + if (!fndecl || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL) + return false; + + switch (DECL_FUNCTION_CODE (fndecl)) + { + case BUILT_IN_MEMMOVE: + case BUILT_IN_MEMCPY: + case BUILT_IN_MEMSET: + case BUILT_IN_STRCPY: + case BUILT_IN_STRNCPY: + case BUILT_IN_STRCAT: + case BUILT_IN_STRNCAT: + return true; + default: + return false; + } +} + /* Return true if STMT is known to compute a non-zero value. If the return value is based on the assumption that signed overflow is undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't change @@ -1097,7 +1125,7 @@ gimple_stmt_nonzero_warnv_p (gimple *stmt, bool *strict_overflow_p) lookup_attribute ("returns_nonnull", TYPE_ATTRIBUTES (gimple_call_fntype (stmt)))) return true; - return gimple_alloca_call_p (stmt); + return gimple_alloca_call_p (stmt) || gimple_str_nonzero_warnv_p (stmt); } default: gcc_unreachable ();