From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32591 invoked by alias); 8 May 2017 05:25:18 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 2866 invoked by uid 89); 8 May 2017 05:22:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPAM_BODY,SPF_PASS autolearn=ham version=3.3.2 spammy=alas, chose, operators X-HELO: cc-smtpout1.netcologne.de Received: from cc-smtpout1.netcologne.de (HELO cc-smtpout1.netcologne.de) (89.1.8.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 08 May 2017 05:22:17 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id 3011A12FE3; Mon, 8 May 2017 07:22:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id 20CE511DDF; Mon, 8 May 2017 07:22:13 +0200 (CEST) Received: from [89.0.2.88] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.1.9) (envelope-from ) id 59100085-022c-7f0000012729-7f000001adc4-1 for ; Mon, 08 May 2017 07:22:13 +0200 Received: from linux-w03z.fritz.box (xdsl-89-0-2-88.netcologne.de [89.0.2.88]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA; Mon, 8 May 2017 07:22:10 +0200 (CEST) Date: Mon, 08 May 2017 05:30:00 -0000 From: Volker Reichelt Subject: Re: [PATCH] Pretty-printing of some unsupported expressions (PR c/35441) To: Joseph Myers cc: gcc-patches@gcc.gnu.org In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=us-ascii Content-Disposition: INLINE X-SW-Source: 2017-05/txt/msg00507.txt.bz2 On 2 May, Joseph Myers wrote: > On Fri, 10 Mar 2017, Volker Reichelt wrote: > >> a) This part (with foo1 and foo2 from the testcase) is straightforward. > > That part is OK. > >> b) I chose the shift operators 'a << b' and 'a >> b' for the rotate >> expressions, which is not 100% correct. Would it be better to use >> something like 'lrotate(a, b)', '__lrotate__(a, b)' or 'a lrotate b' >> instead? Or is there something like an '__builtin_lrotate' that I misseed? > > I'd be inclined to use the notation <<< and >>> for rotation, cf. > . Nice idea. It would be nice to see these operators in some future C/C++ versions. Is the nested ternary operator used in the updated patch below OK, or would you prefer a switch? >> c) I chose 'max(q, b)' and 'min(q, b)'. > > I think that's fine. > >> In addition I found some more division operators in gcc/tree.def that >> aren't handled by the pretty-printer: >> >> CEIL_DIV_EXPR >> FLOOR_DIV_EXPR >> ROUND_DIV_EXPR >> CEIL_MOD_EXPR >> FLOOR_MOD_EXPR >> ROUND_MOD_EXPR >> >> Alas I don't have testcases for them. Nevertheless, I could handle them >> like the other MOD and DIV operators just to be safe. > > These can probably appear from Ada code, but maybe not from C. OK, I'll ignore them. > Now we have caret diagnostics and location ranges I think we should be > moving away from printing complicated expressions from trees anyway. So > for the diagnostics about calling non-functions, it would be best to make > a location range for the called expression available if it isn't already, > then do a diagnostic with a location that underlines that text rather than > trying to reproduce an expression text from trees. Indeed, we can do better with caret diagnostics. But non-caret mode is still there (and has its uses because of its usually more consise form) and there are probably more places where this expression is printed. Therefore, I'd like to fix this regardless of a better caret solution for the diagnostics about calling non-functions. Bootstrapped and regtested on x86_64-pc-linux-gnu. OK for trunk? Regards, Volker 2017-05-07 Volker Reichelt PR c/35441 * c-pretty-print.c (c_pretty_printer::expression): Handle MAX_EXPR, MIN_EXPR, EXACT_DIV_EXPR, RDIV_EXPR, LROTATE_EXPR, RROTATE_EXPR. (c_pretty_printer::postfix_expression): Handle MAX_EXPR, MIN_EXPR. (c_pretty_printer::multiplicative_expression): Handle EXACT_DIV_EXPR, RDIV_EXPR. (pp_c_shift_expression): Handle LROTATE_EXPR, RROTATE_EXPR. Index: gcc/c-family/c-pretty-print.c =================================================================== --- gcc/c-family/c-pretty-print.c (revision 247727) +++ gcc/c-family/c-pretty-print.c (working copy) @@ -1551,6 +1551,14 @@ : "__builtin_islessgreater"); goto two_args_fun; + case MAX_EXPR: + pp_c_ws_string (this, "max"); + goto two_args_fun; + + case MIN_EXPR: + pp_c_ws_string (this, "min"); + goto two_args_fun; + two_args_fun: pp_c_left_paren (this); expression (TREE_OPERAND (e, 0)); @@ -1829,6 +1837,8 @@ case MULT_EXPR: case TRUNC_DIV_EXPR: case TRUNC_MOD_EXPR: + case EXACT_DIV_EXPR: + case RDIV_EXPR: multiplicative_expression (TREE_OPERAND (e, 0)); pp_c_whitespace (this); if (code == MULT_EXPR) @@ -1890,9 +1900,13 @@ { case LSHIFT_EXPR: case RSHIFT_EXPR: + case LROTATE_EXPR: + case RROTATE_EXPR: pp_c_shift_expression (pp, TREE_OPERAND (e, 0)); pp_c_whitespace (pp); - pp_string (pp, code == LSHIFT_EXPR ? "<<" : ">>"); + pp_string (pp, code == LSHIFT_EXPR ? "<<" : + code == RSHIFT_EXPR ? ">>" : + code == LROTATE_EXPR ? "<<<" : ">>>"); pp_c_whitespace (pp); pp_c_additive_expression (pp, TREE_OPERAND (e, 1)); break; @@ -2186,6 +2200,8 @@ case UNLT_EXPR: case UNGE_EXPR: case UNGT_EXPR: + case MAX_EXPR: + case MIN_EXPR: case ABS_EXPR: case CONSTRUCTOR: case COMPOUND_LITERAL_EXPR: @@ -2217,11 +2233,15 @@ case MULT_EXPR: case TRUNC_MOD_EXPR: case TRUNC_DIV_EXPR: + case EXACT_DIV_EXPR: + case RDIV_EXPR: multiplicative_expression (e); break; case LSHIFT_EXPR: case RSHIFT_EXPR: + case LROTATE_EXPR: + case RROTATE_EXPR: pp_c_shift_expression (this, e); break; =================================================================== 2017-05-07 Volker Reichelt PR c/35441 * gcc.dg/pr35441.c: New test. Index: gcc/testsuite/gcc.dg/pr35441.c =================================================================== --- gcc/testsuite/gcc.dg/pr35441.c 2017-03-08 18:38:39 +++ gcc/testsuite/gcc.dg/pr35441.c 2017-03-08 23:43:06 @@ -0,0 +1,26 @@ +/* PR c/35441 */ +/* { dg-do compile } */ +/* { dg-options "-fno-diagnostics-show-caret" } */ +/* { dg-bogus "not supported by" "" { target *-*-* } 0 } */ + +void foo1(char **p, char **q) +{ + (p - q)(); /* { dg-error "is not a function" } */ +} + +void foo2(double x, double y) +{ + (x/y)(); /* { dg-error "is not a function" } */ +} + +void foo3(unsigned i, int j) +{ + (i << j | i >> (32 - j))(); /* { dg-error "is not a function" } */ + (i >> j | i << (32 - j))(); /* { dg-error "is not a function" } */ +} + +void foo4(char *p, char *q) +{ + (p < q ? p : q)(); /* { dg-error "is not a function" } */ + (p > q ? p : q)(); /* { dg-error "is not a function" } */ +} ===================================================================