From patchwork Wed Apr 11 07:48:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Krebbel X-Patchwork-Id: 897069 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-476180-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="XUxXpzHF"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40Lbkn2Swlz9s27 for ; Wed, 11 Apr 2018 17:48:31 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=LYriDsvqZPXM /WMpFweb9643JQI61xkBmJmR0Lq/IfIBsx1Bc0rFChoAKcyETTLcEkDuRDPf8Goq g6SsbFT1DA95z+ZV70KTa/SjsniCXmPKamHlDRqGdAhh96f54EOhwuEL/Z3vXhyG bkSb1MrlQnaEL7MQaJHw7ay2IgoxsXw= 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:from :to:cc:subject:date:message-id; s=default; bh=bBKElxMYHGVAR8yOc3 RQ8tpUyeU=; b=XUxXpzHFNOxksAl0zBHvPK4i7ZQKRXxJy50qlnWNklbpyDQhjY 8jmlHi3PygcQXy9f62CoGAyBzN8LOUVaP1qKd7dXVQDW0O2tK/6rFsAlCLSldWbs j6Fi17dMPncAOA1kCSmE3a57ZGV8L71hGufBnA8SSEyKct+6AOTJ06ERY= Received: (qmail 5659 invoked by alias); 11 Apr 2018 07:48:21 -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 5551 invoked by uid 89); 11 Apr 2018 07:48:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Apr 2018 07:48:11 +0000 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3B7is0a094575 for ; Wed, 11 Apr 2018 03:48:10 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 2h9drx1e52-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Wed, 11 Apr 2018 03:48:09 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 11 Apr 2018 08:48:08 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 11 Apr 2018 08:48:06 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3B7m6Th52297850; Wed, 11 Apr 2018 07:48:06 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 394E24C044; Wed, 11 Apr 2018 08:40:46 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1A4E34C040; Wed, 11 Apr 2018 08:40:46 +0100 (BST) Received: from maggie.boeblingen.de.ibm.com (unknown [9.152.212.134]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 11 Apr 2018 08:40:46 +0100 (BST) From: Andreas Krebbel To: gcc-patches@gcc.gnu.org Cc: msebor@gmail.com Subject: [PATCH] Invoke maybe_warn_nonstring_arg for strcpy/stpcpy builtins. Date: Wed, 11 Apr 2018 09:48:05 +0200 X-TM-AS-GCONF: 00 x-cbid: 18041107-0040-0000-0000-0000042CEFC7 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041107-0041-0000-0000-0000263101DD Message-Id: <20180411074805.17572-1-krebbel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-04-11_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804110076 X-IsSubscribed: yes c-c++-common/attr-nonstring-3.c fails on IBM Z. The reason appears to be that we provide builtin implementations for strcpy and stpcpy. The warnings currently will only be emitted when expanding these as normal calls. Bootstrapped and regression tested on x86_64 and s390x. Ok? gcc/ChangeLog: 2018-04-11 Andreas Krebbel * builtins.c (expand_builtin_strcpy): Invoke maybe_warn_nonstring_arg. (expand_builtin_stpcpy): Likewise. --- gcc/builtins.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gcc/builtins.c b/gcc/builtins.c index ababee5..83bbb70 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -3770,6 +3770,12 @@ expand_builtin_strcpy (tree exp, rtx target) tree dest = CALL_EXPR_ARG (exp, 0); tree src = CALL_EXPR_ARG (exp, 1); + /* Check to see if the argument was declared attribute nonstring + and if so, issue a warning since at this point it's not known + to be nul-terminated. */ + tree fndecl = get_callee_fndecl (exp); + maybe_warn_nonstring_arg (fndecl, exp); + if (warn_stringop_overflow) { tree destsize = compute_objsize (dest, warn_stringop_overflow - 1); @@ -3828,6 +3834,12 @@ expand_builtin_stpcpy (tree exp, rtx target, machine_mode mode) tree len, lenp1; rtx ret; + /* Check to see if the argument was declared attribute nonstring + and if so, issue a warning since at this point it's not known + to be nul-terminated. */ + tree fndecl = get_callee_fndecl (exp); + maybe_warn_nonstring_arg (fndecl, exp); + /* Ensure we get an actual string whose length can be evaluated at compile-time, not an expression containing a string. This is because the latter will potentially produce pessimized code