Deleted Added
full compact
UninitializedObject.h (344779) UninitializedObject.h (353358)
1//===----- UninitializedObject.h ---------------------------------*- C++ -*-==//
2//
1//===----- UninitializedObject.h ---------------------------------*- C++ -*-==//
2//
3// The LLVM Compiler Infrastructure
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4//
6//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines helper classes for UninitializedObjectChecker and
11// documentation about the logic of it.
12//
13// The checker reports uninitialized fields in objects created after a
14// constructor call.
15//
16// This checker has several options:
17// - "Pedantic" (boolean). If its not set or is set to false, the checker
18// won't emit warnings for objects that don't have at least one initialized
19// field. This may be set with
20//
7//===----------------------------------------------------------------------===//
8//
9// This file defines helper classes for UninitializedObjectChecker and
10// documentation about the logic of it.
11//
12// The checker reports uninitialized fields in objects created after a
13// constructor call.
14//
15// This checker has several options:
16// - "Pedantic" (boolean). If its not set or is set to false, the checker
17// won't emit warnings for objects that don't have at least one initialized
18// field. This may be set with
19//
21// `-analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true`.
20// `-analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true`.
22//
23// - "NotesAsWarnings" (boolean). If set to true, the checker will emit a
24// warning for each uninitialized field, as opposed to emitting one warning
25// per constructor call, and listing the uninitialized fields that belongs
26// to it in notes. Defaults to false.
27//
28// `-analyzer-config \
21//
22// - "NotesAsWarnings" (boolean). If set to true, the checker will emit a
23// warning for each uninitialized field, as opposed to emitting one warning
24// per constructor call, and listing the uninitialized fields that belongs
25// to it in notes. Defaults to false.
26//
27// `-analyzer-config \
29// alpha.cplusplus.UninitializedObject:NotesAsWarnings=true`.
28// optin.cplusplus.UninitializedObject:NotesAsWarnings=true`.
30//
31// - "CheckPointeeInitialization" (boolean). If set to false, the checker will
32// not analyze the pointee of pointer/reference fields, and will only check
33// whether the object itself is initialized. Defaults to false.
34//
35// `-analyzer-config \
29//
30// - "CheckPointeeInitialization" (boolean). If set to false, the checker will
31// not analyze the pointee of pointer/reference fields, and will only check
32// whether the object itself is initialized. Defaults to false.
33//
34// `-analyzer-config \
36// alpha.cplusplus.UninitializedObject:CheckPointeeInitialization=true`.
35// optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true`.
37//
36//
37// TODO: With some clever heuristics, some pointers should be dereferenced
38// by default. For example, if the pointee is constructed within the
39// constructor call, it's reasonable to say that no external object
40// references it, and we wouldn't generate multiple report on the same
41// pointee.
42//
38// - "IgnoreRecordsWithField" (string). If supplied, the checker will not
39// analyze structures that have a field with a name or type name that
40// matches the given pattern. Defaults to "".
41//
42// `-analyzer-config \
43// - "IgnoreRecordsWithField" (string). If supplied, the checker will not
44// analyze structures that have a field with a name or type name that
45// matches the given pattern. Defaults to "".
46//
47// `-analyzer-config \
43// alpha.cplusplus.UninitializedObject:IgnoreRecordsWithField="[Tt]ag|[Kk]ind"`.
48// optin.cplusplus.UninitializedObject:IgnoreRecordsWithField="[Tt]ag|[Kk]ind"`.
44//
49//
45// TODO: With some clever heuristics, some pointers should be dereferenced
46// by default. For example, if the pointee is constructed within the
47// constructor call, it's reasonable to say that no external object
48// references it, and we wouldn't generate multiple report on the same
49// pointee.
50// - "IgnoreGuardedFields" (boolean). If set to true, the checker will analyze
51// _syntactically_ whether the found uninitialized object is used without a
52// preceding assert call. Defaults to false.
50//
53//
54// `-analyzer-config \
55// optin.cplusplus.UninitializedObject:IgnoreGuardedFields=true`.
56//
51// Most of the following methods as well as the checker itself is defined in
52// UninitializedObjectChecker.cpp.
53//
54// Some methods are implemented in UninitializedPointee.cpp, to reduce the
55// complexity of the main checker file.
56//
57//===----------------------------------------------------------------------===//
58

--- 5 unchanged lines hidden (view full) ---

64namespace clang {
65namespace ento {
66
67struct UninitObjCheckerOptions {
68 bool IsPedantic = false;
69 bool ShouldConvertNotesToWarnings = false;
70 bool CheckPointeeInitialization = false;
71 std::string IgnoredRecordsWithFieldPattern;
57// Most of the following methods as well as the checker itself is defined in
58// UninitializedObjectChecker.cpp.
59//
60// Some methods are implemented in UninitializedPointee.cpp, to reduce the
61// complexity of the main checker file.
62//
63//===----------------------------------------------------------------------===//
64

--- 5 unchanged lines hidden (view full) ---

70namespace clang {
71namespace ento {
72
73struct UninitObjCheckerOptions {
74 bool IsPedantic = false;
75 bool ShouldConvertNotesToWarnings = false;
76 bool CheckPointeeInitialization = false;
77 std::string IgnoredRecordsWithFieldPattern;
78 bool IgnoreGuardedFields = false;
72};
73
74/// A lightweight polymorphic wrapper around FieldRegion *. We'll use this
75/// interface to store addinitional information about fields. As described
76/// later, a list of these objects (i.e. "fieldchain") will be constructed and
77/// used for printing note messages should an uninitialized value be found.
78class FieldNode {
79protected:

--- 231 unchanged lines hidden (view full) ---

311 bool addFieldToUninits(FieldChainInfo LocalChain,
312 const MemRegion *PointeeR = nullptr);
313};
314
315/// Returns true if T is a primitive type. An object of a primitive type only
316/// needs to be analyzed as much as checking whether their value is undefined.
317inline bool isPrimitiveType(const QualType &T) {
318 return T->isBuiltinType() || T->isEnumeralType() ||
79};
80
81/// A lightweight polymorphic wrapper around FieldRegion *. We'll use this
82/// interface to store addinitional information about fields. As described
83/// later, a list of these objects (i.e. "fieldchain") will be constructed and
84/// used for printing note messages should an uninitialized value be found.
85class FieldNode {
86protected:

--- 231 unchanged lines hidden (view full) ---

318 bool addFieldToUninits(FieldChainInfo LocalChain,
319 const MemRegion *PointeeR = nullptr);
320};
321
322/// Returns true if T is a primitive type. An object of a primitive type only
323/// needs to be analyzed as much as checking whether their value is undefined.
324inline bool isPrimitiveType(const QualType &T) {
325 return T->isBuiltinType() || T->isEnumeralType() ||
319 T->isMemberPointerType() || T->isBlockPointerType() ||
320 T->isFunctionType();
326 T->isFunctionType() || T->isAtomicType() ||
327 T->isVectorType() || T->isScalarType();
321}
322
323inline bool isDereferencableType(const QualType &T) {
324 return T->isAnyPointerType() || T->isReferenceType();
325}
326
327// Template method definitions.
328

--- 21 unchanged lines hidden ---
328}
329
330inline bool isDereferencableType(const QualType &T) {
331 return T->isAnyPointerType() || T->isReferenceType();
332}
333
334// Template method definitions.
335

--- 21 unchanged lines hidden ---