Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
//
//===----------------------------------------------------------------------===//

#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
#include "UninitializedObject.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"
#include "clang/include/clang/AST/Decl.h"

using namespace clang;
using namespace clang::ento;
Expand Down Expand Up @@ -291,7 +292,10 @@ bool FindUninitializedFields::isNonUnionUninit(const TypedValueRegion *R,

// Are all of this non-union's fields initialized?
for (const FieldDecl *I : RD->fields()) {

// Skip checking for unnamed bitfield
if (I->isUnnamedBitField()) {
continue;
}
const auto FieldVal =
State->getLValue(I, loc::MemRegionVal(R)).castAs<loc::MemRegionVal>();
const auto *FR = FieldVal.getRegionAs<FieldRegion>();
Expand Down
16 changes: 16 additions & 0 deletions clang/test/Analysis/unnamed_bitfield.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.UninitializedObject -verify %s
// expected-no-diagnostics

struct S
{
S(bool b)
: b(b)
{}
bool b{false};
long long : 7; // padding
};

void f()
{
S s(true);
}