From fde2efe96e00c5d03e7caaf0c1e67d7b011d9d0c Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 15 Jul 2009 22:09:25 +0000 Subject: [PATCH] Fix by having BasicStoreManager model values for 'static' global variables. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75844 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/BasicStore.cpp | 4 ---- test/Analysis/misc-ps.m | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp index f1f051f244..7aa63c1c63 100644 --- a/lib/Analysis/BasicStore.cpp +++ b/lib/Analysis/BasicStore.cpp @@ -521,10 +521,6 @@ Store BasicStoreManager::getInitialStore() { } } else if (VarDecl* VD = dyn_cast(ND)) { - // Punt on static variables for now. - if (VD->getStorageClass() == VarDecl::Static) - continue; - // Only handle simple types that we can symbolicate. if (!SymbolManager::canSymbolicate(VD->getType())) continue; diff --git a/test/Analysis/misc-ps.m b/test/Analysis/misc-ps.m index 93bb1f347c..958576f455 100644 --- a/test/Analysis/misc-ps.m +++ b/test/Analysis/misc-ps.m @@ -388,3 +388,30 @@ void test_trivial_symbolic_comparison(int *x) { } } +// Test for: +// false positive null dereference due to +// BasicStoreManager not tracking *static* globals +// +// This just tests the proper tracking of symbolic values for globals (both +// static and non-static). +// +static int* x_rdar_7062158; +void rdar_7062158() { + int *current = x_rdar_7062158; + if (current == x_rdar_7062158) + return; + + int *p = 0; + *p = 0xDEADBEEF; // no-warning +} + +int* x_rdar_7062158_2; +void rdar_7062158_2() { + int *current = x_rdar_7062158_2; + if (current == x_rdar_7062158_2) + return; + + int *p = 0; + *p = 0xDEADBEEF; // no-warning +} + -- 2.50.1