ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
clang_c_convertert Class Reference

#include <clang_c_convert.h>

Inheritance diagram for clang_c_convertert:
[legend]

Public Member Functions

 clang_c_convertert (contextt &_context, std::unique_ptr< clang::ASTUnit > &_AST, irep_idt _mode)
virtual ~clang_c_convertert ()=default
bool convert ()

Static Public Member Functions

static void gen_typecast_to_union (const namespacet &ns, exprt &dest, const typet &type)
 Perform the typecast by creating a tmp variable on RHS.
static std::string get_decl_name (const clang::NamedDecl &nd)

Protected Member Functions

bool snapshot_vla_sizes (const clang::Decl &decl, codet &dest)
bool get_vla_size (const clang::Expr &size, exprt &new_expr)
void collect_address_taken_labels (const clang::Stmt &body)
bool convert_builtin_types ()
virtual bool convert_top_level_decl ()
virtual void annotate_exception_specification (const clang::FunctionDecl &, typet &)
 Since this class is inherited by clang-cpp-frontend, some get_* functions are made `virtual' to deal with clang CXX declarations */ virtual bool get_decl(const clang::Decl &decl, exprt &new_expr);.
virtual bool get_function_params (const clang::FunctionDecl &fd, code_typet::argumentst &params)
 Parse function parameters This function simply contains a loop to populate the code argument list and calls get_function_param to parse each individual parameter.
bool get_function_param (const clang::ParmVarDecl &pd, exprt &param)
 Parse each individual parameter of the function.
virtual void name_param_and_continue (const clang::ParmVarDecl &pd, std::string &id, std::string &name, exprt &param)
virtual bool get_struct_union_class (const clang::RecordDecl &recordd)
virtual bool get_struct_union_class_fields (const clang::RecordDecl &recordd, struct_union_typet &type)
virtual bool get_struct_union_class_methods_decls (const clang::RecordDecl &recordd, typet &type)
virtual bool get_type (const clang::QualType &type, typet &new_type)
virtual bool get_type (const clang::Type &the_type, typet &new_type)
void get_ref_to_struct_type (typet &type)
bool get_builtin_type (const clang::BuiltinType &bt, typet &new_type)
bool get_bitfield_type (const clang::FieldDecl &, const typet &orig_type, typet &new_type)
bool wrap_bitfield_type_if_needed (const clang::FieldDecl &fd, typet &t)
void size_flexible_array_member (const clang::ValueDecl &vd, typet &t)
virtual bool get_expr (const clang::Stmt &stmt, exprt &new_expr)
bool get_base_flattened_inits (const clang::InitListExpr &init, std::vector< exprt > &flat)
bool get_array_filler (const clang::InitListExpr &init, exprt &filler)
bool get_enum_value (const clang::EnumConstantDecl *e, exprt &new_expr)
virtual bool get_decl_ref (const clang::Decl &decl, exprt &new_expr)
bool get_binary_operator_expr (const clang::BinaryOperator &binop, exprt &new_expr)
void get_vector_comparison (const clang::BinaryOperator &binop, irep_idt relation, exprt lhs, exprt rhs, const typet &type, exprt &new_expr)
bool get_compound_assign_expr (const clang::CompoundAssignOperator &compop, exprt &new_expr)
virtual bool get_unary_operator_expr (const clang::UnaryOperator &uniop, exprt &new_expr)
bool get_atomic_expr (const clang::AtomicExpr &atm, exprt &new_expr)
virtual bool get_member_expr (const clang::MemberExpr &memb, exprt &new_expr)
bool get_cast_expr (const clang::CastExpr &cast, exprt &new_expr)
void get_default_symbol (symbolt &symbol, irep_idt module_name, typet type, irep_idt base_name, irep_idt unique_name, locationt location)
virtual void get_decl_name (const clang::NamedDecl &vd, std::string &name, std::string &id)
void get_start_location_from_stmt (const clang::Stmt &stmt, locationt &location)
bool report_unsupported_init_list (const clang::InitListExpr &init_stmt)
 Report an initializer list none of get_expr's arms models, with its type and source location. Always returns true (conversion failed).
void get_final_location_from_stmt (const clang::Stmt &stmt, locationt &location)
void get_location_from_decl (const clang::Decl &decl, locationt &location)
void set_location (clang::PresumedLoc &PLoc, std::string &function_name, locationt &location)
void get_presumed_location (const clang::SourceLocation &loc, clang::PresumedLoc &PLoc)
std::string get_filename_from_path (std::string path)
std::string get_modulename_from_path (std::string path)
void convert_expression_to_code (exprt &expr)
bool convert_character_literal (const clang::CharacterLiteral &char_literal, exprt &dest)
bool convert_string_literal (const clang::StringLiteral &string_literal, exprt &dest)
bool convert_integer_literal (const clang::IntegerLiteral &integer_literal, exprt &dest)
bool convert_float_literal (const clang::FloatingLiteral &floating_literal, exprt &dest)
const clang::Decl * get_DeclContext_from_Stmt (const clang::Stmt &stmt)
const clang::Decl * get_top_FunctionDecl_from_Stmt (const clang::Stmt &stmt)
bool process_aligned_attribute (const clang::AlignedAttr &aattr, typet &t) const
bool process_record_layout_attributes (const clang::RecordDecl &rd, typet &t) const
bool check_alignment_attributes (const clang::FieldDecl *field, struct_typet::componentt &comp)
bool is_field_global_storage (const clang::FieldDecl *field)
virtual bool perform_virtual_dispatch (const clang::MemberExpr &member)
virtual bool get_vft_binding_expr (const clang::MemberExpr &member, exprt &new_expr)
virtual bool is_fd_virtual_or_overriding (const clang::FunctionDecl &fd)
virtual bool is_aggregate_type (const clang::QualType &q_type)
bool get_mangled_id (const clang::NamedDecl &nd, std::string &id)
 The USR generator gives up on some C++20 declarations: a specialisation over a class-type template argument, its members and parameters, and the template parameter object that argument names.
bool add_template_param_object (const clang::TemplateParamObjectDecl &tpo, const std::string &name, const std::string &id)
bool get_APValue_expr (const clang::APValue &value, exprt &new_expr, const clang::QualType *type=nullptr)
bool is_member_decl_static (const clang::MemberExpr &member)
void rewrite_builtin_ref (const clang::Decl &d, std::string &name, std::string &id) const
 Rewrites references to builtin functions to their ESBMC counterparts.
bool is_unlowered_math_builtin (const std::string &name) const
 __builtin_copysign and the other __builtin_ spellings of a <math.h> function have no body; the plain name has an operational model.

Protected Attributes

clang::ASTContext * ASTContext
contextt & context
namespacet ns
std::unique_ptr< clang::ASTUnit > & AST
irep_idt mode
symbol_generator anon_symbol
locationt last_loc
unsigned last_loc_line = 0
unsigned last_loc_column = 0
std::string last_loc_filename
std::string last_loc_function
bool last_loc_valid = false
std::string tag_prefix = "tag-"
unsigned int current_scope_var_num
code_blockt * current_block
 During get_expr(), which also transforms blocks/scopes, this represents the latest opened blocks from the top-level.
std::unordered_map< const clang::Expr *, exprt > vla_size_snapshots
 A block-scope VLA's size, bound to a local just before its declarator (C11 6.7.6.2p5, 6.7.8p3).
clang::SourceManager * sm
const clang::FunctionDecl * current_functionDecl
std::vector< const clang::LabelDecl * > address_taken_labels
 Address-taken labels of the function being converted, in the order the addresses appear.

Constructor & Destructor Documentation

◆ clang_c_convertert()

clang_c_convertert::clang_c_convertert ( contextt & _context,
std::unique_ptr< clang::ASTUnit > & _AST,
irep_idt _mode )

◆ ~clang_c_convertert()

virtual clang_c_convertert::~clang_c_convertert ( )
virtualdefault

Member Function Documentation

◆ add_template_param_object()

bool clang_c_convertert::add_template_param_object ( const clang::TemplateParamObjectDecl & tpo,
const std::string & name,
const std::string & id )
protected

◆ annotate_exception_specification()

virtual void clang_c_convertert::annotate_exception_specification ( const clang::FunctionDecl & ,
typet &  )
inlineprotectedvirtual

Since this class is inherited by clang-cpp-frontend, some get_* functions are made `virtual' to deal with clang CXX declarations */ virtual bool get_decl(const clang::Decl &decl, exprt &new_expr);.

virtual bool get_var(const clang::VarDecl &vd, exprt &new_expr); virtual const clang::Expr &elided_copy_source(const clang::Expr &init); bool has_dynamic_local_init(const clang::VarDecl &vd) const; void add_init_guard(const symbolt &var); bool get_static_var_init( const clang::VarDecl &vd, symbolt &symbol, const typet &t, const locationt &location_begin, exprt &new_expr);

std::string header_internal_suffix(const clang::NamedDecl &nd); / Internal-linkage functions and variables sharing a USR, in the order they / were first named; see header_internal_suffix. std::unordered_map<std::string, std::vector<const clang::Decl *>> internal_copies;

virtual bool get_function(const clang::FunctionDecl &fd, exprt &new_expr);

bool get_function_signature(const clang::FunctionDecl &fd, code_typet &type);

virtual bool get_function_body( const clang::FunctionDecl &fd, exprt &new_expr, const code_typet &ftype);

/** Annotate a function's type with its C++ exception specification. No-op in C (which has no exception specifications); overridden in the C++ frontend to record noexcept / dynamic-throw specifications as function-boundary metadata on the function type.

Reimplemented in clang_cpp_convertert.

◆ check_alignment_attributes()

bool clang_c_convertert::check_alignment_attributes ( const clang::FieldDecl * field,
struct_typet::componentt & comp )
protected

◆ collect_address_taken_labels()

void clang_c_convertert::collect_address_taken_labels ( const clang::Stmt & body)
protected

◆ convert()

bool clang_c_convertert::convert ( )

◆ convert_builtin_types()

bool clang_c_convertert::convert_builtin_types ( )
protected

◆ convert_character_literal()

bool clang_c_convertert::convert_character_literal ( const clang::CharacterLiteral & char_literal,
exprt & dest )
protected

◆ convert_expression_to_code()

void clang_c_convertert::convert_expression_to_code ( exprt & expr)
protected

◆ convert_float_literal()

bool clang_c_convertert::convert_float_literal ( const clang::FloatingLiteral & floating_literal,
exprt & dest )
protected

◆ convert_integer_literal()

bool clang_c_convertert::convert_integer_literal ( const clang::IntegerLiteral & integer_literal,
exprt & dest )
protected

◆ convert_string_literal()

bool clang_c_convertert::convert_string_literal ( const clang::StringLiteral & string_literal,
exprt & dest )
protected

◆ convert_top_level_decl()

bool clang_c_convertert::convert_top_level_decl ( )
protectedvirtual

◆ gen_typecast_to_union()

void clang_c_convertert::gen_typecast_to_union ( const namespacet & ns,
exprt & dest,
const typet & type )
static

Perform the typecast by creating a tmp variable on RHS.

The idea is to look for all components of the union and match the type. If not found, throws an error

Parameters
nsNamespace for looking up the union components
destRHS dest
typeUnion type

◆ get_APValue_expr()

bool clang_c_convertert::get_APValue_expr ( const clang::APValue & value,
exprt & new_expr,
const clang::QualType * type = nullptr )
protected

◆ get_array_filler()

bool clang_c_convertert::get_array_filler ( const clang::InitListExpr & init,
exprt & filler )
protected

◆ get_atomic_expr()

bool clang_c_convertert::get_atomic_expr ( const clang::AtomicExpr & atm,
exprt & new_expr )
protected

◆ get_base_flattened_inits()

bool clang_c_convertert::get_base_flattened_inits ( const clang::InitListExpr & init,
std::vector< exprt > & flat )
protected

◆ get_binary_operator_expr()

bool clang_c_convertert::get_binary_operator_expr ( const clang::BinaryOperator & binop,
exprt & new_expr )
protected

◆ get_bitfield_type()

bool clang_c_convertert::get_bitfield_type ( const clang::FieldDecl & fd,
const typet & orig_type,
typet & new_type )
protected

◆ get_builtin_type()

bool clang_c_convertert::get_builtin_type ( const clang::BuiltinType & bt,
typet & new_type )
protected

◆ get_cast_expr()

bool clang_c_convertert::get_cast_expr ( const clang::CastExpr & cast,
exprt & new_expr )
protected

◆ get_compound_assign_expr()

bool clang_c_convertert::get_compound_assign_expr ( const clang::CompoundAssignOperator & compop,
exprt & new_expr )
protected

◆ get_decl_name() [1/2]

std::string clang_c_convertert::get_decl_name ( const clang::NamedDecl & nd)
static

◆ get_decl_name() [2/2]

void clang_c_convertert::get_decl_name ( const clang::NamedDecl & vd,
std::string & name,
std::string & id )
protectedvirtual

Reimplemented in clang_cpp_convertert.

◆ get_decl_ref()

bool clang_c_convertert::get_decl_ref ( const clang::Decl & decl,
exprt & new_expr )
protectedvirtual

Reimplemented in clang_cpp_convertert.

◆ get_DeclContext_from_Stmt()

const clang::Decl * clang_c_convertert::get_DeclContext_from_Stmt ( const clang::Stmt & stmt)
protected

◆ get_default_symbol()

void clang_c_convertert::get_default_symbol ( symbolt & symbol,
irep_idt module_name,
typet type,
irep_idt base_name,
irep_idt unique_name,
locationt location )
protected

◆ get_enum_value()

bool clang_c_convertert::get_enum_value ( const clang::EnumConstantDecl * e,
exprt & new_expr )
protected

◆ get_expr()

bool clang_c_convertert::get_expr ( const clang::Stmt & stmt,
exprt & new_expr )
protectedvirtual

Reimplemented in clang_cpp_convertert.

◆ get_filename_from_path()

std::string clang_c_convertert::get_filename_from_path ( std::string path)
protected

◆ get_final_location_from_stmt()

void clang_c_convertert::get_final_location_from_stmt ( const clang::Stmt & stmt,
locationt & location )
protected

◆ get_function_param()

bool clang_c_convertert::get_function_param ( const clang::ParmVarDecl & pd,
exprt & param )
protected

Parse each individual parameter of the function.

◆ get_function_params()

bool clang_c_convertert::get_function_params ( const clang::FunctionDecl & fd,
code_typet::argumentst & params )
protectedvirtual

Parse function parameters This function simply contains a loop to populate the code argument list and calls get_function_param to parse each individual parameter.

Reimplemented in clang_cpp_convertert.

◆ get_location_from_decl()

void clang_c_convertert::get_location_from_decl ( const clang::Decl & decl,
locationt & location )
protected

◆ get_mangled_id()

bool clang_c_convertert::get_mangled_id ( const clang::NamedDecl & nd,
std::string & id )
protected

The USR generator gives up on some C++20 declarations: a specialisation over a class-type template argument, its members and parameters, and the template parameter object that argument names.

Their mangled names still identify them; a parameter is named after its function.

◆ get_member_expr()

bool clang_c_convertert::get_member_expr ( const clang::MemberExpr & memb,
exprt & new_expr )
protectedvirtual

Reimplemented in clang_cpp_convertert.

◆ get_modulename_from_path()

std::string clang_c_convertert::get_modulename_from_path ( std::string path)
protected

◆ get_presumed_location()

void clang_c_convertert::get_presumed_location ( const clang::SourceLocation & loc,
clang::PresumedLoc & PLoc )
protected

◆ get_ref_to_struct_type()

void clang_c_convertert::get_ref_to_struct_type ( typet & type)
protected

◆ get_start_location_from_stmt()

void clang_c_convertert::get_start_location_from_stmt ( const clang::Stmt & stmt,
locationt & location )
protected

◆ get_struct_union_class()

bool clang_c_convertert::get_struct_union_class ( const clang::RecordDecl & recordd)
protectedvirtual

Reimplemented in clang_cpp_convertert.

◆ get_struct_union_class_fields()

bool clang_c_convertert::get_struct_union_class_fields ( const clang::RecordDecl & recordd,
struct_union_typet & type )
protectedvirtual

Reimplemented in clang_cpp_convertert.

◆ get_struct_union_class_methods_decls()

bool clang_c_convertert::get_struct_union_class_methods_decls ( const clang::RecordDecl & recordd,
typet & type )
protectedvirtual

Reimplemented in clang_cpp_convertert.

◆ get_top_FunctionDecl_from_Stmt()

const clang::Decl * clang_c_convertert::get_top_FunctionDecl_from_Stmt ( const clang::Stmt & stmt)
protected

◆ get_type() [1/2]

bool clang_c_convertert::get_type ( const clang::QualType & type,
typet & new_type )
protectedvirtual

Reimplemented in clang_cpp_convertert.

◆ get_type() [2/2]

bool clang_c_convertert::get_type ( const clang::Type & the_type,
typet & new_type )
protectedvirtual

Reimplemented in clang_cpp_convertert.

◆ get_unary_operator_expr()

bool clang_c_convertert::get_unary_operator_expr ( const clang::UnaryOperator & uniop,
exprt & new_expr )
protectedvirtual

Reimplemented in clang_cpp_convertert.

◆ get_vector_comparison()

void clang_c_convertert::get_vector_comparison ( const clang::BinaryOperator & binop,
irep_idt relation,
exprt lhs,
exprt rhs,
const typet & type,
exprt & new_expr )
protected

◆ get_vft_binding_expr()

bool clang_c_convertert::get_vft_binding_expr ( const clang::MemberExpr & member,
exprt & new_expr )
protectedvirtual

Reimplemented in clang_cpp_convertert.

◆ get_vla_size()

bool clang_c_convertert::get_vla_size ( const clang::Expr & size,
exprt & new_expr )
protected

◆ is_aggregate_type()

bool clang_c_convertert::is_aggregate_type ( const clang::QualType & q_type)
protectedvirtual

Reimplemented in clang_cpp_convertert.

◆ is_fd_virtual_or_overriding()

bool clang_c_convertert::is_fd_virtual_or_overriding ( const clang::FunctionDecl & fd)
protectedvirtual

Reimplemented in clang_cpp_convertert.

◆ is_field_global_storage()

bool clang_c_convertert::is_field_global_storage ( const clang::FieldDecl * field)
protected

◆ is_member_decl_static()

bool clang_c_convertert::is_member_decl_static ( const clang::MemberExpr & member)
protected

◆ is_unlowered_math_builtin()

bool clang_c_convertert::is_unlowered_math_builtin ( const std::string & name) const
protected

__builtin_copysign and the other __builtin_ spellings of a <math.h> function have no body; the plain name has an operational model.

Those that clang_c_adjust lowers by their own spelling keep it.

◆ name_param_and_continue()

void clang_c_convertert::name_param_and_continue ( const clang::ParmVarDecl & pd,
std::string & id,
std::string & name,
exprt & param )
protectedvirtual

Reimplemented in clang_cpp_convertert.

◆ perform_virtual_dispatch()

bool clang_c_convertert::perform_virtual_dispatch ( const clang::MemberExpr & member)
protectedvirtual

Reimplemented in clang_cpp_convertert.

◆ process_aligned_attribute()

bool clang_c_convertert::process_aligned_attribute ( const clang::AlignedAttr & aattr,
typet & t ) const
protected

◆ process_record_layout_attributes()

bool clang_c_convertert::process_record_layout_attributes ( const clang::RecordDecl & rd,
typet & t ) const
protected

◆ report_unsupported_init_list()

bool clang_c_convertert::report_unsupported_init_list ( const clang::InitListExpr & init_stmt)
protected

Report an initializer list none of get_expr's arms models, with its type and source location. Always returns true (conversion failed).

Report an initializer list none of get_expr's arms models.

Reported and not asserted: an assertion aborts the process, leaving the user without a diagnostic, a source location or a verdict (#7643).

◆ rewrite_builtin_ref()

void clang_c_convertert::rewrite_builtin_ref ( const clang::Decl & d,
std::string & name,
std::string & id ) const
protected

Rewrites references to builtin functions to their ESBMC counterparts.

Clang provides builtins for e.g. malloc, memcpy, etc. Instead of re-implementing these functions in ESBMC, we rewrite references to e.g. __builtin_memcpy to just memcpy.

Parameters
ddeclaration to rewrite (if it refers to a builtin function)
namename of the declaration
idid of the declaration

◆ set_location()

void clang_c_convertert::set_location ( clang::PresumedLoc & PLoc,
std::string & function_name,
locationt & location )
protected

◆ size_flexible_array_member()

void clang_c_convertert::size_flexible_array_member ( const clang::ValueDecl & vd,
typet & t )
protected

◆ snapshot_vla_sizes()

bool clang_c_convertert::snapshot_vla_sizes ( const clang::Decl & decl,
codet & dest )
protected

◆ wrap_bitfield_type_if_needed()

bool clang_c_convertert::wrap_bitfield_type_if_needed ( const clang::FieldDecl & fd,
typet & t )
protected

Member Data Documentation

◆ address_taken_labels

std::vector<const clang::LabelDecl *> clang_c_convertert::address_taken_labels
protected

Address-taken labels of the function being converted, in the order the addresses appear.

A label has no storage, so &&L lowers to its 1-based position cast to a pointer and goto *p to an equality chain over those positions. Collected up front because a label's address may be taken after the indirect goto that jumps to it. A vector, not a map keyed on the decl: pointer order varies per run, and the chain it emits has to be reproducible (GCC computed goto, issue #4083).

◆ anon_symbol

symbol_generator clang_c_convertert::anon_symbol
protected

◆ AST

std::unique_ptr<clang::ASTUnit>& clang_c_convertert::AST
protected

◆ ASTContext

clang::ASTContext* clang_c_convertert::ASTContext
protected

◆ context

contextt& clang_c_convertert::context
protected

◆ current_block

code_blockt* clang_c_convertert::current_block
protected

During get_expr(), which also transforms blocks/scopes, this represents the latest opened blocks from the top-level.

A nullptr 'current_block' thus means file scope.

◆ current_functionDecl

const clang::FunctionDecl* clang_c_convertert::current_functionDecl
protected

◆ current_scope_var_num

unsigned int clang_c_convertert::current_scope_var_num
protected

◆ last_loc

locationt clang_c_convertert::last_loc
protected

◆ last_loc_column

unsigned clang_c_convertert::last_loc_column = 0
protected

◆ last_loc_filename

std::string clang_c_convertert::last_loc_filename
protected

◆ last_loc_function

std::string clang_c_convertert::last_loc_function
protected

◆ last_loc_line

unsigned clang_c_convertert::last_loc_line = 0
protected

◆ last_loc_valid

bool clang_c_convertert::last_loc_valid = false
protected

◆ mode

irep_idt clang_c_convertert::mode
protected

◆ ns

namespacet clang_c_convertert::ns
protected

◆ sm

clang::SourceManager* clang_c_convertert::sm
protected

◆ tag_prefix

std::string clang_c_convertert::tag_prefix = "tag-"
protected

◆ vla_size_snapshots

std::unordered_map<const clang::Expr *, exprt> clang_c_convertert::vla_size_snapshots
protected

A block-scope VLA's size, bound to a local just before its declarator (C11 6.7.6.2p5, 6.7.8p3).

Keyed by clang's size expression, which every expression typed by that declarator shares.


The documentation for this class was generated from the following files: