From: Zhongxing Xu Date: Tue, 23 Jun 2009 05:43:16 +0000 (+0000) Subject: If the init list is fewer than the struct fields, bind the rest fields to 0 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dbdf2195803e8e723f25176627caef05740cfbb1;p=clang If the init list is fewer than the struct fields, bind the rest fields to 0 explicitly. Make 0 value with the field type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73949 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index ff2145e26e..0d0f83d71c 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -1165,20 +1165,14 @@ RegionStoreManager::BindStruct(const GRState *state, const TypedRegion* R, nonloc::CompoundVal& CV = cast(V); nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end(); - - for (RecordDecl::field_iterator FI = RD->field_begin(getContext()), - FE = RD->field_end(getContext()); + + RecordDecl::field_iterator FI, FE; + + for (FI = RD->field_begin(getContext()), FE = RD->field_end(getContext()); FI != FE; ++FI, ++VI) { - // There may be fewer values than fields only when we are initializing a - // struct decl. In this case, mark the region as having default value. - if (VI == VE) { - // FIXME: We should bind signed/unsigned 0 according to the sign of the - // field type. - const NonLoc& Idx = NonLoc::MakeIntVal(getBasicVals(), 0, false); - state = state->set(R, Idx); + if (VI == VE) break; - } QualType FTy = (*FI)->getType(); FieldRegion* FR = MRMgr.getFieldRegion(*FI, R); @@ -1191,6 +1185,17 @@ RegionStoreManager::BindStruct(const GRState *state, const TypedRegion* R, state = BindStruct(state, FR, *VI); } + // There may be fewer values in the initialize list than the fields of struct. + while (FI != FE) { + QualType FTy = (*FI)->getType(); + if (FTy->isIntegerType()) { + FieldRegion* FR = MRMgr.getFieldRegion(*FI, R); + state = Bind(state, Loc::MakeVal(FR), ValMgr.makeZeroVal(FTy)); + } + + ++FI; + } + return state; }