scott.linder added a comment.

In D123878#3506500 <https://reviews.llvm.org/D123878#3506500>, @afanfa wrote:

> If possible, I would like to keep some kind of delimiter. I like the idea of 
> having it at the beginning and at the end of the section. The best option 
> would be to convince clang to print new lines.

It seems like the stripping of non-printable characters is intentional, but 
only for diagnostics that don't use the TableGen based diagnostic formatting 
scheme in clang. I'm not sure exactly why, but regardless there is precedent 
for newlines in other messages.

To get the newlines to hit the terminal for our case the following patch is 
enough:

  --- a/clang/lib/Basic/Diagnostic.cpp
  +++ b/clang/lib/Basic/Diagnostic.cpp
  @@ -812,7 +812,7 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
         getArgKind(0) == DiagnosticsEngine::ak_std_string) {                   
                                                                                
                                                                                
                               const std::string &S = getArgStdStr(0);          
                                                                                
                                                                                
                                                       for (char c : S) {
  -      if (llvm::sys::locale::isPrint(c) || c == '\t') {
  +      if (llvm::sys::locale::isPrint(c) || c == '\t' || c == '\n') {
           OutStr.push_back(c);
         }
       }

To get the right indentation inserted for the extra lines the `TextDiagnostic` 
consumer needs to also be updated, but that should be a small change. Only one 
test breaks, and it seems useful for it to pick up the new behavior anyway.

The only other potential conflict is that in `TextDiagnostic` specifically 
there is also the Clang option `-fmessage-length=N` which will forcibly wrap 
diagnostic messages on word-boundaries (although never breaking up a word 
across lines). It seems to only apply to text preceding the first newline in 
the message, so it is likely just a non-issue?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123878/new/

https://reviews.llvm.org/D123878

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to