Teach -Wuninitialized-experimental about sizeof().

llvm-svn: 124076
This commit is contained in:
Ted Kremenek 2011-01-23 17:53:04 +00:00
parent 6f907e69e9
commit 8f01420d9d
2 changed files with 22 additions and 0 deletions

View File

@ -302,6 +302,7 @@ public:
void VisitUnaryOperator(UnaryOperator *uo);
void VisitBinaryOperator(BinaryOperator *bo);
void VisitCastExpr(CastExpr *ce);
void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *se);
};
}
@ -435,6 +436,15 @@ void TransferFunctions::VisitCastExpr(clang::CastExpr *ce) {
Visit(ce->getSubExpr());
}
void TransferFunctions::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *se) {
if (se->isSizeOf()) {
if (se->getType()->isConstantSizeType())
return;
// Handle VLAs.
Visit(se->getArgumentExpr());
}
}
//------------------------------------------------------------------------====//
// High-level "driver" logic for uninitialized values analysis.
//====------------------------------------------------------------------------//

View File

@ -180,3 +180,15 @@ MyInt test26() {
MyInt x; // expected-warning{{use of uninitialized variable 'x'}} expected-note{{add initialization to silence this warning}}
return x; // expected-note{{variable 'x' is possibly uninitialized when used here}}
}
// Test handling of sizeof().
int test27() {
struct test_27 { int x; } *y;
return sizeof(y->x); // no-warning
}
int test28() {
int len; // expected-warning{{use of uninitialized variable 'len'}} expected-note{{add initialization to silence this warning}}
return sizeof(int[len]); // expected-note{{variable 'len' is possibly uninitialized when used here}}
}