From fb1e3310da7e3886c8057a5f009d2cdf30d8804f Mon Sep 17 00:00:00 2001 From: Zhongxing Xu Date: Fri, 8 May 2009 02:12:59 +0000 Subject: [PATCH] Replace the heuristic isSmallerThan with ASTContext::getTypeSize(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71206 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/RegionStore.cpp | 14 +++++--------- test/Analysis/casts.c | 1 - test/Analysis/rdar-6541136-region.c | 1 + 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index ea42c465aa..32226af98f 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -616,13 +616,6 @@ SVal RegionStoreManager::ArrayToPointer(Loc Array) { return loc::MemRegionVal(ER); } -static bool isSmallerThan(QualType T1, QualType T2) { - if (T1->isCharType()) - return true; - else - return false; -} - RegionStoreManager::CastResult RegionStoreManager::CastRegion(const GRState* state, const MemRegion* R, QualType CastToTy) { @@ -675,8 +668,11 @@ RegionStoreManager::CastRegion(const GRState* state, const MemRegion* R, // VarRegion. if (isa(R) || isa(R) || isa(R) || isa(R) || isa(R)) { - if (isSmallerThan(PointeeTy, - cast(R)->getRValueType(getContext()))) { + QualType ObjTy = cast(R)->getRValueType(getContext()); + uint64_t PointeeTySize = getContext().getTypeSize(PointeeTy); + uint64_t ObjTySize = getContext().getTypeSize(ObjTy); + + if (PointeeTySize > 0 && PointeeTySize < ObjTySize) { // Record the cast type of the region. state = setCastType(state, R, ToTy); diff --git a/test/Analysis/casts.c b/test/Analysis/casts.c index fa41961a45..94a1eac0a3 100644 --- a/test/Analysis/casts.c +++ b/test/Analysis/casts.c @@ -2,7 +2,6 @@ // Test if the 'storage' region gets properly initialized after it is cast to // 'struct sockaddr *'. -// XFAIL #include void f(int sock) { diff --git a/test/Analysis/rdar-6541136-region.c b/test/Analysis/rdar-6541136-region.c index 1e7a2d974b..58ec8e8bbf 100644 --- a/test/Analysis/rdar-6541136-region.c +++ b/test/Analysis/rdar-6541136-region.c @@ -1,4 +1,5 @@ // RUN: clang-cc -verify -analyze -checker-cfref -analyzer-store=region %s +// XFAIL struct tea_cheese { unsigned magic; }; typedef struct tea_cheese kernel_tea_cheese_t; -- 2.40.0