From patchwork Wed Feb 15 12:07:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 93993 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp1931563obz; Wed, 15 Feb 2017 04:08:17 -0800 (PST) X-Received: by 10.99.241.17 with SMTP id f17mr38423383pgi.94.1487160497919; Wed, 15 Feb 2017 04:08:17 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id d74si3567211pfd.278.2017.02.15.04.08.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Feb 2017 04:08:17 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-448573-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-448573-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-448573-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=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=c8KuFYk3sqoUoHm8MFEEUpJ4uU1NfTtDQwA8UdKHkFIP5+ RZTqPRI+I4tJAAbyiOPJBW4aA0prUHrcSjPwGn3D6Sze9Bz4/dvPvnYd5R/EcyGg /2eMEO9VcGs+0C1sAdmGxqa+b3g8A5LkrVWwrMsoaTslOj+vgBxD1GvfeQe8c= 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=XN7D5lf8M1bs64LcVmnZtmQYAAY=; b=jMxjvdozSj/a5lmtFMe8 vlGQqUiekh1vXoMkDeNu1w0k9P9nHkeE0VsdZZU6K5XEKDDcKCNdRSa0ubSGDXp5 aC1YqJSINjFWWQpGOUm2FQ5ZVMcEOODkOXT2tasPN8UAMfoF8aP0yPQb2C7+j/Qd mFH9B5mCI1fm0uVEkuUBJYY= Received: (qmail 129967 invoked by alias); 15 Feb 2017 12:08:05 -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 129929 invoked by uid 89); 15 Feb 2017 12:08:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=GIMPLE, 1, 20, Hx-languages-length:3812, 1973 X-HELO: mail-it0-f41.google.com Received: from mail-it0-f41.google.com (HELO mail-it0-f41.google.com) (209.85.214.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 Feb 2017 12:07:53 +0000 Received: by mail-it0-f41.google.com with SMTP id c7so61649036itd.1 for ; Wed, 15 Feb 2017 04:07:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=L0dtVwznHU43hgr0DvY+x5xS7gfYV1R+OQLhbYgyiFg=; b=n0KPS/z5sOYtX4RMGDnPPygiHE2ENrsoO3G/aE4DxB4Bce6RmmnXWS9i8h26yz4bMs T4UhSIUbQXlxA3GyKm9xfo9EVq5RQ2UAZIXKO4C1w8ElLSnCWucThV+ZSZRWeFQjZ5am t8eGdXQGmOrFXnmuFFsrZT7+M6N2dq4L7ljrSZb20N44zjSIqgddQRu9ALnXxcg+B/5I O9Js2fKicsXeF+5lgwPFiu2z+Ex9LlcLRoAjtf2T5jen2HBQFve1uprlSr2D+xHyempi Tai8z6881dAmRFgGSCNEN8P9uRVHUNfVn9zO52D48UXSz24iKlo3/Hq/3NY84cITtmAv EKbA== X-Gm-Message-State: AMke39ny+1WGpYLm5BZviTfKFuSDhad2Qv7JRQSOLhL/B90hntHJiTkrnrrHLPUm/ZmmG/fXcpL1WoaAHsTNOBU7 X-Received: by 10.36.53.210 with SMTP id k201mr8138287ita.21.1487160471861; Wed, 15 Feb 2017 04:07:51 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.162.13 with HTTP; Wed, 15 Feb 2017 04:07:51 -0800 (PST) From: Prathamesh Kulkarni Date: Wed, 15 Feb 2017 17:37:51 +0530 Message-ID: Subject: [GIMPLE FE] avoid ICE with same ssa version number for multiple names To: gcc Patches , Richard Biener X-IsSubscribed: yes Hi, For the following (invalid) test-case: void __GIMPLE () foo (int a) { int t0; int _1; _1 = a; t0_1 = a; } results in following ICE: gimplefe-error-4.c: In function ‘foo’: gimplefe-error-4.c:20:1: error: SSA_NAME_DEF_STMT is wrong } ^ Expected definition statement: _1 = a_2(D); Actual definition statement: _1 = a_2(D); gimplefe-error-4.c:20:1: internal compiler error: verify_ssa failed 0xe1458b verify_ssa(bool, bool) ../../gcc/gcc/tree-ssa.c:1184 0xb0d1ed execute_function_todo ../../gcc/gcc/passes.c:1973 0xb0dad5 execute_todo ../../gcc/gcc/passes.c:2016 The reason for ICE is that in c_parser_parse_ssa_name, ssa_name (1) returns tree node for _1, and "t0_1" gets replaced by "_1" resulting in multiple definitions for _1. The attached patch checks if multiple ssa names have same version number and emits a diagnostic in that case, for the above case: gimplefe-error-4.c: In function ‘foo’: gimplefe-error-4.c:10:3: error: ssa version ‘1’ used anonymously and in ‘t0’ t0_1 = a; ^~~~ OK to commit after bootstrap+test ? Thanks, Prathamesh 2017-02-15 Prathamesh Kulkarni c/ * gimple-parser.c (c_parser_parse_ssa_name): Emit diagnostic if same ssa version is used with multiple names. testsuite/ * gcc.dg/gimplefe-error-4.c: New test. diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c index d959877..2e163f4 100644 --- a/gcc/c/gimple-parser.c +++ b/gcc/c/gimple-parser.c @@ -672,29 +672,49 @@ c_parser_parse_ssa_name (c_parser *parser, } else { + /* Separate var name from version. */ + char *var_name = XNEWVEC (char, ver_offset + 1); + memcpy (var_name, token, ver_offset); + var_name[ver_offset] = '\0'; + /* lookup for parent decl. */ + id = get_identifier (var_name); + tree parent = lookup_name (id); + if (! parent || parent == error_mark_node) + { + c_parser_error (parser, "base variable or SSA name undeclared"); + XDELETEVEC (var_name); + return error_mark_node; + } if (version < num_ssa_names) name = ssa_name (version); if (! name) { - /* Separate var name from version. */ - char *var_name = XNEWVEC (char, ver_offset + 1); - memcpy (var_name, token, ver_offset); - var_name[ver_offset] = '\0'; - /* lookup for parent decl. */ - id = get_identifier (var_name); - tree parent = lookup_name (id); - XDELETEVEC (var_name); - if (! parent || parent == error_mark_node) - { - c_parser_error (parser, "base variable or SSA name undeclared"); - return error_mark_node; - } if (VECTOR_TYPE_P (TREE_TYPE (parent)) || TREE_CODE (TREE_TYPE (parent)) == COMPLEX_TYPE) DECL_GIMPLE_REG_P (parent) = 1; name = make_ssa_name_fn (cfun, parent, gimple_build_nop (), version); } + else if (!SSA_NAME_IDENTIFIER (name)) + { + error_at (input_location, "ssa version %<%d%> used anonymously" + " and in %<%s%>", version, var_name); + XDELETEVEC (var_name); + return error_mark_node; + } + else + { + const char *ssaname = IDENTIFIER_POINTER (SSA_NAME_IDENTIFIER (name)); + if (strcmp (ssaname, var_name)) + { + error_at (input_location, "ssa version %<%d%> used for" + " multiple names %<%s%>, %<%s%>", version, + ssaname, var_name); + XDELETEVEC (var_name); + return error_mark_node; + } + } + XDELETEVEC (var_name); } return name; diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-4.c b/gcc/testsuite/gcc.dg/gimplefe-error-4.c new file mode 100644 index 0000000..a3c652e --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-error-4.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ + +void __GIMPLE () foo (int a) +{ + int t0; + int _1; + + _1 = a; + t0_1 = a; /* { dg-error "used anonymously and in 't0'" } */ +} + +void __GIMPLE () bar (int a) +{ + int t0; + int t1; + + t0_1 = a; + t1_1 = a; /* { dg-error "multiple names 't0', 't1'" } */ +}