diff options
| author | Ted Kremenek <kremenek@apple.com> | 2008-02-25 17:51:31 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2008-02-25 17:51:31 +0000 |
| commit | 6f92e2294abc8822f7ff4a09ca129f6a773f6be4 (patch) | |
| tree | dd66db529395b04d3e6f3af3a2f5e541e47d1ff8 /clang/Analysis/GRExprEngine.cpp | |
| parent | 896c519d195dd40db492a5b4941301f0fd12a70b (diff) | |
| download | bcm5719-llvm-6f92e2294abc8822f7ff4a09ca129f6a773f6be4.tar.gz bcm5719-llvm-6f92e2294abc8822f7ff4a09ca129f6a773f6be4.zip | |
Added transfer function support for checking for divide-by-zero errors.
llvm-svn: 47547
Diffstat (limited to 'clang/Analysis/GRExprEngine.cpp')
| -rw-r--r-- | clang/Analysis/GRExprEngine.cpp | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/clang/Analysis/GRExprEngine.cpp b/clang/Analysis/GRExprEngine.cpp index 2931d2aa6d8..74fadcc9e36 100644 --- a/clang/Analysis/GRExprEngine.cpp +++ b/clang/Analysis/GRExprEngine.cpp @@ -850,6 +850,33 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B, BinaryOperator::Opcode Op = B->getOpcode(); + if (Op == BinaryOperator::Div) { // Check for divide-by-zero. + + // First, "assume" that the denominator is 0. + + bool isFeasible = false; + StateTy ZeroSt = Assume(St, RightV, false, isFeasible); + + if (isFeasible) { + NodeTy* DivZeroNode = Builder->generateNode(B, ZeroSt, N2); + + if (DivZeroNode) { + DivZeroNode->markAsSink(); + DivZeroes.insert(DivZeroNode); + } + } + + // Second, "assume" that the denominator cannot be 0. + + isFeasible = false; + St = Assume(St, RightV, true, isFeasible); + + if (!isFeasible) + continue; + + // Fall-through. The logic below processes the divide. + } + if (Op <= BinaryOperator::Or) { // Process non-assignements except commas or short-circuited @@ -964,8 +991,35 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B, RightV = EvalCast(RightV, CTy); // Evaluate operands and promote to result type. + + if (Op == BinaryOperator::Div) { // Check for divide-by-zero. + + // First, "assume" that the denominator is 0. + + bool isFeasible = false; + StateTy ZeroSt = Assume(St, RightV, false, isFeasible); + + if (isFeasible) { + NodeTy* DivZeroNode = Builder->generateNode(B, ZeroSt, N2); + + if (DivZeroNode) { + DivZeroNode->markAsSink(); + DivZeroes.insert(DivZeroNode); + } + } + + // Second, "assume" that the denominator cannot be 0. + + isFeasible = false; + St = Assume(St, RightV, true, isFeasible); + + if (!isFeasible) + continue; + + // Fall-through. The logic below processes the divide. + } + RVal Result = EvalCast(EvalBinOp(Op, V, RightV), B->getType()); - St = SetRVal(SetRVal(St, B, Result), LeftLV, Result); } } |

