From patchwork Fri Mar 27 16:36:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 455503 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 E31FD1400B6 for ; Sat, 28 Mar 2015 03:37:01 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=BPUllnA1; dkim-adsp=none (unprotected policy); 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:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=QBKRpMPOFGrIOeh1Yyl5mHYP4ku8InSDA6y9TIQm0VYUqfcyCJ 9UGpPbqTzjhSAYq1m5BhquTbvFuI5RgZNKfrGMoD+949C4VJQZpDTIh8uCGCsIyg CGfUyqgabqk6C3KQglO0TCVistnPf8MIIYCm6IJ4aBlWBK7UpmN7l+aeE= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=hxLjL0zu/QWjPHGSemh0vAU+2sg=; b=BPUllnA1c/ihcYtfUOVE 3Vpgb5EY/v+PRrl+8j2azL6yDKfnQ2S+LWnWdnrPIREjFPYnkWVChumAut/eQ8n1 O68pRnXE5FPJQeMXWITgTXVyY9/4qf0jhq0FoKy4Xfy3xckhJCBQrI69occt9Sjv 0YFR/uNbtxu4tFQM1bFq9Uk= Received: (qmail 103084 invoked by alias); 27 Mar 2015 16:36:54 -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 103068 invoked by uid 89); 27 Mar 2015 16:36:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.9 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 27 Mar 2015 16:36:52 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2RGaoBI017923 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 27 Mar 2015 12:36:50 -0400 Received: from host1.jankratochvil.net (ovpn-116-21.ams2.redhat.com [10.36.116.21]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2RGakBH007232 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 27 Mar 2015 12:36:49 -0400 Date: Fri, 27 Mar 2015 17:36:46 +0100 From: Jan Kratochvil To: gcc-patches@gcc.gnu.org Cc: Phil Muldoon , gdb-patches@sourceware.org Subject: [gcc patch] libcc1: '@' GDB array operator Message-ID: <20150327163646.GA16457@host1.jankratochvil.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Hi, there is now pending GDB patch for: (gdb) compile print EXPR [PATCH 4/4] compile: New 'compile print' https://sourceware.org/ml/gdb-patches/2015-03/msg00875.html Reasons for this patch: How to implement '@' GDB-like operator for libcc1 https://gcc.gnu.org/ml/gcc/2015-03/msg00175.html Testcase is in the GDB patch. There could be a testcase in the 'guality' part of GCC testsuite. I have some doubts if the copy_node() way is right. The error for stray '@' is now reported elsewhere so for example int a=1@a; produced stray.c:1:8: error: stray ‘@’ in program int a=1@a; ^ stray.c:1:9: error: expected ‘,’ or ‘;’ before ‘a’ int a=1@a; ^ but now it produces: stray.c:1:8: error: stray ‘@’ in program int a=1@a; ^ stray.c:1:8: error: expected ‘,’ or ‘;’ before ‘@’ token It is because in c-family/c-common.c we cannot yet access c_binding_oracle (whether GDB is present) as c_binding_oracle is c-specific symbol while c-family/c-common.c is linked for both c and c++; so c_binding_oracle symbol is missing when linking cc1plus. As there should be also C++ support for libcc1 in the future c_binding_oracle will need to be present for both C and C++. But so far I have left it as submitted. GCC testsuite has passed without regressions. Thanks, Jan gcc/c-family/ 2015-03-27 Jan Kratochvil * c-common.c (c_fully_fold_internal, binary_op_error): Add ATSIGN_EXPR. * c-lex.c (c_lex_with_flags): Add ATSIGN_EXPR. gcc/c/ 2015-03-27 Jan Kratochvil * c-parser.c (enum c_parser_prec): Add PREC_ATSIGN. (c_parser_binary_expression): Add CPP_ATSIGN. * c-typeck.c (build_binary_op): Add ATSIGN_EXPR. gcc/ 2015-03-27 Jan Kratochvil * tree-pretty-print.c (dump_generic_node, op_symbol_code): Add ATSIGN_EXPR. * tree.def: Add ATSIGN_EXPR. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 456c619..37cb104c 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -1289,6 +1289,28 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands, ret = fold (ret); goto out; + case ATSIGN_EXPR: + orig_op0 = op0 = TREE_OPERAND (expr, 0); + orig_op1 = op1 = TREE_OPERAND (expr, 1); + op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands, + maybe_const_itself); + STRIP_TYPE_NOPS (op0); + op1 = c_fully_fold_internal (op1, in_init, maybe_const_operands, + maybe_const_itself); + STRIP_TYPE_NOPS (op1); + op1 = decl_constant_value_for_optimization (op1); + ret = copy_node (op0); + TREE_TYPE (ret) = build_array_type_nelts (TREE_TYPE (op0), + tree_to_uhwi (op1)); + if (ret != expr) + { + TREE_READONLY (ret) = TREE_READONLY (expr); + TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (expr); + TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (expr); + } + ret = fold (ret); + goto out; + case COMPOUND_EXPR: case MODIFY_EXPR: case PREDECREMENT_EXPR: @@ -4084,6 +4106,8 @@ binary_op_error (location_t location, enum tree_code code, opname = "||"; break; case BIT_XOR_EXPR: opname = "^"; break; + case ATSIGN_EXPR: + opname = "@"; break; default: gcc_unreachable (); } diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c index bb55be8..3a9f968 100644 --- a/gcc/c-family/c-lex.c +++ b/gcc/c-family/c-lex.c @@ -515,7 +515,10 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, break; } - /* FALLTHROUGH */ + // Create ATSIGN_EXPR for GDB. + *value = NULL_TREE; + break; + case CPP_HASH: case CPP_PASTE: { diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 5cc3892..2a30d72 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -1173,6 +1173,7 @@ enum c_parser_prec { PREC_EQ, PREC_REL, PREC_SHIFT, + PREC_ATSIGN, PREC_ADD, PREC_MULT, NUM_PRECS @@ -6283,6 +6284,16 @@ c_parser_binary_expression (c_parser *parser, struct c_expr *after, oprec = PREC_ADD; ocode = MINUS_EXPR; break; + case CPP_ATSIGN: + if (!c_binding_oracle) + { + error_at (c_parser_peek_token (parser)->location, + "stray %qs in program", "@"); + goto out; + } + oprec = PREC_ATSIGN; + ocode = ATSIGN_EXPR; + break; case CPP_LSHIFT: oprec = PREC_SHIFT; ocode = LSHIFT_EXPR; diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index ebe4c73..22e7bd8 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -10976,6 +10976,19 @@ build_binary_op (location_t location, enum tree_code code, maybe_warn_bool_compare (location, code, orig_op0, orig_op1); break; + case ATSIGN_EXPR: + if (TREE_CODE (orig_op1) == INTEGER_CST) + { + result_type = build_array_type_nelts (type0, tree_to_uhwi (orig_op1)); + converted = 1; + break; + } + // Otherwise it would look unclear: + // error: invalid operands to binary @ (have ‘int’ and ‘int’) + error_at (location, + "second parameter of operator %<@%> requires constant integer"); + return error_mark_node; + default: gcc_unreachable (); } diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c index d7c049f..cf00457 100644 --- a/gcc/tree-pretty-print.c +++ b/gcc/tree-pretty-print.c @@ -2037,6 +2037,7 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, int flags, case LTGT_EXPR: case ORDERED_EXPR: case UNORDERED_EXPR: + case ATSIGN_EXPR: { const char *op = op_symbol (node); op0 = TREE_OPERAND (node, 0); @@ -3432,6 +3433,9 @@ op_symbol_code (enum tree_code code) case MIN_EXPR: return "min"; + case ATSIGN_EXPR: + return "@"; + default: return "<<< ??? >>>"; } diff --git a/gcc/tree.def b/gcc/tree.def index b4b4164..250b8d9 100644 --- a/gcc/tree.def +++ b/gcc/tree.def @@ -669,6 +669,9 @@ DEFTREECODE (PLUS_EXPR, "plus_expr", tcc_binary, 2) DEFTREECODE (MINUS_EXPR, "minus_expr", tcc_binary, 2) DEFTREECODE (MULT_EXPR, "mult_expr", tcc_binary, 2) +/* GDB operator '@' to create array types. */ +DEFTREECODE (ATSIGN_EXPR, "atsign_expr", tcc_binary, 2) + /* Pointer addition. The first operand is always a pointer and the second operand is an integer of type sizetype. */ DEFTREECODE (POINTER_PLUS_EXPR, "pointer_plus_expr", tcc_binary, 2)