From patchwork Fri Sep 14 19:51:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 970068 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-485681-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=hotmail.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="xHT8N5H4"; 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 42BmNq2chJz9s3l for ; Sat, 15 Sep 2018 05:51:21 +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:subject:date:message-id:content-type:mime-version; q=dns; s= default; b=KTX+nfrD+hTdAXVP73sQ3g+rX8KU9l3e3QRUQlhcG+GbfCuyTh9vC tYTiCbvwEn1kYwbWpygQ7KTUqqyB3+qlZcWtN4rFWRcrj91xpbcrqLTucVHbc++z Mj0UMf63SBao6soXQZYwZFcEwM4UdlgNRbfNwNoLZfRPW7W09luflY= 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:subject:date:message-id:content-type:mime-version; s= default; bh=WbjqKjd+fNNd3TNwZP9DRmTjPi8=; b=xHT8N5H4mINDHr5uDUYs tV1cd98s6JG3dIkchzIK7ycHsv711bcY4JneRHl58+GYclO30Fodm7CNGSM5hrWh d5IGAXRXys9eHlt3ygOIyLG/wxvsdPwGohZ2X0B99pHA2qHRYm1IA93/5/nO7mH6 /n7shbjc42nFjuzoDQDQlWA= Received: (qmail 89669 invoked by alias); 14 Sep 2018 19:51:14 -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 89651 invoked by uid 89); 14 Sep 2018 19:51:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.8 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2411 X-HELO: EUR02-VE1-obe.outbound.protection.outlook.com Received: from mail-oln040092069064.outbound.protection.outlook.com (HELO EUR02-VE1-obe.outbound.protection.outlook.com) (40.92.69.64) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Sep 2018 19:51:11 +0000 Received: from AM5EUR02FT045.eop-EUR02.prod.protection.outlook.com (10.152.8.59) by AM5EUR02HT194.eop-EUR02.prod.protection.outlook.com (10.152.9.227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.14; Fri, 14 Sep 2018 19:51:08 +0000 Received: from VI1PR0701MB2862.eurprd07.prod.outlook.com (10.152.8.60) by AM5EUR02FT045.mail.protection.outlook.com (10.152.9.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.14 via Frontend Transport; Fri, 14 Sep 2018 19:51:08 +0000 Received: from VI1PR0701MB2862.eurprd07.prod.outlook.com ([fe80::854a:328:c580:5fb9]) by VI1PR0701MB2862.eurprd07.prod.outlook.com ([fe80::854a:328:c580:5fb9%3]) with mapi id 15.20.1143.014; Fri, 14 Sep 2018 19:51:08 +0000 From: Bernd Edlinger To: "gcc-patches@gcc.gnu.org" , Jeff Law , Martin Sebor Subject: [PATCH] Resolve the TODO in fold_builtin_strlen Date: Fri, 14 Sep 2018 19:51:08 +0000 Message-ID: received-spf: None (protection.outlook.com: hotmail.de does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=bernd.edlinger@hotmail.de; MIME-Version: 1.0 Hi, this resolves the TODO I left in fold_builtin_strlen by adding some test cases that fail without the c_strlen call with the TODO comment and pass when the additional c_strlen call is done. Bootstrapped and reg-tested on x86_64-pc-linux-gnu. Is it OK for trunk? Thanks Bernd. 2018-09-14 Bernd Edlinger * builtins.c (fold_builtin_strlen): Remove TODO comment. testsuite: 2018-09-14 Bernd Edlinger * gcc.dg/warn-strlen-no-nul.c: Add some missing test cases. diff -Npur gcc/builtins.c gcc/builtins.c --- gcc/builtins.c 2018-08-30 08:21:13.000000000 +0200 +++ gcc/builtins.c 2018-08-30 21:46:11.155211333 +0200 Index: gcc/builtins.c =================================================================== --- gcc/builtins.c (revision 264318) +++ gcc/builtins.c (working copy) @@ -8417,7 +8417,7 @@ fold_builtin_strlen (location_t loc, tree type, tr return fold_convert_loc (loc, type, len); if (!nonstr) - c_strlen (arg, 1, &nonstr); /* TODO: add test coverage here. */ + c_strlen (arg, 1, &nonstr); if (nonstr) { Index: gcc/testsuite/gcc.dg/warn-strlen-no-nul.c =================================================================== --- gcc/testsuite/gcc.dg/warn-strlen-no-nul.c (revision 264318) +++ gcc/testsuite/gcc.dg/warn-strlen-no-nul.c (working copy) @@ -9,6 +9,7 @@ const char a[5] = "12345"; /* { dg-message "decl int v0 = 0; int v1 = 1; +volatile int v2; void sink (int, ...); @@ -117,10 +118,8 @@ T (v0 ? b[i0] : &b[i3][i0] + i1); /* { dg-warni T (v0 ? b[i0] : &b[i3][i0] + i1); /* { dg-warning "nul" } */ T (v0 ? b[i1] : &b[i3][i1] + v0); /* { dg-warning "nul" } */ -/* It's possible to detect the missing nul in the following two - expressions but GCC doesn't do it yet. */ -T (v0 ? &b[3][1] + v0 : b[2]); /* { dg-warning "nul" "bug" } */ -T (v0 ? &b[3][v0] : &b[3][v1]); /* { dg-warning "nul" "bug" } */ +T (v0 ? &b[3][1] + v0 : b[2]); /* { dg-warning "nul" } */ +T (v0 ? &b[3][v0] : &b[3][v1]); /* { dg-warning "nul" } */ struct A { char a[5], b[5]; }; @@ -299,3 +298,7 @@ T (v0 ? &ba[3].a[1].a[1] : ba[0].a[0].a); /* T (v0 ? ba[0].a[0].a : ba[0].a[1].b); T (v0 ? ba[0].a[1].b : ba[0].a[0].a); + +T (v2 ? b[1] : &b[3][1] + v2); /* { dg-warning "nul" } */ +T (v2 ? &b[3][1] + v2 : b[2]); /* { dg-warning "nul" } */ +T (v2 ? &b[3][v2] : &b[2][v2]); /* { dg-warning "nul" } */