Externals-AbstractReferenceTypes

User-provided list of smart pointer and iterator types for which information is tracked by specialized analyses

Specifies types that are used as smart pointer or iterator abstractions (both referred to as abstract references) in the analyzed code.

Analyses that track values of smart pointers and iterators - such as those detecting null pointer dereferences - can leverage additional information about specific instances of these types. Furthermore, the behavior of methods that affect the values of abstract references (e.g., operator== for std::shared_ptr) can be specified using entries in the post_conditions option of the corresponding external rule to get more precise results. For details on how to write these specifications, refer to the description of the post_conditions option.

Example

If, e.g., a custom smart pointer type mynamespace::MySmartPointer<T> is used in the project (possibly without the actual implementation available in the compiled code), the first step is to add mynamespace::MySmartPointer to option smart_pointer_types (the template parameter has to be left out to match all possible template instances of the type). Then the effect of operations provided by MySmartPointer can be given by creating new instances of the Externals-FunctionSummary rule and adapting the config option post_conditions. Some examples:
  • If MySmartPointer provides an operator mynamespace::MySmartPointer<T>::makeSmartPointer, unconditionally returning a valid (dereferenceable) abstract reference, an external rule with option functions set to mynamespace::MySmartPointer::makeSmartPointer can be created; the entry @valid_ref(@ret) can then be added to the option post_conditions.
  • If MySmartPointer provides an operator mynamespace::MySmartPointer<T>::bool, returning true if the reference can safely be dereferenced, an external rule with option functions set to mynamespace::MySmartPointer::bool can be created; the entry @is_true(@ret) <-> @valid_ref(*@param0) can then be added to the option post_conditions.
See, for example, the rules whose names start with Externals-StdUniquePtr for more examples of specifications.

Possible Messages

This rule has no predefined messages.

Options

The following places define options that affect this rule: Analysis-GlobalOptions

iterator_types

iterator_types

Type: set[bauhaus.analysis.config.GlobPattern]

Default: {'std::*::const_iterator', 'std::*::const_reverse_iterator', 'std::*::iterator', 'std::*::reverse_iterator', 'std::_List_const_iterator', 'std::_List_iterator', 'std::_Node_iterator_base', 'std::_Rb_tree_const_iterator', 'std::_Vector_const_iterator', 'std::_Vector_iterator', 'std::__1::__wrap_iter', 'std::__wrap_iter'}

A set of globbing patterns for qualified names of iterator types. Analyses specialized to infer information about iterator behaviour can track facts for instances of the specified types. Additionally, the behaviour of methods influencing the value of iterator instances (e.g., end() for containers) has to be specified by providing conditions in the post_conditions option of the corresponding external rule for the method to get precise results.
 

smart_pointer_types

smart_pointer_types : set[bauhaus.analysis.config.GlobPattern] = {'QSharedPointer', 'std::shared_ptr', 'std::unique_ptr'}

A set of globbing patterns for qualified names of smart pointer types. Analyses specialized to infer information about smart pointer behaviour can track facts for instances of the specified types. Additionally, the behaviour of methods influencing the value of smart pointer instances (e.g., operator==() for std::shared_ptr) has to be specified by providing conditions in the postcondition option of the corresponding external rule for the method to get precise results.