From patchwork Fri Jan 4 03:21:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1020600 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-493369-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="UgofPzfK"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="pG5WTggz"; 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 43W97h6lDqz9s7T for ; Fri, 4 Jan 2019 14:22:07 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=EXFcAxYQskWi5cn/Si2fSa+a5GPIA0LkXs1T0/IxYlipOpvGOD 2Wo1HFx8MK38ce6DcTK5yKrnsTHKiAFXprI9r84vi3lUugWchjhzwE09KgyZkOIV wtmVIwc9as2i4uoMM7jeEUbg0WO+pMHS6sKVjOTx48DgHYF3c2D67lvvY= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=6o/kkncHiemWI/ehr0JJn35fuy8=; b=UgofPzfK00T3HfwM3OIv ChIKda1OETHAKyosvnZWaz5SyV83DukOlHm9K9cwkVe9gQoxgphFXhjjguj2TEXM cHzNZZp4MQe9n32CLmt8CqgmX7Rn9MZMP9rm8dITt3d/kz9bs9RgKCnJh6EKSW7J AWpP3m/43+/aJpLm6Fq0pVU= Received: (qmail 128799 invoked by alias); 4 Jan 2019 03:22:00 -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 128363 invoked by uid 89); 4 Jan 2019 03:21:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1887 X-HELO: mail-qt1-f170.google.com Received: from mail-qt1-f170.google.com (HELO mail-qt1-f170.google.com) (209.85.160.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 04 Jan 2019 03:21:58 +0000 Received: by mail-qt1-f170.google.com with SMTP id n32so39080259qte.11 for ; Thu, 03 Jan 2019 19:21:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=faMw9SA+1FLm8SOz0XhOONGqRKC58W+iYiYbEaJZOeE=; b=pG5WTggz97j1fbFn+tAYhpbGObtISHORzUKuWgEvoNOkqZvAyeUojL89KzwQ1XIZuV kvJb94VB+pRCFH3nankvJu7fa7UClMIldMMFKzvSorl9781YWBptejW699AXRPaRIeEr Wl407ukSc2UoTnW0hF43+KNBCgeNkGSFkbL9pH/RjYsfsvOX/KBLdcvmUN9/Lebiwyuo yPbQIHxhjLLrincamWhbktQnW7ZgfHbQ/5isQoQ3/QwIJe+ziueey7TZZVssp9e669lR wOXzMEmS5bsc2xJiYCEXrKYblJcpBxFzyN8K5TlM58uCeRQza0N2kUfmVUjm6Jd62e+M uanw== Received: from [192.168.0.106] (174-16-101-177.hlrn.qwest.net. [174.16.101.177]) by smtp.gmail.com with ESMTPSA id x11sm21305559qkh.25.2019.01.03.19.21.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Jan 2019 19:21:55 -0800 (PST) To: "gcc-patches@gcc.gnu.org" From: Martin Sebor Subject: [committed] avoid null dereference in maybe_warn_nonstring_arg (PR 88659) Message-ID: <2851d3ff-1be8-7add-3e48-673bd6d84d02@gmail.com> Date: Thu, 3 Jan 2019 20:21:53 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 X-IsSubscribed: yes The attached patch avoids dereferencing a null pointer in maybe_warn_nonstring_arg reported to cause an ICE in pr88659. Committed in r267569 after bootstrapping and regtesting on x86_64-linux. Martin gcc/ChangeLog: PR tree-optimization/88659 * calls.c (maybe_warn_nonstring_arg): Avoid assuming maxlen is set. gcc/testsuite/ChangeLog: PR tree-optimization/88659 * gcc.dg/Wstringop-truncation-6.c: New test. Index: gcc/calls.c =================================================================== --- gcc/calls.c (revision 267568) +++ gcc/calls.c (working copy) @@ -1681,7 +1681,7 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp) bndrng[1] = maxlen; bound = void_type_node; } - else + else if (maxlen) { /* Replace the bound on the operation with the upper bound of the length of the string if the latter is smaller. */ Index: gcc/testsuite/gcc.dg/Wstringop-truncation-6.c =================================================================== --- gcc/testsuite/gcc.dg/Wstringop-truncation-6.c (nonexistent) +++ gcc/testsuite/gcc.dg/Wstringop-truncation-6.c (working copy) @@ -0,0 +1,42 @@ +/* PR tree-optimization/88659 - ICE in maybe_warn_nonstring_arg + { dg-do compile } + { dg-options "-O0 -Wall" } */ + +const char a[5] = "1234"; + +int cst_idx_cst_bnd (void) +{ + return __builtin_strnlen (&a[1], 0); +} + +int var_idx_cst_bnd (void) +{ + int i = 1; + return __builtin_strnlen (&a[i], 0); +} + +int phi_idx_cst_bnd (int i) +{ + return __builtin_strnlen (&a[i ? 1 : 2], 0); +} + +int unk_idx_cst_bnd (int i) +{ + return __builtin_strnlen (&a[i], 0); +} + +int cst_idx_var_bnd (void) +{ + int n = 0; + return __builtin_strnlen (&a[1], n); +} + +int cst_idx_phi_bnd (int n) +{ + return __builtin_strnlen (&a[1], n ? 1 : 2); +} + +int cst_idx_unk_bnd (int n) +{ + return __builtin_strnlen (&a[1], n); +}