From patchwork Thu Jun 13 19:10:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1115571 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-502926-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="Jo+i6sNX"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="CF+GifUF"; 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 45PtcH4ntmz9s6w for ; Fri, 14 Jun 2019 05:10:38 +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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=IphyUa13vGQ6lcyuA1MwnyfST8oEwvd3sb6vfvWQlxYqiXgczd uHprWZlABW/o0s5cBO17bMGZ5WdRjX3UWRpbt6Ri1k4rLx/sBMzldt9uZ3dCeyyP 1PoF+2SiSeMv1Ab773vRAliS+cTTaQZIT4emHAG72ysZXAvPTkLN6CSFs= 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=2aHW7t200qXQVH3IpfL15EjrBgo=; b=Jo+i6sNX3uCEoqE5V6Tk 3L+7sFrtXcB2guyMGrZkCgLUkhqwaD2bENDVQI6QxCr90adLwxIWWFS7xfAuQfn+ 8LzOUUDF+O7IuXJVKabsISFZ+LpwdaCyEc108Y0vsdsdESCByEFLCl8pSeV1d9oy bH8+alNe0khEC3CYx0caTb8= Received: (qmail 5707 invoked by alias); 13 Jun 2019 19:10:30 -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 5697 invoked by uid 89); 13 Jun 2019 19:10:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-12.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-qt1-f178.google.com Received: from mail-qt1-f178.google.com (HELO mail-qt1-f178.google.com) (209.85.160.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Jun 2019 19:10:28 +0000 Received: by mail-qt1-f178.google.com with SMTP id h21so23825507qtn.13 for ; Thu, 13 Jun 2019 12:10:28 -0700 (PDT) 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=C4rDogqhDQiR3CKyg2vNuY2g/1IdrRt0qMhw/Aw6OqM=; b=CF+GifUFgW4mgCHTR1ABh7af/WQ9D/nBSP8AYkZmwmpQPxJHn4sE6R+I8DBS9W/rNG kS/4nIRn2Tf7CB7kpdR5tWpQoRwU2SO3PdjIhHV8Levj4LN1UQ88mXVe73Ap21m38zIZ nCHcAdmox1EP1qRl2wPjeIs+GjOeJV+xgQlYVuDby/g4gpiZa/UHQuJr839S3nm7+Kc2 6V3da+v0CZeBjeMDgm0vzGnnzCY94ZmqgWQozBYFOISx300bN3jJWFhPGufm8GhUselK K9LtkQpmKTOra8DCp7mkMujsl4bYFEY+e6x1v0VcXI505n75S7mmcRPdXWdamYvqGvuO z4mQ== Received: from [192.168.0.41] (75-166-109-122.hlrn.qwest.net. [75.166.109.122]) by smtp.gmail.com with ESMTPSA id k40sm382832qta.50.2019.06.13.12.10.25 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jun 2019 12:10:25 -0700 (PDT) To: gcc-patches From: Martin Sebor Subject: [PATCH] avoid ice due to inconsistent argument types to fold_build (PR 90662) Message-ID: Date: Thu, 13 Jun 2019 13:10:24 -0600 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 Attached is a fix for the fold_build call with inconsistent argument types introduced in a recent commit of mine. Tested on x86_64-linux. Martin PR tree-optimization/90662 - strlen of a string in a vla plus offset not folded gcc/ChangeLog: PR tree-optimization/90662 * tree-ssa-strlen.c (get_stridx): Convert fold_build2 operands to the same type. gcc/testsuite/ChangeLog: PR tree-optimization/90662 * gcc.dg/pr90866-2.c: New test. * gcc.dg/pr90866.c: Ditto. Index: gcc/testsuite/gcc.dg/pr90866-2.c =================================================================== --- gcc/testsuite/gcc.dg/pr90866-2.c (nonexistent) +++ gcc/testsuite/gcc.dg/pr90866-2.c (working copy) @@ -0,0 +1,24 @@ +/* PR tree-optimization/90866 - ICE in fold_binary_loc, at fold-const.c:9827 + { dg-do compile } + { dg-options "-O2 -fsanitize=thread" } */ + +typedef enum { a } b; +typedef struct { + int c[0]; +} d; +typedef struct { + int *data; +} e; +typedef struct { + e buffer; +} f; +int g, h; +int i(); +int i(f *j, d *k, b l, int m) { + if (l) + if (m) { + h = j->buffer.data[0]; + k->c[g] = k->c[g] * 8; + } + return 0; +} Index: gcc/testsuite/gcc.dg/pr90866.c =================================================================== --- gcc/testsuite/gcc.dg/pr90866.c (nonexistent) +++ gcc/testsuite/gcc.dg/pr90866.c (working copy) @@ -0,0 +1,18 @@ +/* PR tree-optimization/90866 - ICE in fold_binary_loc, at fold-const.c:9827 + { dg-do compile } + { dg-options "-O3 -Wall -fno-tree-loop-optimize" } */ + +int a[1024], b[1024]; + +void f (void) +{ + int i = 0; + for ( ; ; i++) + { + b[16] = a[i * 16 + 10]; + b[i * 16 + 11] = a[i * 16 + 11] * 3; + b[i * 16 + 12] = a[i * 16 + 12] * 4; + b[i * 16 + 13] = a[i * 16 + 13] * 4; + b[i * 16 + 14] = a[i * 16 + 14] * 3; + } +} Index: gcc/tree-ssa-strlen.c =================================================================== --- gcc/tree-ssa-strlen.c (revision 272252) +++ gcc/tree-ssa-strlen.c (working copy) @@ -322,11 +322,17 @@ get_stridx (tree exp) if (TREE_CODE (ptr) == ARRAY_REF) { off = TREE_OPERAND (ptr, 1); - /* Scale the array index by the size of the element - type (normally 1 for char). */ - off = fold_build2 (MULT_EXPR, TREE_TYPE (off), off, - eltsize); ptr = TREE_OPERAND (ptr, 0); + if (!integer_onep (eltsize)) + { + /* Scale the array index by the size of the element + type in the rare case that it's greater than + the typical 1 for char, making sure both operands + have the same type. */ + eltsize = fold_convert (ssizetype, eltsize); + off = fold_convert (ssizetype, off); + off = fold_build2 (MULT_EXPR, ssizetype, off, eltsize); + } } else off = integer_zero_node;