BugReporter: Use llvm::raw_string_stream instead of std::ostringstream.
llvm-svn: 64259
This commit is contained in:
		
							parent
							
								
									6abe6923e5
								
							
						
					
					
						commit
						a3d9025dd3
					
				| 
						 | 
					@ -24,7 +24,6 @@
 | 
				
			||||||
#include "llvm/Support/raw_ostream.h"
 | 
					#include "llvm/Support/raw_ostream.h"
 | 
				
			||||||
#include "llvm/ADT/DenseMap.h"
 | 
					#include "llvm/ADT/DenseMap.h"
 | 
				
			||||||
#include "llvm/ADT/STLExtras.h"
 | 
					#include "llvm/ADT/STLExtras.h"
 | 
				
			||||||
#include <sstream>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace clang;
 | 
					using namespace clang;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -75,27 +74,26 @@ static inline Stmt* GetStmt(const ExplodedNode<GRState>* N) {
 | 
				
			||||||
  return isa<BlockEntrance>(ProgP) ? GetLastStmt(N) : GetStmt(ProgP);
 | 
					  return isa<BlockEntrance>(ProgP) ? GetLastStmt(N) : GetStmt(ProgP);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void ExecutionContinues(std::ostringstream& os, SourceManager& SMgr,
 | 
					static void ExecutionContinues(llvm::raw_string_ostream& os,
 | 
				
			||||||
                               const Stmt* S) {
 | 
					                               SourceManager& SMgr,
 | 
				
			||||||
  
 | 
					                               const Stmt* S) {  
 | 
				
			||||||
  if (!S)
 | 
					  if (!S)
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  // Slow, but probably doesn't matter.
 | 
					  // Slow, but probably doesn't matter.
 | 
				
			||||||
  if (os.str().empty())
 | 
					  if (os.str().empty()) os << ' ';
 | 
				
			||||||
    os << ' ';
 | 
					 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  os << "Execution continues on line "
 | 
					  os << "Execution continues on line "
 | 
				
			||||||
  << SMgr.getInstantiationLineNumber(S->getLocStart()) << '.';
 | 
					     << SMgr.getInstantiationLineNumber(S->getLocStart()) << '.';
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline void ExecutionContinues(std::ostringstream& os,
 | 
					static inline void ExecutionContinues(llvm::raw_string_ostream& os,
 | 
				
			||||||
                                      SourceManager& SMgr,
 | 
					                                      SourceManager& SMgr,
 | 
				
			||||||
                                      const ExplodedNode<GRState>* N) {
 | 
					                                      const ExplodedNode<GRState>* N) {
 | 
				
			||||||
  ExecutionContinues(os, SMgr, GetStmt(N->getLocation()));
 | 
					  ExecutionContinues(os, SMgr, GetStmt(N->getLocation()));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline void ExecutionContinues(std::ostringstream& os,
 | 
					static inline void ExecutionContinues(llvm::raw_string_ostream& os,
 | 
				
			||||||
                                      SourceManager& SMgr,
 | 
					                                      SourceManager& SMgr,
 | 
				
			||||||
                                      const CFGBlock* B) {  
 | 
					                                      const CFGBlock* B) {  
 | 
				
			||||||
  ExecutionContinues(os, SMgr, GetStmt(B));
 | 
					  ExecutionContinues(os, SMgr, GetStmt(B));
 | 
				
			||||||
| 
						 | 
					@ -603,7 +601,8 @@ void GRBugReporter::GeneratePathDiagnostic(PathDiagnostic& PD,
 | 
				
			||||||
          if (!S)
 | 
					          if (!S)
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
          
 | 
					          
 | 
				
			||||||
          std::ostringstream os;
 | 
					          std::string sbuf;
 | 
				
			||||||
 | 
					          llvm::raw_string_ostream os(sbuf);
 | 
				
			||||||
          
 | 
					          
 | 
				
			||||||
          os << "Control jumps to line "
 | 
					          os << "Control jumps to line "
 | 
				
			||||||
             << SMgr.getInstantiationLineNumber(S->getLocStart()) << ".\n";
 | 
					             << SMgr.getInstantiationLineNumber(S->getLocStart()) << ".\n";
 | 
				
			||||||
| 
						 | 
					@ -612,11 +611,10 @@ void GRBugReporter::GeneratePathDiagnostic(PathDiagnostic& PD,
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
          
 | 
					          
 | 
				
			||||||
        case Stmt::SwitchStmtClass: {
 | 
					        case Stmt::SwitchStmtClass: {          
 | 
				
			||||||
          
 | 
					 | 
				
			||||||
          // Figure out what case arm we took.
 | 
					          // Figure out what case arm we took.
 | 
				
			||||||
 | 
					          std::string sbuf;
 | 
				
			||||||
          std::ostringstream os;
 | 
					          llvm::raw_string_ostream os(sbuf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          if (Stmt* S = Dst->getLabel())
 | 
					          if (Stmt* S = Dst->getLabel())
 | 
				
			||||||
            switch (S->getStmtClass()) {
 | 
					            switch (S->getStmtClass()) {
 | 
				
			||||||
| 
						 | 
					@ -663,9 +661,8 @@ void GRBugReporter::GeneratePathDiagnostic(PathDiagnostic& PD,
 | 
				
			||||||
                  continue;
 | 
					                  continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                llvm::raw_os_ostream OS(os);
 | 
					                os << V;
 | 
				
			||||||
                OS << V;
 | 
					              }       
 | 
				
			||||||
              }              
 | 
					 | 
				
			||||||
              
 | 
					              
 | 
				
			||||||
              os << ":'  at line " 
 | 
					              os << ":'  at line " 
 | 
				
			||||||
                 << SMgr.getInstantiationLineNumber(S->getLocStart()) << ".\n";
 | 
					                 << SMgr.getInstantiationLineNumber(S->getLocStart()) << ".\n";
 | 
				
			||||||
| 
						 | 
					@ -684,15 +681,16 @@ void GRBugReporter::GeneratePathDiagnostic(PathDiagnostic& PD,
 | 
				
			||||||
          
 | 
					          
 | 
				
			||||||
        case Stmt::BreakStmtClass:
 | 
					        case Stmt::BreakStmtClass:
 | 
				
			||||||
        case Stmt::ContinueStmtClass: {
 | 
					        case Stmt::ContinueStmtClass: {
 | 
				
			||||||
          std::ostringstream os;
 | 
					          std::string sbuf;
 | 
				
			||||||
 | 
					          llvm::raw_string_ostream os(sbuf);
 | 
				
			||||||
          ExecutionContinues(os, SMgr, LastNode);
 | 
					          ExecutionContinues(os, SMgr, LastNode);
 | 
				
			||||||
          PD.push_front(new PathDiagnosticPiece(L, os.str()));
 | 
					          PD.push_front(new PathDiagnosticPiece(L, os.str()));
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        case Stmt::ConditionalOperatorClass: {
 | 
					        case Stmt::ConditionalOperatorClass: {
 | 
				
			||||||
          
 | 
					          std::string sbuf;
 | 
				
			||||||
          std::ostringstream os;
 | 
					          llvm::raw_string_ostream os(sbuf);
 | 
				
			||||||
          os << "'?' condition evaluates to ";
 | 
					          os << "'?' condition evaluates to ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          if (*(Src->succ_begin()+1) == Dst)
 | 
					          if (*(Src->succ_begin()+1) == Dst)
 | 
				
			||||||
| 
						 | 
					@ -700,16 +698,15 @@ void GRBugReporter::GeneratePathDiagnostic(PathDiagnostic& PD,
 | 
				
			||||||
          else
 | 
					          else
 | 
				
			||||||
            os << "true.";
 | 
					            os << "true.";
 | 
				
			||||||
          
 | 
					          
 | 
				
			||||||
          PD.push_front(new PathDiagnosticPiece(L, os.str()));
 | 
					          PD.push_front(new PathDiagnosticPiece(L, os.str()));          
 | 
				
			||||||
          
 | 
					 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
          
 | 
					          
 | 
				
			||||||
        case Stmt::DoStmtClass:  {
 | 
					        case Stmt::DoStmtClass:  {
 | 
				
			||||||
          
 | 
					          
 | 
				
			||||||
          if (*(Src->succ_begin()) == Dst) {
 | 
					          if (*(Src->succ_begin()) == Dst) {
 | 
				
			||||||
            
 | 
					            std::string sbuf;
 | 
				
			||||||
            std::ostringstream os;          
 | 
					            llvm::raw_string_ostream os(sbuf);
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            os << "Loop condition is true. ";
 | 
					            os << "Loop condition is true. ";
 | 
				
			||||||
            ExecutionContinues(os, SMgr, Dst);
 | 
					            ExecutionContinues(os, SMgr, Dst);
 | 
				
			||||||
| 
						 | 
					@ -727,12 +724,12 @@ void GRBugReporter::GeneratePathDiagnostic(PathDiagnostic& PD,
 | 
				
			||||||
        case Stmt::ForStmtClass: {
 | 
					        case Stmt::ForStmtClass: {
 | 
				
			||||||
          
 | 
					          
 | 
				
			||||||
          if (*(Src->succ_begin()+1) == Dst) {
 | 
					          if (*(Src->succ_begin()+1) == Dst) {
 | 
				
			||||||
            
 | 
					            std::string sbuf;
 | 
				
			||||||
            std::ostringstream os;          
 | 
					            llvm::raw_string_ostream os(sbuf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            os << "Loop condition is false. ";
 | 
					            os << "Loop condition is false. ";
 | 
				
			||||||
            ExecutionContinues(os, SMgr, Dst);
 | 
					            ExecutionContinues(os, SMgr, Dst);
 | 
				
			||||||
          
 | 
					
 | 
				
			||||||
            PD.push_front(new PathDiagnosticPiece(L, os.str()));
 | 
					            PD.push_front(new PathDiagnosticPiece(L, os.str()));
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
          else
 | 
					          else
 | 
				
			||||||
| 
						 | 
					@ -742,8 +739,7 @@ void GRBugReporter::GeneratePathDiagnostic(PathDiagnostic& PD,
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
          
 | 
					          
 | 
				
			||||||
        case Stmt::IfStmtClass: {
 | 
					        case Stmt::IfStmtClass: {          
 | 
				
			||||||
          
 | 
					 | 
				
			||||||
          if (*(Src->succ_begin()+1) == Dst)
 | 
					          if (*(Src->succ_begin()+1) == Dst)
 | 
				
			||||||
            PD.push_front(new PathDiagnosticPiece(L, "Taking false branch."));
 | 
					            PD.push_front(new PathDiagnosticPiece(L, "Taking false branch."));
 | 
				
			||||||
          else 
 | 
					          else 
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue