@@ -440,7 +440,7 @@ static Result accumulateStructMembers(const Scope* scope, F f, ValueFlow::Accura
440440 for (const Variable& var : scope->varlist ) {
441441 if (var.isStatic ())
442442 continue ;
443- const size_t bits = var.nameToken () ? var.nameToken ()->bits () : 0 ;
443+ const char bits = var.nameToken () ? var.nameToken ()->bits () : - 1 ;
444444 if (const ValueType* vt = var.valueType ()) {
445445 if (vt->type == ValueType::Type::RECORD && vt->typeScope == scope)
446446 return {0 , false };
@@ -455,7 +455,7 @@ static Result accumulateStructMembers(const Scope* scope, F f, ValueFlow::Accura
455455 else
456456 total = f (total, *vt, dim, bits);
457457 }
458- if (accuracy == ValueFlow::Accuracy::ExactOrZero && total == 0 && bits == 0 )
458+ if (accuracy == ValueFlow::Accuracy::ExactOrZero && total == 0 && bits == - 1 )
459459 return {0 , false };
460460 }
461461 return {total, true };
@@ -537,10 +537,17 @@ size_t ValueFlow::getSizeOf(const ValueType &vt, const Settings &settings, Accur
537537 if (vt.type == ValueType::Type::RECORD && vt.typeScope ) {
538538 size_t currentBitCount = 0 ;
539539 size_t currentBitfieldAlloc = 0 ;
540- auto accHelper = [&](size_t total, const ValueType& vt2, size_t dim, size_t bits) -> size_t {
540+ auto accHelper = [&](size_t total, const ValueType& vt2, size_t dim, char bits) -> size_t {
541541 const size_t charBit = settings.platform .char_bit ;
542542 size_t n = ValueFlow::getSizeOf (vt2, settings,accuracy, ++maxRecursion);
543543 size_t a = getAlignOf (vt2, settings, accuracy);
544+ if (bits == 0 ) {
545+ if (currentBitfieldAlloc == 0 ) {
546+ bits = n * charBit;
547+ } else {
548+ bits = currentBitfieldAlloc * charBit - currentBitCount;
549+ }
550+ }
544551 if (bits > 0 ) {
545552 size_t ret = total;
546553 if (currentBitfieldAlloc == 0 ) {
0 commit comments