Bug 35441 - pretty-printer cannot handle some expressions
Summary: pretty-printer cannot handle some expressions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.4.0
: P4 normal
Target Milestone: ---
Assignee: Volker Reichelt
URL:
Keywords: diagnostic, monitored
Depends on:
Blocks: 35442 35443 35742
  Show dependency treegraph
 
Reported: 2008-03-03 21:31 UTC by Volker Reichelt
Modified: 2017-05-09 19:11 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-03-15 01:36:55


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2008-03-03 21:31:34 UTC
A broken diagnostic is issued for the following invalid code snippet
since GCC 4.0.0:

================================
void foo(char **p, char **q)
{
  (p - q)();
}
================================

With GCC 4.0.x we got 

bug.c: In function 'foo':
bug.c:3: error: called object '#'exact_div_expr' not supported by pp_c_expression#' is not a function

which is already bad enough. But since GCC 4.1.0 it's even worse:

#'exact_div_expr' not supported by pp_c_expression#'bug.c: In function 'foo':
bug.c:3: error: called object  is not a function

Not only the exact_div_expr case should be fixed, but also the output
order when we hit something unsupported. And, yes, there are more cases
of unsupported expressions. How about the following?

================================
void foo(char *p, char *q)
{
  (p < q ? p : q)();
}
================================

#'min_expr' not supported by pp_c_expression#'bug.c: In function 'foo':
bug.c:3: error: called object  is not a function

================================
void foo(double x, double y)
{
  (x/y)();
}
================================

#'rdiv_expr' not supported by pp_c_expression#'bug.c: In function 'foo':
bug.c:3: error: called object  is not a function

================================
void foo(unsigned i, int j)
{
  (i << j | i >> (32 - j))();
  (i >> j | i << (32 - j))();
}
================================

#'lrotate_expr' not supported by pp_c_expression#'bug.c: In function 'foo':
bug.c:3: error: called object  is not a function
#'rrotate_expr' not supported by pp_c_expression#'bug.c:4: error: called object  is not a function
Comment 1 Joseph S. Myers 2008-07-04 22:38:01 UTC
Closing 4.1 branch.
Comment 2 Chris Lattner 2008-08-14 04:23:39 UTC
FYI, clang produces:

t.c:3:3: error: called object is not a function or function pointer
  (p - q)();
  ^~~~~~~~~
t.c:8:3: error: called object is not a function or function pointer
  (p < q ? p : q)();
  ^~~~~~~~~~~~~~~~~

Comment 3 Joseph S. Myers 2009-03-31 20:46:07 UTC
Closing 4.2 branch.
Comment 4 Richard Biener 2009-08-04 12:28:52 UTC
GCC 4.3.4 is being released, adjusting target milestone.
Comment 5 Richard Biener 2010-05-22 18:12:06 UTC
GCC 4.3.5 is being released, adjusting target milestone.
Comment 6 Richard Biener 2011-06-27 12:14:35 UTC
4.3 branch is being closed, moving to 4.4.7 target.
Comment 7 Jakub Jelinek 2012-03-13 12:48:04 UTC
4.4 branch is being closed, moving to 4.5.4 target.
Comment 8 Manuel López-Ibáñez 2012-04-21 14:53:25 UTC
Author: manu
Date: Sat Apr 21 14:53:21 2012
New Revision: 186652

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186652
Log:
2012-04-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR 35441
	* c-typeck.c (inform_declaration): New.
	(build_function_call_vec):  Do not pretty-print
	expressions when caret is enabled.
	(convert_arguments): Use inform_declaration.
cp/
	* typeck.c (cp_build_function_call_vec): Do not pretty-print
	expressions when caret is enabled.
testsuite/
	* c-c++-common/pr35441.C: New.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-typeck.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog
Comment 9 Manuel López-Ibáñez 2012-04-21 15:03:42 UTC
This is fixed when using -fdiagnostics-show-caret, which is the default. However, the underlying problem is still there, so I cannot be considered fixed.
Comment 10 Volker Reichelt 2017-04-03 20:52:12 UTC
Patch at https://gcc.gnu.org/ml/gcc-patches/2017-03/msg00498.html
Comment 11 Volker Reichelt 2017-05-09 19:09:54 UTC
Author: reichelt
Date: Tue May  9 19:09:22 2017
New Revision: 247810

URL: https://gcc.gnu.org/viewcvs?rev=247810&root=gcc&view=rev
Log:
        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.

        * gcc.dg/pr35441.c: New test.


Added:
    trunk/gcc/testsuite/gcc.dg/pr35441.c
Modified:
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-pretty-print.c
    trunk/gcc/testsuite/ChangeLog
Comment 12 Volker Reichelt 2017-05-09 19:11:44 UTC
Fixed on trunk for GCC 8.