vangthao created this revision.
Herald added a project: All.
vangthao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In expected diagnostic checks containing newlines, anything after the last
newline would be discarded since we stop parsing directly after the last 
newline.
Fix this behavior so that any remaining string after the last newline is
appended instead of ignored.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126908

Files:
  clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
  clang/test/SemaCXX/references.cpp


Index: clang/test/SemaCXX/references.cpp
===================================================================
--- clang/test/SemaCXX/references.cpp
+++ clang/test/SemaCXX/references.cpp
@@ -90,7 +90,7 @@
   int& okay; // expected-note{{reference member 'okay' will never be 
initialized}}
 };
 
-struct C : B, A { }; // expected-warning {{direct base 'A' is inaccessible due 
to ambiguity:\n    struct C -> struct B -> struct A\nstruct C -> struct A}}
+struct C : B, A { }; // expected-warning {{direct base 'A' is inaccessible due 
to ambiguity:\n    struct C -> struct B -> struct A\n    struct C -> struct A}}
 
 void test7(C& c) {
   A& a1 = c; // expected-error {{ambiguous conversion from derived class 'C' 
to base class 'A':}}
Index: clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
===================================================================
--- clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -631,11 +631,18 @@
     StringRef Content(ContentBegin, ContentEnd-ContentBegin);
     size_t CPos = 0;
     size_t FPos;
+    bool Append = false;
     while ((FPos = Content.find(NewlineStr, CPos)) != StringRef::npos) {
       D.Text += Content.substr(CPos, FPos-CPos);
       D.Text += '\n';
       CPos = FPos + NewlineStr.size();
+      Append = true;
     }
+    // Previous while loop did not add line after final newline. If there is
+    // more text after the newline, append it here.
+    if (Append && CPos != Content.size())
+      D.Text += Content.substr(CPos, Content.size());
+
     if (D.Text.empty())
       D.Text.assign(ContentBegin, ContentEnd);
 


Index: clang/test/SemaCXX/references.cpp
===================================================================
--- clang/test/SemaCXX/references.cpp
+++ clang/test/SemaCXX/references.cpp
@@ -90,7 +90,7 @@
   int& okay; // expected-note{{reference member 'okay' will never be initialized}}
 };
 
-struct C : B, A { }; // expected-warning {{direct base 'A' is inaccessible due to ambiguity:\n    struct C -> struct B -> struct A\nstruct C -> struct A}}
+struct C : B, A { }; // expected-warning {{direct base 'A' is inaccessible due to ambiguity:\n    struct C -> struct B -> struct A\n    struct C -> struct A}}
 
 void test7(C& c) {
   A& a1 = c; // expected-error {{ambiguous conversion from derived class 'C' to base class 'A':}}
Index: clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
===================================================================
--- clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -631,11 +631,18 @@
     StringRef Content(ContentBegin, ContentEnd-ContentBegin);
     size_t CPos = 0;
     size_t FPos;
+    bool Append = false;
     while ((FPos = Content.find(NewlineStr, CPos)) != StringRef::npos) {
       D.Text += Content.substr(CPos, FPos-CPos);
       D.Text += '\n';
       CPos = FPos + NewlineStr.size();
+      Append = true;
     }
+    // Previous while loop did not add line after final newline. If there is
+    // more text after the newline, append it here.
+    if (Append && CPos != Content.size())
+      D.Text += Content.substr(CPos, Content.size());
+
     if (D.Text.empty())
       D.Text.assign(ContentBegin, ContentEnd);
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D126908: [VerifyDiagnost... Vang Thao via Phabricator via cfe-commits

Reply via email to