From 599788806ada4be1d635304104165500d6f9668d Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 8 Jul 2009 22:42:46 +0000 Subject: [PATCH] Fix: ValueManager::makeIntVal(uint64_t X, QualType T) should return a 'Loc' when 'T' is a pointer git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75062 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Analysis/PathSensitive/ValueManager.h | 5 ++++- test/Analysis/misc-ps.m | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/clang/Analysis/PathSensitive/ValueManager.h b/include/clang/Analysis/PathSensitive/ValueManager.h index 36d1df2150..bbf77740c9 100644 --- a/include/clang/Analysis/PathSensitive/ValueManager.h +++ b/include/clang/Analysis/PathSensitive/ValueManager.h @@ -109,7 +109,10 @@ public: return nonloc::ConcreteInt(BasicVals.getValue(V, isUnsigned)); } - NonLoc makeIntVal(uint64_t X, QualType T) { + SVal makeIntVal(uint64_t X, QualType T) { + if (Loc::IsLocType(T)) + return loc::ConcreteInt(BasicVals.getValue(X, T)); + return nonloc::ConcreteInt(BasicVals.getValue(X, T)); } diff --git a/test/Analysis/misc-ps.m b/test/Analysis/misc-ps.m index 59578819f2..f82cf0b7f6 100644 --- a/test/Analysis/misc-ps.m +++ b/test/Analysis/misc-ps.m @@ -10,7 +10,7 @@ typedef signed char BOOL; typedef int NSInteger; typedef unsigned int NSUInteger; typedef struct _NSZone NSZone; -@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; +@class NSInvocation, NSArray, NSMethodSignature, NSCoder, NSString, NSEnumerator; @protocol NSObject - (BOOL)isEqual:(id)object; @end @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end @protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end @@ -313,3 +313,14 @@ void test_cast_from_incomplete_struct() { test_cast_from_incomplete_struct_aux(&_cmd); } +// Test for +// "ValueManager::makeIntVal(uint64_t X, QualType T) should return a 'Loc' +// when 'T' is a pointer" +// +// Previously this case would crash. +void test_rdar_7034511(NSArray *y) { + NSObject *x; + for (x in y) {} + if (x == ((void*) 0)) {} +} + -- 2.40.0