diff options
| author | Ted Kremenek <kremenek@apple.com> | 2011-01-23 17:53:04 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2011-01-23 17:53:04 +0000 |
| commit | 8f01420d9d10c5ec56f917cc0f8923ff61647795 (patch) | |
| tree | 13ca2221c7a740efd7d7fcf74b20ddcbec689e7b | |
| parent | 6f907e69e9de7e59f94f664788cca86b96145648 (diff) | |
| download | bcm5719-llvm-8f01420d9d10c5ec56f917cc0f8923ff61647795.tar.gz bcm5719-llvm-8f01420d9d10c5ec56f917cc0f8923ff61647795.zip | |
Teach -Wuninitialized-experimental about sizeof().
llvm-svn: 124076
| -rw-r--r-- | clang/lib/Analysis/UninitializedValuesV2.cpp | 10 | ||||
| -rw-r--r-- | clang/test/Sema/uninit-variables.c | 12 |
2 files changed, 22 insertions, 0 deletions
diff --git a/clang/lib/Analysis/UninitializedValuesV2.cpp b/clang/lib/Analysis/UninitializedValuesV2.cpp index dfaff314e2f..4c548854131 100644 --- a/clang/lib/Analysis/UninitializedValuesV2.cpp +++ b/clang/lib/Analysis/UninitializedValuesV2.cpp @@ -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. //====------------------------------------------------------------------------// diff --git a/clang/test/Sema/uninit-variables.c b/clang/test/Sema/uninit-variables.c index aed7a709660..faf94c024bc 100644 --- a/clang/test/Sema/uninit-variables.c +++ b/clang/test/Sema/uninit-variables.c @@ -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}} +} + |

