Improve BugReport diagnostics for loops and ? operator.
llvm-svn: 49356
This commit is contained in:
		
							parent
							
								
									c0f15487c6
								
							
						
					
					
						commit
						e73006ee45
					
				| 
						 | 
				
			
			@ -41,6 +41,11 @@ static inline Stmt* GetStmt(const ProgramPoint& P) {
 | 
			
		|||
  return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline Stmt* GetStmt(const CFGBlock* B) {
 | 
			
		||||
  assert (!B->empty());
 | 
			
		||||
  return (*B)[0];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
PathDiagnosticPiece*
 | 
			
		||||
BugDescription::getEndPath(ASTContext& Ctx, ExplodedNode<ValueState> *N) const {
 | 
			
		||||
| 
						 | 
				
			
			@ -217,10 +222,58 @@ void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD, ASTContext& Ctx,
 | 
			
		|||
          break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        case Stmt::ConditionalOperatorClass: {
 | 
			
		||||
          
 | 
			
		||||
          std::ostringstream os;
 | 
			
		||||
          os << "'?' condition evaluates to ";
 | 
			
		||||
 | 
			
		||||
          if (*(Src->succ_begin()+1) == Dst)
 | 
			
		||||
            os << "false.";
 | 
			
		||||
          else
 | 
			
		||||
            os << "true.";
 | 
			
		||||
          
 | 
			
		||||
          PD.push_front(new PathDiagnosticPiece(L, os.str()));
 | 
			
		||||
          
 | 
			
		||||
          break;
 | 
			
		||||
        }
 | 
			
		||||
          
 | 
			
		||||
        case Stmt::DoStmtClass:  {
 | 
			
		||||
          
 | 
			
		||||
          if (*(Src->succ_begin()) == Dst) {
 | 
			
		||||
            
 | 
			
		||||
            std::ostringstream os;          
 | 
			
		||||
            
 | 
			
		||||
            os << "Loop condition is true. Execution continues on line "
 | 
			
		||||
               << SMgr.getLogicalLineNumber(GetStmt(Dst)->getLocStart()) << '.';
 | 
			
		||||
            
 | 
			
		||||
            PD.push_front(new PathDiagnosticPiece(L, os.str()));
 | 
			
		||||
          }
 | 
			
		||||
          else
 | 
			
		||||
            PD.push_front(new PathDiagnosticPiece(L,
 | 
			
		||||
                              "Loop condition is false.  Exiting loop."));
 | 
			
		||||
          
 | 
			
		||||
          break;
 | 
			
		||||
        }
 | 
			
		||||
          
 | 
			
		||||
        case Stmt::DoStmtClass:
 | 
			
		||||
        case Stmt::WhileStmtClass:
 | 
			
		||||
        case Stmt::ForStmtClass:
 | 
			
		||||
        case Stmt::ForStmtClass: {
 | 
			
		||||
          
 | 
			
		||||
          if (*(Src->succ_begin()+1) == Dst) {
 | 
			
		||||
            
 | 
			
		||||
            std::ostringstream os;          
 | 
			
		||||
 | 
			
		||||
            os << "Loop condition is false. Execution continues on line "
 | 
			
		||||
               << SMgr.getLogicalLineNumber(GetStmt(Dst)->getLocStart()) << '.';
 | 
			
		||||
          
 | 
			
		||||
            PD.push_front(new PathDiagnosticPiece(L, os.str()));
 | 
			
		||||
          }
 | 
			
		||||
          else
 | 
			
		||||
            PD.push_front(new PathDiagnosticPiece(L,
 | 
			
		||||
                            "Loop condition is true.  Entering loop body."));
 | 
			
		||||
          
 | 
			
		||||
          break;
 | 
			
		||||
        }
 | 
			
		||||
          
 | 
			
		||||
        case Stmt::IfStmtClass: {
 | 
			
		||||
          
 | 
			
		||||
          if (*(Src->succ_begin()+1) == Dst)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue