diff options
Diffstat (limited to 'gcc/c-family/c-indentation.c')
-rw-r--r-- | gcc/c-family/c-indentation.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/gcc/c-family/c-indentation.c b/gcc/c-family/c-indentation.c index cd9637d..521f992 100644 --- a/gcc/c-family/c-indentation.c +++ b/gcc/c-family/c-indentation.c @@ -36,10 +36,30 @@ extern cpp_options *cpp_opts; on the line. */ static bool -get_visual_column (expanded_location exploc, +get_visual_column (expanded_location exploc, location_t loc, unsigned int *out, unsigned int *first_nws) { + /* PR c++/68819: if the column number is zero, we presumably + had a location_t > LINE_MAP_MAX_LOCATION_WITH_COLS, and so + we have no column information. + Act as if no conversion was possible, triggering the + error-handling path in the caller. */ + if (!exploc.column) + { + static bool issued_note = false; + if (!issued_note) + { + /* Notify the user the first time this happens. */ + issued_note = true; + inform (loc, + "-Wmisleading-indentation is disabled from this point" + " onwards, since column-tracking was disabled due to" + " the size of the code/headers"); + } + return false; + } + int line_len; const char *line = location_get_source_line (exploc.file, exploc.line, &line_len); @@ -297,7 +317,7 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo, gcc_assert (guard_exploc.line == next_stmt_exploc.line); unsigned int guard_vis_column; unsigned int guard_line_first_nws; - if (!get_visual_column (guard_exploc, + if (!get_visual_column (guard_exploc, guard_loc, &guard_vis_column, &guard_line_first_nws)) return false; @@ -357,14 +377,15 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo, the case for input files containing #line directives, and these are often for autogenerated sources (e.g. from .md files), where it's not clear that it's meaningful to look at indentation. */ - if (!get_visual_column (next_stmt_exploc, &next_stmt_vis_column, + if (!get_visual_column (next_stmt_exploc, next_stmt_loc, + &next_stmt_vis_column, &next_stmt_line_first_nws)) return false; - if (!get_visual_column (body_exploc, + if (!get_visual_column (body_exploc, body_loc, &body_vis_column, &body_line_first_nws)) return false; - if (!get_visual_column (guard_exploc, + if (!get_visual_column (guard_exploc, guard_loc, &guard_vis_column, &guard_line_first_nws)) return false; |