From patchwork Sat Feb 4 11:45:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 93357 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp982185qgi; Sat, 4 Feb 2017 03:45:52 -0800 (PST) X-Received: by 10.98.94.2 with SMTP id s2mr2077596pfb.133.1486208752263; Sat, 04 Feb 2017 03:45:52 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id h9si28225789pli.37.2017.02.04.03.45.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Feb 2017 03:45:52 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-447924-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-447924-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-447924-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=CpUnZGz8+dk29JmmzRvbtiUSAYQZwW07fdyK7vYE9eDkjz pk3t16Hesa2pns99rsBzV5y2RcDSey/ZZ95trPeMib3swaPREdliD0KDDcx+nnZ4 yJOMSgy93U9c0xpG+QAGoX7T31Z3JTrkHRGZdU0RhTNUZZXLeKp2XsPdCpL6s= 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=GlnsOmdSYScBcArBU5XXxu5rAUg=; b=wqYskV3XZ+OcGegAi86t jq39/H7Mjvtj3s0k9PzEv3IP3+nrx5Ce/OBLSGqhSXG9JtRME7VJ+BNXLkh7EaCF 9PttExjEfOiN3ZF7OeIMAZaO4qdfrfXKBj6AYv2xxulLwxP7sxWl00zynNCMtC6E YRadtesgztzex7dgj7ipcpA= Received: (qmail 54234 invoked by alias); 4 Feb 2017 11:45:34 -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 54169 invoked by uid 89); 4 Feb 2017 11:45:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL, BAYES_05, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=c-parser.c, cparserc, UD:c-parser.c, 1464 X-HELO: mail-io0-f170.google.com Received: from mail-io0-f170.google.com (HELO mail-io0-f170.google.com) (209.85.223.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 04 Feb 2017 11:45:17 +0000 Received: by mail-io0-f170.google.com with SMTP id j13so36158050iod.3 for ; Sat, 04 Feb 2017 03:45:14 -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=qVThFxiCrgFPS2Ep7+AlBgwmzIpWKKquPUgEIgjsRus=; b=m2DM9r95y1WDWl1FlI3sRS0s1cVZhqvI6y619rcN89Qzr6nnmkVyrZ/39IGxg+bYDc OjnfyIv5f2Ql84PX95ljq+bkFwnRMo0Ljml01RHB7lGTMxuD1QNslmkGN3xbtckzgWYy +b97OveU9idS1/Lhnt61QcGQTvWNSIMIqVDx4UhXuijaqRWbfi8hA+fUCpbbQBe6dREM jqLU8XyzjICD+dnLBmzRIvZ10pSxnjMGVFf/sdNOMsFgeVTxGTe7dUXfcFBFFSrUNgCg ZFTJRwlLaRGxN+k/6Cv3rx8aa53k7fZ2Ta6JC4nsYLX/ix8Hetl5K7/ewDLby5BUm4l7 As3g== X-Gm-Message-State: AMke39kc6Ee8Me0Z7NNQ8/G7teNAV92a/cgbvs5Wf3VFw1wywFlNWR4w1tQqj/8r5uYMrCIPa85QYUlRYEYmxBfQ X-Received: by 10.107.22.197 with SMTP id 188mr1258913iow.183.1486208712522; Sat, 04 Feb 2017 03:45:12 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.162.13 with HTTP; Sat, 4 Feb 2017 03:45:12 -0800 (PST) From: Prathamesh Kulkarni Date: Sat, 4 Feb 2017 17:15:12 +0530 Message-ID: Subject: [GIMPLE FE] Avoid ICE with __builtin_abs To: gcc Patches , Richard Biener X-IsSubscribed: yes Hi, The following test-case ICE's with -fgimple: int __GIMPLE foo(int a) { int t1; t1_1 = __builtin_abs (a); return t1_1; } gimplefe-2.c:4:3: internal compiler error: in get_callee_fndecl, at tree.c:9500 t1_1 = __builtin_abs (a); ^~~~ 0xe96e8d get_callee_fndecl(tree_node const*) ../../gcc/gcc/tree.c:9500 0x924d75 gimple_build_call_from_tree(tree_node*) ../../gcc/gcc/gimple.c:351 0x6c86b3 c_parser_gimple_statement ../../gcc/gcc/c/gimple-parser.c:393 0x6c86b3 c_parser_gimple_compound_statement ../../gcc/gcc/c/gimple-parser.c:216 0x6c86b3 c_parser_parse_gimple_body(c_parser*) ../../gcc/gcc/c/gimple-parser.c:93 0x6b04f1 c_parser_declaration_or_fndef ../../gcc/gcc/c/c-parser.c:2081 0x6b883b c_parser_external_declaration ../../gcc/gcc/c/c-parser.c:1464 0x6b92a1 c_parser_translation_unit ../../gcc/gcc/c/c-parser.c:1344 0x6b92a1 c_parse_file() ../../gcc/gcc/c/c-parser.c:18141 0x717832 c_common_parse_file() ../../gcc/gcc/c-family/c-opts.c:1102 This happens because __builtin_abs(a) gets folded to > and get_callee_fndecl expects CALL_EXPR. The attached patch tries to fix the issue by building gimple_assign with appropriate subcode for functions that get folded to expression instead of trying to build it as a function-call. Is it OK to commit after bootstrap+test ? Thanks, Prathamesh 2017-02-04 Prathamesh Kulkarni * gimple-pretty-print.c (dump_unary_rhs): Change dump format for ABS_EXPR for gimple dump. * tree-pretty-print.c (dump_generic_node): Likewise. c/ * gimple-parser.c (c_parser_gimple_statement): Check if rhs.value is CALL_EXPR and build gimple_assign if it isn't. testsuite/ * gcc.dg/gimplefe-23.c: New test-case. diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c index 7feb6d0..4e2ae37 100644 --- a/gcc/c/gimple-parser.c +++ b/gcc/c/gimple-parser.c @@ -401,10 +401,22 @@ c_parser_gimple_statement (c_parser *parser, gimple_seq *seq) rhs = c_parser_gimple_unary_expression (parser); if (rhs.value != error_mark_node) { - gimple *call = gimple_build_call_from_tree (rhs.value); - gimple_call_set_lhs (call, lhs.value); - gimple_seq_add_stmt (seq, call); - gimple_set_location (call, loc); + if (TREE_CODE (rhs.value) == CALL_EXPR) + { + gimple *call = gimple_build_call_from_tree (rhs.value); + gimple_call_set_lhs (call, lhs.value); + gimple_seq_add_stmt (seq, call); + gimple_set_location (call, loc); + } + else + { + tree value = tree_strip_nop_conversions (rhs.value); + gcc_assert (get_gimple_rhs_class (TREE_CODE (value)) + != GIMPLE_INVALID_RHS); + gassign *assign = gimple_build_assign (lhs.value, value); + gimple_seq_add_stmt (seq, assign); + gimple_set_location (assign, loc); + } } return; } diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c index 91c839d..f773d85 100644 --- a/gcc/gimple-pretty-print.c +++ b/gcc/gimple-pretty-print.c @@ -323,9 +323,18 @@ dump_unary_rhs (pretty_printer *buffer, gassign *gs, int spc, int flags) break; case ABS_EXPR: - pp_string (buffer, "ABS_EXPR <"); - dump_generic_node (buffer, rhs, spc, flags, false); - pp_greater (buffer); + if (flags & TDF_GIMPLE) + { + pp_string (buffer, "__builtin_abs ("); + dump_generic_node (buffer, rhs, spc, flags, false); + pp_right_paren (buffer); + } + else + { + pp_string (buffer, "ABS_EXPR <"); + dump_generic_node (buffer, rhs, spc, flags, false); + pp_greater (buffer); + } break; default: diff --git a/gcc/testsuite/gcc.dg/gimplefe-23.c b/gcc/testsuite/gcc.dg/gimplefe-23.c new file mode 100644 index 0000000..1448030 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-23.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fgimple -fdump-tree-ssa-gimple" } */ + +int __GIMPLE foo(int a) +{ + int t1; + t1_1 = __builtin_abs (a); + return t1_1; +} + +/* { dg-final { scan-tree-dump "__builtin_abs" "ssa" } } */ diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c index d823c2e..f1a5bdd 100644 --- a/gcc/tree-pretty-print.c +++ b/gcc/tree-pretty-print.c @@ -2441,9 +2441,18 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, int flags, break; case ABS_EXPR: - pp_string (pp, "ABS_EXPR <"); - dump_generic_node (pp, TREE_OPERAND (node, 0), spc, flags, false); - pp_greater (pp); + if (flags & TDF_GIMPLE) + { + pp_string (pp, "__builtin_abs ("); + dump_generic_node (pp, TREE_OPERAND (node, 0), spc, flags, false); + pp_right_paren (pp); + } + else + { + pp_string (pp, "ABS_EXPR <"); + dump_generic_node (pp, TREE_OPERAND (node, 0), spc, flags, false); + pp_greater (pp); + } break; case RANGE_EXPR: