From ce487ef6c1ba3b35250ce5bfe053e24e34a854e6 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 16 Apr 2010 00:23:51 +0000 Subject: [PATCH] Fix a bug in caret-line-pruning logic that only happens when we have a source line wider than the terminal where the associated fix-it line is longer than the caret line. Previously, we would crash in this case, which was rather unfortunate. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101426 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/TextDiagnosticPrinter.cpp | 13 ++++++++++--- test/Misc/message-length.c | 16 +++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index 6c8137e3d2..f2b16a4b38 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -148,9 +148,16 @@ static void SelectInterestingSourceRegion(std::string &SourceLine, std::string &FixItInsertionLine, unsigned EndOfCaretToken, unsigned Columns) { - if (CaretLine.size() > SourceLine.size()) - SourceLine.resize(CaretLine.size(), ' '); - + unsigned MaxSize = std::max(SourceLine.size(), + std::max(CaretLine.size(), + FixItInsertionLine.size())); + if (MaxSize > SourceLine.size()) + SourceLine.resize(MaxSize, ' '); + if (MaxSize > CaretLine.size()) + CaretLine.resize(MaxSize, ' '); + if (!FixItInsertionLine.empty() && MaxSize > FixItInsertionLine.size()) + FixItInsertionLine.resize(MaxSize, ' '); + // Find the slice that we need to display the full caret line // correctly. unsigned CaretStart = 0, CaretEnd = CaretLine.size(); diff --git a/test/Misc/message-length.c b/test/Misc/message-length.c index 3c746052fd..3e69b6a206 100644 --- a/test/Misc/message-length.c +++ b/test/Misc/message-length.c @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 -fmessage-length 72 %s 2>&1 | FileCheck -strict-whitespace %s -// RUN: %clang_cc1 -fmessage-length 1 %s - +// RUN: not %clang_cc1 -fmessage-length 72 %s 2>&1 | FileCheck -strict-whitespace %s +// RUN: not %clang_cc1 -fmessage-length 1 %s +// RUN: not %clang_cc1 -fmessage-length 8 %s 2>&1 | FileCheck -check-prefix=CHECK-DOT %s // Hack so we can check things better, force the file name and line. # 1 "FILE" 1 @@ -30,3 +30,13 @@ void a_very_long_line(int *ip, float *FloatPointer) { // CHECK: FILE:23:78 // CHECK: {{^ ...// some long comment text and a brace, eh {} }} + +struct A { int x; }; +void h(struct A *a) { + // CHECK-DOT: member + // CHECK-DOT: reference + // CHECK-DOT: type + (void)a + . + x; +} -- 2.40.0