[PATCH] D153849: [clang][Diagnostics] Fix diagnostic line numbers
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 30 01:57:44 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8554a55d041f: [clang][Diagnostics] Fix diagnostic line numbers (authored by tbaeder).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D153849/new/
https://reviews.llvm.org/D153849
Files:
clang/lib/Frontend/TextDiagnostic.cpp
clang/test/Misc/diag-style.cpp
Index: clang/test/Misc/diag-style.cpp
===================================================================
--- clang/test/Misc/diag-style.cpp
+++ clang/test/Misc/diag-style.cpp
@@ -10,3 +10,17 @@
// CHECK-NEXT: {{^}} 5 | {{$}}
// CHECK-NEXT: {{^}} 6 | true, "");{{$}}
// CHECK-NEXT: {{^}} | ~~~~{{$}}
+
+
+/// #line pragmas are respected
+void printf(const char *a, ...) __attribute__((__format__(__printf__, 1, 2)));
+#line 10
+void f(int x) {
+ printf("%f",
+ x);
+}
+// CHECK: 12:10: warning: format specifies type
+// CHECK-NEXT: {{^}} 11 |
+// CHECK-NEXT: {{^}} |
+// CHECK-NEXT: {{^}} |
+// CHECK-NEXT: {{^}} 12 |
Index: clang/lib/Frontend/TextDiagnostic.cpp
===================================================================
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1160,16 +1160,20 @@
// Find the set of lines to include.
const unsigned MaxLines = DiagOpts->SnippetLineLimit;
std::pair<unsigned, unsigned> Lines = {CaretLineNo, CaretLineNo};
+ unsigned DisplayLineNo =
+ Ranges.empty() ? Loc.getPresumedLoc().getLine() : ~0u;
for (const auto &I : Ranges) {
if (auto OptionalRange = findLinesForRange(I, FID, SM))
Lines = maybeAddRange(Lines, *OptionalRange, MaxLines);
+
+ DisplayLineNo =
+ std::min(DisplayLineNo, SM.getPresumedLineNumber(I.getBegin()));
}
// Our line numbers look like:
// " [number] | "
// Where [number] is MaxLineNoDisplayWidth columns
// and the full thing is therefore MaxLineNoDisplayWidth + 4 columns.
- unsigned DisplayLineNo = Loc.getPresumedLoc().getLine();
unsigned MaxLineNoDisplayWidth =
DiagOpts->ShowLineNumbers
? std::max(4u, getNumDisplayWidth(DisplayLineNo + MaxLines))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153849.536144.patch
Type: text/x-patch
Size: 1806 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230630/094cd527/attachment.bin>
More information about the cfe-commits
mailing list