]> granicus.if.org Git - clang/commitdiff
Replace the heuristic isSmallerThan with ASTContext::getTypeSize().
authorZhongxing Xu <xuzhongxing@gmail.com>
Fri, 8 May 2009 02:12:59 +0000 (02:12 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Fri, 8 May 2009 02:12:59 +0000 (02:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71206 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/RegionStore.cpp
test/Analysis/casts.c
test/Analysis/rdar-6541136-region.c

index ea42c465aa5fdc1dd405ef6a22c9f82fce9fe9be..32226af98f02b6dd36504c1d56378e18267aebd7 100644 (file)
@@ -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<VarRegion>(R) || isa<ElementRegion>(R) || isa<FieldRegion>(R)
       || isa<ObjCIvarRegion>(R) || isa<CompoundLiteralRegion>(R)) {
-    if (isSmallerThan(PointeeTy, 
-                      cast<TypedRegion>(R)->getRValueType(getContext()))) {
+    QualType ObjTy = cast<TypedRegion>(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);
 
index fa41961a45954d979632506b98055340c777c67c..94a1eac0a316a84d81874d0959ce6cf3ad2a29a5 100644 (file)
@@ -2,7 +2,6 @@
 
 // Test if the 'storage' region gets properly initialized after it is cast to
 // 'struct sockaddr *'. 
-// XFAIL
 
 #include <sys/socket.h>
 void f(int sock) {
index 1e7a2d974bc4d34b0e28dfbc6deb905d16c5bc76..58ec8e8bbf8bd0708c4c48fefd316b624e632ecc 100644 (file)
@@ -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;