llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.67k stars 10.92k forks source link

False positive for clang static analyzer checker optin.cplusplus.UninitializedObject #50658

Open llvmbot opened 2 years ago

llvmbot commented 2 years ago
Bugzilla Link 51316
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@zygoloid

Extended Description

Checker UninitializedObject is enable by default in clang-tidy and reports some false positives. Tests case(UninitializedObjectChecker_false_positive.cpp) :

struct Operand_ { int e; int a[2]; };

class b : Operand { public: b() : Operand{ 1, { 2, 3 }} {} };

void c() { b(); }


It returns wrong warning:


UninitializedObjectChecker_falsepositive.cpp:9:17: warning: 1 uninitialized field at the end of the constructor call [optin.cplusplus.UninitializedObject] b() : Operand{ 1, { 2, 3 }} {} ^~~~~~ UninitializedObjectChecker_falsepositive.cpp:3:7: note: uninitialized field 'this->Operand::e' int e; ^ 1 warning generated.

Arguments for clang-12 or clangs-13 in trunk:


clang-12 -c UninitializedObjectChecker_false_positive.cpp -Xclang -analyzer-checker=optin.cplusplus.UninitializedObject -Xclang -analyze


tiagomacarios commented 2 years ago

I think I just hit the same issue with a simpler repro.

Initializing S with {} triggers the false positive. () works fine.

https://godbolt.org/z/3rTdacqo7

struct S {
    int i1 = 0;
};

struct K : S {
    int ii1 = 0;
    K() : S() {}
    // K() : S{} {}
};

void _() {
    K k;
}