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: 724039 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3vFsPW2M6Cz9s65 for ; Sat, 4 Feb 2017 22:45:48 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="no2EyuVV"; dkim-atps=neutral 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=LHksSA+fkNv6UnS/zBm21NzGxID2lhGeaas+SGsoWdzerZ 1CTbgVdtNd0DoaKR/xbA7DMrnhweRF83HIuZg5K591H3Jt5HoW62qqqPBRAZ8aeu bmD2Fewt9DCDZeyPaxPVr1fZuMiYrI7GplHrDTULtcLjt7f4x4fiWwWHt257I= 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=no2EyuVVJm5Vv7lb1/IO dmb2JsotDkFMHdYyqbLl6nECdz5yailiWP0WsDJUqNQJ+TCpZ3RlQAaR488eLN4e 5+vxnjWc+zUXrbX5DLsgUj2jpPI1Tpck4rsUKn6iO2xMU3eYCqFIc+84OcVUx33M cKHSfZTTMgEQzXI7pT+ivT8= 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: