From 9660803cd332d5c605899435019bb3b37fca3acc Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sun, 23 Jan 2011 17:53:04 +0000 Subject: [PATCH] Teach -Wuninitialized-experimental about sizeof(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124076 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/UninitializedValuesV2.cpp | 10 ++++++++++ test/Sema/uninit-variables.c | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/Analysis/UninitializedValuesV2.cpp b/lib/Analysis/UninitializedValuesV2.cpp index dfaff314e2..4c54885413 100644 --- a/lib/Analysis/UninitializedValuesV2.cpp +++ b/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/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c index aed7a70966..faf94c024b 100644 --- a/test/Sema/uninit-variables.c +++ b/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}} +} + -- 2.40.0