Author: szelethus Date: Fri Apr 19 16:33:50 2019 New Revision: 358797 URL: http://llvm.org/viewvc/llvm-project?rev=358797&view=rev Log: [analyzer] Move UninitializedObjectChecker out of alpha
Moved UninitializedObjectChecker from the 'alpha.cplusplus' to the 'optin.cplusplus' package. Differential Revision: https://reviews.llvm.org/D58573 Modified: cfe/trunk/docs/analyzer/checkers.rst cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h cfe/trunk/test/Analysis/cxx-uninitialized-object-inheritance.cpp cfe/trunk/test/Analysis/cxx-uninitialized-object-no-dereference.cpp cfe/trunk/test/Analysis/cxx-uninitialized-object-notes-as-warnings.cpp cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp cfe/trunk/test/Analysis/cxx-uninitialized-object-unguarded-access.cpp cfe/trunk/test/Analysis/cxx-uninitialized-object-unionlike-constructs.cpp cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp cfe/trunk/test/Analysis/objcpp-uninitialized-object.mm cfe/trunk/www/analyzer/alpha_checks.html cfe/trunk/www/analyzer/available_checks.html Modified: cfe/trunk/docs/analyzer/checkers.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/analyzer/checkers.rst?rev=358797&r1=358796&r2=358797&view=diff ============================================================================== --- cfe/trunk/docs/analyzer/checkers.rst (original) +++ cfe/trunk/docs/analyzer/checkers.rst Fri Apr 19 16:33:50 2019 @@ -339,6 +339,110 @@ optin Checkers for portability, performance or coding style specific rules. +optin.cplusplus.UninitializedObject (C++) +""""""""""""""""""""""""""""""""""" + +This checker reports uninitialized fields in objects created after a constructor +call. It doesn't only find direct uninitialized fields, but rather makes a deep +inspection of the object, analyzing all of it's fields subfields. +The checker regards inherited fields as direct fields, so one will recieve +warnings for uninitialized inherited data members as well. + +.. code-block:: cpp + + // With Pedantic and CheckPointeeInitialization set to true + + struct A { + struct B { + int x; // note: uninitialized field 'this->b.x' + // note: uninitialized field 'this->bptr->x' + int y; // note: uninitialized field 'this->b.y' + // note: uninitialized field 'this->bptr->y' + }; + int *iptr; // note: uninitialized pointer 'this->iptr' + B b; + B *bptr; + char *cptr; // note: uninitialized pointee 'this->cptr' + + A (B *bptr, char *cptr) : bptr(bptr), cptr(cptr) {} + }; + + void f() { + A::B b; + char c; + A a(&b, &c); // warning: 6 uninitialized fields + // after the constructor call + } + + // With Pedantic set to false and + // CheckPointeeInitialization set to true + // (every field is uninitialized) + + struct A { + struct B { + int x; + int y; + }; + int *iptr; + B b; + B *bptr; + char *cptr; + + A (B *bptr, char *cptr) : bptr(bptr), cptr(cptr) {} + }; + + void f() { + A::B b; + char c; + A a(&b, &c); // no warning + } + + // With Pedantic set to true and + // CheckPointeeInitialization set to false + // (pointees are regarded as initialized) + + struct A { + struct B { + int x; // note: uninitialized field 'this->b.x' + int y; // note: uninitialized field 'this->b.y' + }; + int *iptr; // note: uninitialized pointer 'this->iptr' + B b; + B *bptr; + char *cptr; + + A (B *bptr, char *cptr) : bptr(bptr), cptr(cptr) {} + }; + + void f() { + A::B b; + char c; + A a(&b, &c); // warning: 3 uninitialized fields + // after the constructor call + } + + +**Options** + +This checker has several options which can be set from command line (e.g. +``-analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true``): + +* ``Pedantic`` (boolean). If to false, the checker won't emit warnings for + objects that don't have at least one initialized field. Defaults to false. + +* ``NotesAsWarnings`` (boolean). If set to true, the checker will emit a + warning for each uninitalized field, as opposed to emitting one warning per + constructor call, and listing the uninitialized fields that belongs to it in + notes. *Defaults to false*. + +* ``CheckPointeeInitialization`` (boolean). If set to false, the checker will + not analyze the pointee of pointer/reference fields, and will only check + whether the object itself is initialized. *Defaults to false*. + +* ``IgnoreRecordsWithField`` (string). If supplied, the checker will not analyze + structures that have a field with a name or type name that matches the given + pattern. *Defaults to ""*. + optin.cplusplus.VirtualCall (C++) """"""""""""""""""""""""""""""""" Check virtual function calls during construction or destruction. @@ -1383,102 +1487,6 @@ Method calls on a moved-from object and a.foo(); // warn: method call on a 'moved-from' object 'a' } -alpha.cplusplus.UninitializedObject (C++) -""""""""""""""""""""""""""""""""""""""""" - -This checker reports uninitialized fields in objects created after a constructor call. -It doesn't only find direct uninitialized fields, but rather makes a deep inspection -of the object, analyzing all of it's fields subfields. -The checker regards inherited fields as direct fields, so one will -recieve warnings for uninitialized inherited data members as well. - -.. code-block:: cpp - - // With Pedantic and CheckPointeeInitialization set to true - - struct A { - struct B { - int x; // note: uninitialized field 'this->b.x' - // note: uninitialized field 'this->bptr->x' - int y; // note: uninitialized field 'this->b.y' - // note: uninitialized field 'this->bptr->y' - }; - int *iptr; // note: uninitialized pointer 'this->iptr' - B b; - B *bptr; - char *cptr; // note: uninitialized pointee 'this->cptr' - - A (B *bptr, char *cptr) : bptr(bptr), cptr(cptr) {} - }; - - void f() { - A::B b; - char c; - A a(&b, &c); // warning: 6 uninitialized fields - // after the constructor call - } - - // With Pedantic set to false and - // CheckPointeeInitialization set to true - // (every field is uninitialized) - - struct A { - struct B { - int x; - int y; - }; - int *iptr; - B b; - B *bptr; - char *cptr; - - A (B *bptr, char *cptr) : bptr(bptr), cptr(cptr) {} - }; - - void f() { - A::B b; - char c; - A a(&b, &c); // no warning - } - - // With Pedantic set to true and - // CheckPointeeInitialization set to false - // (pointees are regarded as initialized) - - struct A { - struct B { - int x; // note: uninitialized field 'this->b.x' - int y; // note: uninitialized field 'this->b.y' - }; - int *iptr; // note: uninitialized pointer 'this->iptr' - B b; - B *bptr; - char *cptr; - - A (B *bptr, char *cptr) : bptr(bptr), cptr(cptr) {} - }; - - void f() { - A::B b; - char c; - A a(&b, &c); // warning: 3 uninitialized fields - // after the constructor call - } - - -**Options** - -This checker has several options which can be set from command line (e.g. ``-analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true``): - -* ``Pedantic`` (boolean). If to false, the checker won't emit warnings for objects that don't have at least one initialized field. Defaults to false. - -* ``NotesAsWarnings`` (boolean). If set to true, the checker will emit a warning for each uninitalized field, as opposed to emitting one warning per constructor call, and listing the uninitialized fields that belongs to it in notes. *Defaults to false.*. - -* ``CheckPointeeInitialization`` (boolean). If set to false, the checker will not analyze the pointee of pointer/reference fields, and will only check whether the object itself is initialized. *Defaults to false.*. - -* ``IgnoreRecordsWithField`` (string). If supplied, the checker will not analyze structures that have a field with a name or type name that matches the given pattern. *Defaults to ""*. Can be set with ``-analyzer-config alpha.cplusplus.UninitializedObject:IgnoreRecordsWithField="[Tt]ag|[Kk]ind"``. - - alpha.deadcode ^^^^^^^^^^^^^^ alpha.deadcode.UnreachableCode (C, C++) Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=358797&r1=358796&r2=358797&view=diff ============================================================================== --- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original) +++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Fri Apr 19 16:33:50 2019 @@ -493,6 +493,43 @@ def MoveChecker: Checker<"Move">, let ParentPackage = CplusplusOptIn in { +def UninitializedObjectChecker: Checker<"UninitializedObject">, + HelpText<"Reports uninitialized fields after object construction">, + CheckerOptions<[ + CmdLineOption<Boolean, + "Pedantic", + "If set to false, the checker won't emit warnings " + "for objects that don't have at least one initialized " + "field.", + "false">, + CmdLineOption<Boolean, + "NotesAsWarnings", + "If set to true, the checker will emit a warning " + "for each uninitalized field, as opposed to emitting one " + "warning per constructor call, and listing the uninitialized " + "fields that belongs to it in notes.", + "false">, + CmdLineOption<Boolean, + "CheckPointeeInitialization", + "If set to false, the checker will not analyze " + "the pointee of pointer/reference fields, and will only " + "check whether the object itself is initialized.", + "false">, + CmdLineOption<String, + "IgnoreRecordsWithField", + "If supplied, the checker will not analyze " + "structures that have a field with a name or type name that " + "matches the given pattern.", + "\"\"">, + CmdLineOption<Boolean, + "IgnoreGuardedFields", + "If set to true, the checker will analyze _syntactically_ " + "whether the found uninitialized object is used without a " + "preceding assert call. Defaults to false.", + "false"> + ]>, + Documentation<HasAlphaDocumentation>; + def VirtualCallChecker : Checker<"VirtualCall">, HelpText<"Check virtual function calls during construction or destruction">, CheckerOptions<[ @@ -536,43 +573,6 @@ def MismatchedIteratorChecker : Checker< Dependencies<[IteratorModeling]>, Documentation<HasAlphaDocumentation>; -def UninitializedObjectChecker: Checker<"UninitializedObject">, - HelpText<"Reports uninitialized fields after object construction">, - CheckerOptions<[ - CmdLineOption<Boolean, - "Pedantic", - "If set to false, the checker won't emit warnings " - "for objects that don't have at least one initialized " - "field.", - "false">, - CmdLineOption<Boolean, - "NotesAsWarnings", - "If set to true, the checker will emit a warning " - "for each uninitalized field, as opposed to emitting one " - "warning per constructor call, and listing the uninitialized " - "fields that belongs to it in notes.", - "false">, - CmdLineOption<Boolean, - "CheckPointeeInitialization", - "If set to false, the checker will not analyze " - "the pointee of pointer/reference fields, and will only " - "check whether the object itself is initialized.", - "false">, - CmdLineOption<String, - "IgnoreRecordsWithField", - "If supplied, the checker will not analyze " - "structures that have a field with a name or type name that " - "matches the given pattern.", - "\"\"">, - CmdLineOption<Boolean, - "IgnoreGuardedFields", - "If set to true, the checker will analyze _syntactically_ " - "whether the found uninitialized object is used without a " - "preceding assert call. Defaults to false.", - "false"> - ]>, - Documentation<HasAlphaDocumentation>; - } // end: "alpha.cplusplus" Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h?rev=358797&r1=358796&r2=358797&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h Fri Apr 19 16:33:50 2019 @@ -17,7 +17,7 @@ // won't emit warnings for objects that don't have at least one initialized // field. This may be set with // -// `-analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true`. +// `-analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true`. // // - "NotesAsWarnings" (boolean). If set to true, the checker will emit a // warning for each uninitialized field, as opposed to emitting one warning @@ -25,14 +25,14 @@ // to it in notes. Defaults to false. // // `-analyzer-config \ -// alpha.cplusplus.UninitializedObject:NotesAsWarnings=true`. +// optin.cplusplus.UninitializedObject:NotesAsWarnings=true`. // // - "CheckPointeeInitialization" (boolean). If set to false, the checker will // not analyze the pointee of pointer/reference fields, and will only check // whether the object itself is initialized. Defaults to false. // // `-analyzer-config \ -// alpha.cplusplus.UninitializedObject:CheckPointeeInitialization=true`. +// optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true`. // // TODO: With some clever heuristics, some pointers should be dereferenced // by default. For example, if the pointee is constructed within the @@ -45,14 +45,14 @@ // matches the given pattern. Defaults to "". // // `-analyzer-config \ -// alpha.cplusplus.UninitializedObject:IgnoreRecordsWithField="[Tt]ag|[Kk]ind"`. +// optin.cplusplus.UninitializedObject:IgnoreRecordsWithField="[Tt]ag|[Kk]ind"`. // // - "IgnoreGuardedFields" (boolean). If set to true, the checker will analyze // _syntactically_ whether the found uninitialized object is used without a // preceding assert call. Defaults to false. // // `-analyzer-config \ -// alpha.cplusplus.UninitializedObject:IgnoreGuardedFields=true`. +// optin.cplusplus.UninitializedObject:IgnoreGuardedFields=true`. // // Most of the following methods as well as the checker itself is defined in // UninitializedObjectChecker.cpp. Modified: cfe/trunk/test/Analysis/cxx-uninitialized-object-inheritance.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cxx-uninitialized-object-inheritance.cpp?rev=358797&r1=358796&r2=358797&view=diff ============================================================================== --- cfe/trunk/test/Analysis/cxx-uninitialized-object-inheritance.cpp (original) +++ cfe/trunk/test/Analysis/cxx-uninitialized-object-inheritance.cpp Fri Apr 19 16:33:50 2019 @@ -1,6 +1,6 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject \ -// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \ -// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:CheckPointeeInitialization=true \ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \ +// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \ +// RUN: -analyzer-config optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true \ // RUN: -std=c++11 -verify %s //===----------------------------------------------------------------------===// Modified: cfe/trunk/test/Analysis/cxx-uninitialized-object-no-dereference.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cxx-uninitialized-object-no-dereference.cpp?rev=358797&r1=358796&r2=358797&view=diff ============================================================================== --- cfe/trunk/test/Analysis/cxx-uninitialized-object-no-dereference.cpp (original) +++ cfe/trunk/test/Analysis/cxx-uninitialized-object-no-dereference.cpp Fri Apr 19 16:33:50 2019 @@ -1,4 +1,4 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject \ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \ // RUN: -std=c++11 -DPEDANTIC -verify %s class UninitPointerTest { Modified: cfe/trunk/test/Analysis/cxx-uninitialized-object-notes-as-warnings.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cxx-uninitialized-object-notes-as-warnings.cpp?rev=358797&r1=358796&r2=358797&view=diff ============================================================================== --- cfe/trunk/test/Analysis/cxx-uninitialized-object-notes-as-warnings.cpp (original) +++ cfe/trunk/test/Analysis/cxx-uninitialized-object-notes-as-warnings.cpp Fri Apr 19 16:33:50 2019 @@ -1,6 +1,6 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject \ -// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:NotesAsWarnings=true \ -// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:CheckPointeeInitialization=true \ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \ +// RUN: -analyzer-config optin.cplusplus.UninitializedObject:NotesAsWarnings=true \ +// RUN: -analyzer-config optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true \ // RUN: -std=c++11 -verify %s class NotesAsWarningsTest { Modified: cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp?rev=358797&r1=358796&r2=358797&view=diff ============================================================================== --- cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp (original) +++ cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp Fri Apr 19 16:33:50 2019 @@ -1,10 +1,10 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject \ -// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \ -// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:CheckPointeeInitialization=true \ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \ +// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \ +// RUN: -analyzer-config optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true \ // RUN: -std=c++11 -verify %s -// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject \ -// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:CheckPointeeInitialization=true \ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \ +// RUN: -analyzer-config optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true \ // RUN: -std=c++11 -verify %s //===----------------------------------------------------------------------===// Modified: cfe/trunk/test/Analysis/cxx-uninitialized-object-unguarded-access.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cxx-uninitialized-object-unguarded-access.cpp?rev=358797&r1=358796&r2=358797&view=diff ============================================================================== --- cfe/trunk/test/Analysis/cxx-uninitialized-object-unguarded-access.cpp (original) +++ cfe/trunk/test/Analysis/cxx-uninitialized-object-unguarded-access.cpp Fri Apr 19 16:33:50 2019 @@ -1,6 +1,6 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject \ -// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \ -// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:IgnoreGuardedFields=true \ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \ +// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \ +// RUN: -analyzer-config optin.cplusplus.UninitializedObject:IgnoreGuardedFields=true \ // RUN: -std=c++11 -verify %s //===----------------------------------------------------------------------===// Modified: cfe/trunk/test/Analysis/cxx-uninitialized-object-unionlike-constructs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cxx-uninitialized-object-unionlike-constructs.cpp?rev=358797&r1=358796&r2=358797&view=diff ============================================================================== --- cfe/trunk/test/Analysis/cxx-uninitialized-object-unionlike-constructs.cpp (original) +++ cfe/trunk/test/Analysis/cxx-uninitialized-object-unionlike-constructs.cpp Fri Apr 19 16:33:50 2019 @@ -1,17 +1,17 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject \ -// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \ -// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:IgnoreRecordsWithField="[Tt]ag|[Kk]ind" \ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \ +// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \ +// RUN: -analyzer-config optin.cplusplus.UninitializedObject:IgnoreRecordsWithField="[Tt]ag|[Kk]ind" \ // RUN: -std=c++11 -verify %s // RUN: not %clang_analyze_cc1 -verify %s \ // RUN: -analyzer-checker=core \ -// RUN: -analyzer-checker=alpha.cplusplus.UninitializedObject \ +// RUN: -analyzer-checker=optin.cplusplus.UninitializedObject \ // RUN: -analyzer-config \ -// RUN: alpha.cplusplus.UninitializedObject:IgnoreRecordsWithField="([)]" \ +// RUN: optin.cplusplus.UninitializedObject:IgnoreRecordsWithField="([)]" \ // RUN: 2>&1 | FileCheck %s -check-prefix=CHECK-UNINIT-INVALID-REGEX // CHECK-UNINIT-INVALID-REGEX: (frontend): invalid input for checker option -// CHECK-UNINIT-INVALID-REGEX-SAME: 'alpha.cplusplus.UninitializedObject:IgnoreRecordsWithField', +// CHECK-UNINIT-INVALID-REGEX-SAME: 'optin.cplusplus.UninitializedObject:IgnoreRecordsWithField', // CHECK-UNINIT-INVALID-REGEX-SAME: that expects a valid regex, building failed // CHECK-UNINIT-INVALID-REGEX-SAME: with error message "parentheses not // CHECK-UNINIT-INVALID-REGEX-SAME: balanced" Modified: cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp?rev=358797&r1=358796&r2=358797&view=diff ============================================================================== --- cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp (original) +++ cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp Fri Apr 19 16:33:50 2019 @@ -1,10 +1,10 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject \ -// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \ -// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:CheckPointeeInitialization=true \ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \ +// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \ +// RUN: -analyzer-config optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true \ // RUN: -std=c++14 -verify %s -// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject \ -// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:CheckPointeeInitialization=true \ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \ +// RUN: -analyzer-config optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true \ // RUN: -std=c++14 -verify %s //===----------------------------------------------------------------------===// Modified: cfe/trunk/test/Analysis/objcpp-uninitialized-object.mm URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/objcpp-uninitialized-object.mm?rev=358797&r1=358796&r2=358797&view=diff ============================================================================== --- cfe/trunk/test/Analysis/objcpp-uninitialized-object.mm (original) +++ cfe/trunk/test/Analysis/objcpp-uninitialized-object.mm Fri Apr 19 16:33:50 2019 @@ -1,4 +1,4 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject -std=c++11 -fblocks -verify %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject -std=c++11 -fblocks -verify %s typedef void (^myBlock) (); Modified: cfe/trunk/www/analyzer/alpha_checks.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/analyzer/alpha_checks.html?rev=358797&r1=358796&r2=358797&view=diff ============================================================================== --- cfe/trunk/www/analyzer/alpha_checks.html (original) +++ cfe/trunk/www/analyzer/alpha_checks.html Fri Apr 19 16:33:50 2019 @@ -445,120 +445,6 @@ void f() { </pre></div></div></td></tr> -<tr><td><a id="alpha.cplusplus.UninitializedObject"><div class="namedescr expandable"><span class="name"> -alpha.cplusplus.UninitializedObject</span><span class="lang"> -(C++)</span><div class="descr"> -This checker reports uninitialized fields in objects created after a constructor -call. It doesn't only find direct uninitialized fields, but rather makes a deep -inspection of the object, analyzing all of it's fields subfields. <br> -The checker regards inherited fields as direct fields, so one will recieve -warnings for uninitialized inherited data members as well. <br> -<br> -It has several options: -<ul> - <li> - "<code>Pedantic</code>" (boolean). If its not set or is set to false, the - checker won't emit warnings for objects that don't have at least one - initialized field. This may be set with <br> - <code>-analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true</code>. - </li> - <li> - "<code>NotesAsWarnings</code>" (boolean). If set to true, the checker will - emit a warning for each uninitalized field, as opposed to emitting one - warning per constructor call, and listing the uninitialized fields that - belongs to it in notes. Defaults to false. <br> - <code>-analyzer-config alpha.cplusplus.UninitializedObject:NotesAsWarnings=true</code>. - </li> - <li> - "<code>CheckPointeeInitialization</code>" (boolean). If set to false, the - checker will not analyze the pointee of pointer/reference fields, and will - only check whether the object itself is initialized. Defaults to false. <br> - <code>-analyzer-config alpha.cplusplus.UninitializedObject:CheckPointeeInitialization=true</code>. - </li> - <li> - "<code>IgnoreRecordsWithField</code>" (string). If supplied, the checker - will not analyze structures that have a field with a name or type name that - matches the given pattern. Defaults to <code>""</code>. - - <code>-analyzer-config alpha.cplusplus.UninitializedObject:IgnoreRecordsWithField="[Tt]ag|[Kk]ind"</code>. - </li> -</ul></div></div></a></td> -<td><div class="exampleContainer expandable"> -<div class="example"><pre> -// With Pedantic and CheckPointeeInitialization set to true - -struct A { - struct B { - int x; // note: uninitialized field 'this->b.x' - // note: uninitialized field 'this->bptr->x' - int y; // note: uninitialized field 'this->b.y' - // note: uninitialized field 'this->bptr->y' - }; - int *iptr; // note: uninitialized pointer 'this->iptr' - B b; - B *bptr; - char *cptr; // note: uninitialized pointee 'this->cptr' - - A (B *bptr, char *cptr) : bptr(bptr), cptr(cptr) {} -}; - -void f() { - A::B b; - char c; - A a(&b, &c); // warning: 6 uninitialized fields - // after the constructor call -} -</pre></div><div class="separator"></div> -<div class="example"><pre> -// With Pedantic set to false and -// CheckPointeeInitialization set to true -// (every field is uninitialized) - -struct A { - struct B { - int x; - int y; - }; - int *iptr; - B b; - B *bptr; - char *cptr; - - A (B *bptr, char *cptr) : bptr(bptr), cptr(cptr) {} -}; - -void f() { - A::B b; - char c; - A a(&b, &c); // no warning -} -</pre></div><div class="separator"></div> -<div class="example"><pre> -// With Pedantic and CheckPointeeInitialization set to false -// (pointees are regarded as initialized) - -struct A { - struct B { - int x; // note: uninitialized field 'this->b.x' - int y; // note: uninitialized field 'this->b.y' - }; - int *iptr; // note: uninitialized pointer 'this->iptr' - B b; - B *bptr; - char *cptr; - - A (B *bptr, char *cptr) : bptr(bptr), cptr(cptr) {} -}; - -void f() { - A::B b; - char c; - A a(&b, &c); // warning: 3 uninitialized fields - // after the constructor call -} -</pre></div></div></td></tr> - - </tbody></table> Modified: cfe/trunk/www/analyzer/available_checks.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/analyzer/available_checks.html?rev=358797&r1=358796&r2=358797&view=diff ============================================================================== --- cfe/trunk/www/analyzer/available_checks.html (original) +++ cfe/trunk/www/analyzer/available_checks.html Fri Apr 19 16:33:50 2019 @@ -543,6 +543,119 @@ void test() { <colgroup><col class="namedescr"><col class="example"></colgroup> <thead><tr><td>Name, Description</td><td>Example</td></tr></thead> +<tr><td><a id="cplusplus.UninitializedObject"><div class="namedescr expandable"><span class="name"> +cplusplus.UninitializedObject</span><span class="lang"> +(C++)</span><div class="descr"> +This checker reports uninitialized fields in objects created after a constructor +call. It doesn't only find direct uninitialized fields, but rather makes a deep +inspection of the object, analyzing all of it's fields subfields. <br> +The checker regards inherited fields as direct fields, so one will recieve +warnings for uninitialized inherited data members as well. <br> +<br> +It has several options: +<ul> + <li> + "<code>Pedantic</code>" (boolean). If its not set or is set to false, the + checker won't emit warnings for objects that don't have at least one + initialized field. This may be set with <br> + <code>-analyzer-config cplusplus.UninitializedObject:Pedantic=true</code>. + </li> + <li> + "<code>NotesAsWarnings</code>" (boolean). If set to true, the checker will + emit a warning for each uninitalized field, as opposed to emitting one + warning per constructor call, and listing the uninitialized fields that + belongs to it in notes. Defaults to false. <br> + <code>-analyzer-config cplusplus.UninitializedObject:NotesAsWarnings=true</code>. + </li> + <li> + "<code>CheckPointeeInitialization</code>" (boolean). If set to false, the + checker will not analyze the pointee of pointer/reference fields, and will + only check whether the object itself is initialized. Defaults to false. <br> + <code>-analyzer-config cplusplus.UninitializedObject:CheckPointeeInitialization=true</code>. + </li> + <li> + "<code>IgnoreRecordsWithField</code>" (string). If supplied, the checker + will not analyze structures that have a field with a name or type name that + matches the given pattern. Defaults to <code>""</code>. + + <code>-analyzer-config cplusplus.UninitializedObject:IgnoreRecordsWithField="[Tt]ag|[Kk]ind"</code>. + </li> +</ul></div></div></a></td> +<td><div class="exampleContainer expandable"> +<div class="example"><pre> +// With Pedantic and CheckPointeeInitialization set to true + +struct A { + struct B { + int x; // note: uninitialized field 'this->b.x' + // note: uninitialized field 'this->bptr->x' + int y; // note: uninitialized field 'this->b.y' + // note: uninitialized field 'this->bptr->y' + }; + int *iptr; // note: uninitialized pointer 'this->iptr' + B b; + B *bptr; + char *cptr; // note: uninitialized pointee 'this->cptr' + + A (B *bptr, char *cptr) : bptr(bptr), cptr(cptr) {} +}; + +void f() { + A::B b; + char c; + A a(&b, &c); // warning: 6 uninitialized fields + // after the constructor call +} +</pre></div><div class="separator"></div> +<div class="example"><pre> +// With Pedantic set to false and +// CheckPointeeInitialization set to true +// (every field is uninitialized) + +struct A { + struct B { + int x; + int y; + }; + int *iptr; + B b; + B *bptr; + char *cptr; + + A (B *bptr, char *cptr) : bptr(bptr), cptr(cptr) {} +}; + +void f() { + A::B b; + char c; + A a(&b, &c); // no warning +} +</pre></div><div class="separator"></div> +<div class="example"><pre> +// With Pedantic and CheckPointeeInitialization set to false +// (pointees are regarded as initialized) + +struct A { + struct B { + int x; // note: uninitialized field 'this->b.x' + int y; // note: uninitialized field 'this->b.y' + }; + int *iptr; // note: uninitialized pointer 'this->iptr' + B b; + B *bptr; + char *cptr; + + A (B *bptr, char *cptr) : bptr(bptr), cptr(cptr) {} +}; + +void f() { + A::B b; + char c; + A a(&b, &c); // warning: 3 uninitialized fields + // after the constructor call +} +</pre></div></div></td></tr> + <tbody> <tr><td><a id="optin.cplusplus.VirtualCall"><div class="namedescr expandable"><span class="name"> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits