From e6c28039c63d829577a2e37170e06a1dbdf89748 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 10 May 2011 22:10:35 +0000 Subject: [PATCH] Fix crash in -Wuninitialized when using switch statments whose condition is a logical operation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131158 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/UninitializedValues.cpp | 14 +++++++++----- test/Sema/uninit-variables.c | 13 +++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp index 88a2db751a..fc0b904c83 100644 --- a/lib/Analysis/UninitializedValues.cpp +++ b/lib/Analysis/UninitializedValues.cpp @@ -214,11 +214,15 @@ static BinaryOperator *getLogicalOperatorInChain(const CFGBlock *block) { if (!b || !b->isLogicalOp()) return 0; - if (block->pred_size() == 2 && - ((block->succ_size() == 2 && block->getTerminatorCondition() == b) || - block->size() == 1)) - return b; - + if (block->pred_size() == 2) { + if (block->getTerminatorCondition() == b) { + if (block->succ_size() == 2) + return b; + } + else if (block->size() == 1) + return b; + } + return 0; } diff --git a/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c index 60cae802ae..b70a29519c 100644 --- a/test/Sema/uninit-variables.c +++ b/test/Sema/uninit-variables.c @@ -339,3 +339,16 @@ int test51(void) return a; // no-warning } +// FIXME: This is a false positive, but it tests logical operations in switch statements. +int test52(int a, int b) { + int x; // expected-note {{variable 'x' is declared here}} expected-note {{add initialization to silence this warning}} + switch (a || b) { // expected-warning {{switch condition has boolean value}} + case 0: + x = 1; + break; + case 1: + x = 2; + break; + } + return x; // expected-warning {{variable 'x' may be uninitialized when used here}} +} -- 2.40.0