This is the mail archive of the gcc-patches@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]

[PATCH linemap] Make some asserts fail gracefully


The following patch adds linemap_assert_fails(), which is an assert
meant to be used in conditions such as:

if (linemap_assert_fails(EXPR))
  handle_error();

This is useful for ICEs that we would like to detect during the
development phase but that could be handled gracefully. In the case of
linemap_position_for_loc_and_offset (its only user so far), there are
a few conditions that show something went wrong, but it would be bad
to ICE on users when we can simply return the original location
without column offset, which is only a minor diagnostic output
degradation.

Bootstrapped & regression tested.

I'm happy to use a different name. I tried linemap_soft_assert, but it
doesn't read as nice together with "if". The alternative is to just
not use assert but a simple 'if'. We could resort to that if some
condition triggers too often or we cannot find an immediate fix. For
now, one has to use special Fortran testcases to trigger this, thus I
would like to fix the testcases rather than disable the asserts
completely.

OK?

libcpp/ChangeLog:

2014-12-01  Manuel López-Ibáñez  <manu@gcc.gnu.org>

    * include/line-map.h (linemap_assert_fails): Declare.
    * line-map.c (linemap_position_for_loc_and_offset): Use it.

Attachment: linemap_assert_fails.diff
Description: Text document


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