Miscellaneous-NoTypeConversionToBool

Do not use type conversions to bool, use value comparison

Required inputs: IR

Instead of using implicit conversions to bool, make the comparison explicit:
void (int i, float* pf)
{
    if (i != 0)
    {
    }
    if (pf != NULL)
    {
    }
}

Possible Messages

Key

Text

Severity

Disabled

cast_changes_type_category

Conversion to bool - use value comparison instead.

None

False

Options

category_changes

category_changes

Type: list[typing.Tuple[typing.Set[bauhaus.ir.common.types.type_systems.TypeCategory], typing.Set[bauhaus.ir.common.types.type_systems.TypeCategory]]]

Default: [({'bool_types', 'char_types', 'enum_types', 'float_types', 'function_pointer_types', 'incomplete_pointer_types', 'null_pointer_types', 'object_pointer_types', 'other_types', 'signed_types', 'unsigned_types', 'void_pointer_types', 'void_types'}, {'bool_types'})]

List of (from, to) type category pairs to check for. Both from and to are lists of categories.
 

check_explicit_casts

check_explicit_casts : bool = True

Whether explicit casts should be checked and reported.
 

check_implicit_casts

check_implicit_casts : bool = True

Whether implicit casts should be checked and reported.
 

look_through_casts

look_through_casts : bool = False

If true, operand after stripping casts is used.
 

only_complex_expressions

only_complex_expressions : bool = False

Whether all operands or only those deemed complex should be inspected.
 

show_operand_in_entity

show_operand_in_entity : bool = False

Whether entity should be "from->to" or "(from->to)operand".
 

type_system

type_system : bauhaus.ir.common.types.type_systems.TypeSystem = <bauhaus.ir.common.types.type_systems.CompilerTypeSystem object at 0x7f6f1c5fd510>

Which type system to use: compiler types, underlying types, essential types.
 

Option Types

These types are used by options listed above:

TypeCategory

Base class for the different type categories.
 

signed_types

unsigned_types

float_types

char_types

plain char.

bool_types

bool, _Bool and special expressions.

enum_types

void_types

void_pointer_types

incomplete_pointer_types

function_pointer_types

object_pointer_types

null_pointer_types

other_types

Those not covered by other categories.