[PATCH] D25596: alpha.core.Conversion - Fix false positive for 'U32 += S16; ' expression, that is not unsafe
Daniel Marjamäki via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 14 01:56:11 PDT 2016
danielmarjamaki created this revision.
danielmarjamaki added a reviewer: NoQ.
danielmarjamaki added subscribers: cfe-commits, xazax.hun, dcoughlin.
danielmarjamaki set the repository for this revision to rL LLVM.
This patch fix false positives for loss of sign in addition and subtraction assignment operators.
Repository:
rL LLVM
https://reviews.llvm.org/D25596
Files:
lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
test/Analysis/conversion.c
Index: test/Analysis/conversion.c
===================================================================
--- test/Analysis/conversion.c
+++ test/Analysis/conversion.c
@@ -77,6 +77,10 @@
void dontwarn5() {
signed S = -32;
U8 = S + 10;
+
+ unsigned x = 100;
+ signed short delta = -1;
+ x += delta;
}
Index: lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
+++ lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
@@ -73,10 +73,13 @@
// Loss of sign/precision in binary operation.
if (const auto *B = dyn_cast<BinaryOperator>(Parent)) {
BinaryOperator::Opcode Opc = B->getOpcode();
- if (Opc == BO_Assign || Opc == BO_AddAssign || Opc == BO_SubAssign ||
- Opc == BO_MulAssign) {
- LossOfSign = isLossOfSign(Cast, C);
- LossOfPrecision = isLossOfPrecision(Cast, C);
+ if (B->isAssignmentOp()) {
+ if (Opc == BO_Assign || Opc == BO_AddAssign || Opc == BO_SubAssign ||
+ Opc == BO_MulAssign || Opc == BO_OrAssign || Opc == BO_XorAssign)
+ LossOfPrecision = isLossOfPrecision(Cast, C);
+ if (Opc == BO_Assign || Opc == BO_MulAssign || Opc == BO_DivAssign ||
+ Opc == BO_RemAssign)
+ LossOfSign = isLossOfSign(Cast, C);
} else if (B->isRelationalOp() || B->isMultiplicativeOp()) {
LossOfSign = isLossOfSign(Cast, C);
}
@@ -153,7 +156,7 @@
}
bool ConversionChecker::isLossOfPrecision(const ImplicitCastExpr *Cast,
- CheckerContext &C) const {
+ CheckerContext &C) const {
// Don't warn about explicit loss of precision.
if (Cast->isEvaluatable(C.getASTContext()))
return false;
@@ -177,7 +180,7 @@
}
bool ConversionChecker::isLossOfSign(const ImplicitCastExpr *Cast,
- CheckerContext &C) const {
+ CheckerContext &C) const {
QualType CastType = Cast->getType();
QualType SubType = Cast->IgnoreParenImpCasts()->getType();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25596.74623.patch
Type: text/x-patch
Size: 2116 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161014/bd434061/attachment-0001.bin>
More information about the cfe-commits
mailing list