This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Major debugging breakage


  > > It seems to me that we should have stored the line number into the
  > > statement tree when we first encounter the statement.  We should
  > > then extract that line number from the statement tree when we
  > > convert the tree into RTL.
  > 
  > Yes, this makes the most sense to me, too.  I think in 3.2, we should
  > try to get the parsers to be the only users of "lineno"; with
  > everything else getting it from the trees or RTL they are handling.
OK.  Slowly this is starting to make sense.  It turns out the C++ front-end
handles this correctly.  

If we look at the parser for C++ we have the following:
simple_if:

          IF
                { $<ttype>$ = begin_if_stmt ();
                  cond_stmt_keyword = "if"; }
            paren_cond_or_null
                { finish_if_stmt_cond ($3, $<ttype>2); }
            implicitly_scoped_stmt
                { $$ = $<ttype>2;
                  finish_then_clause ($<ttype>2); }

begin_if_stmt builds the initial statement and records the line number.  Note
this happens before "paren_cond_or_null".

If we look at the C front-end we have:

/* Value is number of statements counted as of the closeparen.  */
simple_if:
          if_prefix c99_block_lineno_labeled_stmt
                { c_finish_then (); }
/* Make sure c_expand_end_cond is run once
   for each call to c_expand_start_cond.
   Otherwise a crash is likely.  */
        | if_prefix error
        ;

if_prefix:
          IF '(' expr ')'
                { c_expand_start_cond (truthvalue_conversion ($3),
                                       compstmt_count);
                  $<itype>$ = stmt_count;
                  if_stmt_file = $<filename>-2;
                  if_stmt_line = $<lineno>-1; }

Note that we call c_expand_start_cond (which records the line number for
the statement) *after* we've parsed the entire expression.  Thus the
recorded line number is wrong.

At least that's my theory :-)


I haven't hacked parser input files in forever.  I may be able to slog my
way through it using C++ as a guide.

jeff


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]