ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
clang_cpp_convert.h
Go to the documentation of this file.
1#ifndef CLANG_CPP_FRONTEND_CLANG_CPP_CONVERT_H_
2#define CLANG_CPP_FRONTEND_CLANG_CPP_CONVERT_H_
3
4#define __STDC_LIMIT_MACROS
5#define __STDC_FORMAT_MACROS
6
8#include <optional>
9
11{
12public:
14 contextt &_context,
15 std::unique_ptr<clang::ASTUnit> &_AST,
16 irep_idt _mode);
17 virtual ~clang_cpp_convertert() = default;
18
19protected:
20 // this_map contains key-value pairs in the form of <method address,
21 // <identifier, type>>
22 typedef std::unordered_map<std::size_t, std::pair<std::string, typet>>
25
26 bool get_decl(const clang::Decl &decl, exprt &new_expr) override;
27
28 void get_decl_name(
29 const clang::NamedDecl &nd,
30 std::string &name,
31 std::string &id) override;
32
38 bool get_decl_ref(const clang::Decl &decl, exprt &new_expr) override;
39
40 bool get_type(const clang::QualType &type, typet &new_type) override;
41
42 bool get_type(const clang::Type &the_type, typet &new_type) override;
43
44 bool get_method(const clang::CXXMethodDecl &md, exprt &new_expr);
45
47 const clang::CXXMethodDecl &md,
48 const symbolt *&symbol);
49
51 const clang::FunctionDecl &fd,
52 typet &type) override;
53
58 const clang::CXXConstructExpr &constructor_call,
59 exprt &new_expr);
60
61#if CLANG_VERSION_MAJOR <= 15
62# define CAPTURE_VARIABLE_TYPE clang::VarDecl
63#else
64# define CAPTURE_VARIABLE_TYPE clang::ValueDecl
65#endif
66 /*
67 * Map captured variables and this to the non-static members storing their
68 * values or references.
69 * Arguments:
70 * is_lambda_operator: the lambda operator is being converted
71 * captures: populated with the mapping from captured variables to the
72 * corresponding fields.
73 * thisCapture: the field declaration for the This capture.
74 */
75 typedef llvm::DenseMap<const CAPTURE_VARIABLE_TYPE *, clang::FieldDecl *>
77 typedef std::
78 unordered_map<std::size_t, std::pair<field_mapt, clang::FieldDecl *>>
81
82 bool is_lambda() const
83 {
85 return false;
86
87 if (
88 const auto *methodDecl =
89 llvm::dyn_cast<clang::CXXMethodDecl>(current_functionDecl))
90 {
91 const auto *parent = methodDecl->getParent();
92 if (parent && parent->isLambda())
93 return true;
94 }
95 return false;
96 }
97
99 const clang::FunctionDecl &fd,
100 exprt &new_expr,
101 const code_typet &ftype) override;
102 bool get_new_initializer(const clang::CXXNewExpr &ne, exprt &new_expr);
103
105 const clang::Expr &init,
106 const typet &member_type,
107 exprt &rhs);
108
112 const clang::CXXMethodDecl &invoker,
113 exprt &new_expr);
114
120 const clang::FunctionDecl &fd,
121 code_typet::argumentst &params) override;
122
124 const clang::ParmVarDecl &pd,
125 std::string &id,
126 std::string &name,
127 exprt &param) override;
128
129 std::string constref_suffix = "ref";
130
139 const clang::CXXMethodDecl &fd,
140 code_typet::argumentst &params);
141
142 bool get_struct_union_class(const clang::RecordDecl &rd) override;
143
144 bool get_var(const clang::VarDecl &vd, exprt &new_expr) override;
145 const clang::Expr &elided_copy_source(const clang::Expr &init) override;
146
148 const clang::RecordDecl &rd,
149 struct_union_typet &type) override;
150
152 const clang::RecordDecl &rd,
153 typet &type) override;
154
155 /*
156 * Deal with ClassTemplateDecl or FunctionTemplateDecl or
157 * a class or function template declaration respectively.
158 * For C++14 and above, this function might be extended to deal
159 * with VarTemplateDecl for variable template.
160 */
161 template <typename TemplateDecl>
163 const TemplateDecl &D,
164 bool DumpExplicitInst,
165 exprt &new_expr);
166
167 template <typename SpecializationDecl>
169 const SpecializationDecl *D,
170 bool DumpExplicitInst,
171 exprt &new_expr);
172
173 bool get_expr(const clang::Stmt &stmt, exprt &new_expr) override;
174
175 void
176 build_member_from_component(const clang::FunctionDecl &fd, exprt &component);
177
178 /*
179 * Append the implicit chain of member-subobject and base-subobject
180 * destructor calls to the body of a CXXDestructor. C++ [class.dtor]/9
181 * requires that, after the user-written body runs, each non-static data
182 * member is destroyed in reverse declaration order, then each direct
183 * non-virtual base in reverse declaration order. Clang does not emit
184 * these calls in the AST body (they are codegen-only in a real compiler),
185 * so the C++ frontend has to synthesise them here.
186 */
187 bool
188 build_destructor_chain(const clang::CXXDestructorDecl &dd, code_blockt &body);
189
190public:
191 /*
192 * The destructor calls of one subobject of a class, and the subobject's
193 * position in construction order: the direct non-virtual bases, then the
194 * members, numbered from 0.
195 */
197 {
198 std::size_t position;
200 };
201
202protected:
203 const this_mapt::mapped_type &
204 method_this(const clang::CXXMethodDecl &md) const;
205 const symbolt *nontrivial_destructor(const clang::CXXRecordDecl *rec);
207 const clang::FieldDecl &field,
208 const exprt &deref,
209 code_blockt &calls);
211 const symbolt &sym,
212 const clang::CXXRecordDecl &base,
213 const clang::CXXMethodDecl &md);
214
215 /*
216 * The members and direct non-virtual bases of md's class whose destructor
217 * is non-trivial, in destruction order, with `this` taken from md.
218 */
220 const clang::CXXMethodDecl &md,
221 std::vector<subobject_destructort> &out);
222
223 /*
224 * Whether this translation unit's own code throws or catches. If not, no
225 * constructor gets the handler that unwinds its subobjects, so the program
226 * stays out of exception lowering and pays nothing for it.
227 */
228 std::optional<bool> uses_exceptions;
230
231 /*
232 * try { tried } catch (...) { handler; throw; }
233 */
234 codet rethrowing_catch(const code_blockt &tried, code_blockt handler);
235
236 /*
237 * Run cd's class destructor when the body of the delegating constructor cd,
238 * which starts at body_start in body, exits by an exception.
239 */
241 const clang::CXXConstructorDecl &cd,
242 std::size_t body_start,
243 code_blockt &body);
244
245 /*
246 * Destroy the subobjects a constructor has built when an exception leaves
247 * it ([except.ctor]/3), or a delegating constructor's object when its body
248 * throws ([except.ctor]/4). starts[i] is where the code of cd's i-th
249 * initializer begins in body, and starts.back() where its own body does.
250 */
252 const clang::CXXConstructorDecl &cd,
253 const std::vector<std::size_t> &starts,
254 code_blockt &body);
255
256 /*
257 * Put a constructor's converted initializers at the start of its body.
258 */
260 const clang::CXXConstructorDecl &cd,
261 exprt::operandst &initializers,
262 std::vector<std::size_t> starts,
263 const symbolt *array_init_sym,
264 code_blockt &body);
265
266 /*
267 * The `this` a base destructor is called with: the address of the derived
268 * object's base subobject, not the derived object itself.
269 */
271 const clang::CXXRecordDecl &base,
272 const exprt &deref,
273 const irep_idt &this_id,
274 const typet &this_ptr_type);
275
276 /*
277 * Add additional annotations for class/struct/union fields
278 * Arguments:
279 * field: clang AST node representing the field we are dealing with
280 * type: ESBMC's typet representing the type of the class we are currently
281 * dealing with comp: the `component` representing the field
282 */
284 const clang::FieldDecl &field,
285 const struct_union_typet &type,
287
288 /*
289 * Add access in class symbol type's component:
290 * 0: component:
291 * * access: public
292 */
294 const clang::FieldDecl &field,
296
297 /*
298 * Get access from any clang Decl (field, method .etc)
299 */
300 bool get_access_from_decl(const clang::Decl &decl, std::string &access);
301
302 /*
303 * Get the symbol from the context for a C++ function
304 *
305 * Returns:
306 * fd_symb: pointer of the function symbol
307 * Arguments:
308 * fd: Clang AST for this function declaration
309 */
310 symbolt *get_fd_symbol(const clang::FunctionDecl &fd);
311
312 /*
313 * Add additional annotations for class/struct/union methods:
314 * 0: component
315 * * type: code
316 * * #member_name: tag-MyClasss
317 * * return_type: constructor
318 * * from_base: 1
319 * * access: public
320 * * name: MyMethodName
321 * * #location:
322 * Arguments:
323 * cxxmdd: clang AST node representing the method we are dealing with
324 * new_expr: the `component` in class/struct/union symbol type
325 * fd: clang AST node representing the function declaration we are dealing
326 * with
327 */
328 bool
329 annotate_class_method(const clang::CXXMethodDecl &cxxmdd, exprt &new_expr);
330 /*
331 * Flag copy constructor.
332 *
333 * Arguments:
334 * cxxmdd: clang AST node representing the constructor we are dealing with
335 * rtn_type: the corresponding return type node
336 */
338 const clang::CXXMethodDecl &cxxmdd,
339 typet &ctor_return_type);
340 /*
341 * Flag return type in ctor or dtor by setting it to the marker type
342 * `constructor` (or `destructor`), e.g. a constructor gets:
343 * * return_type: constructor
344 *
345 * Arguments:
346 * cxxmdd: clang AST node representing the ctor/dtor we are dealing with
347 * rtn_type: the corresponding return type node
348 */
350 const clang::CXXMethodDecl &cxxmdd,
351 typet &rtn_type);
352
353 /*
354 * A reference to the ctor or dtor md, with its `this` parameter, whether or
355 * not md has been converted yet.
356 */
357 bool get_ctor_dtor_ref(const clang::CXXMethodDecl &md, exprt &new_expr);
358 bool is_copy_or_move_ctor(const clang::DeclContext &dcxt);
359 bool is_defaulted_ctor(const clang::CXXMethodDecl &md);
360
361 /*
362 * When getting a function call to ctor, we might call the base ctor from a
363 * derived class ctor Need to wrap derived class `this` in a typecast expr and
364 * convert to the base `this`, e.g.: Base( (Base*) this)
365 *
366 * Arguments:
367 * callee_decl: base ctor symbol
368 * call: function call statement to the base ctor
369 * initializer: this is an intermediate data structure containing the
370 * information of derived `this`
371 */
373 const exprt &callee_decl,
375 exprt &initializer);
376
377 /*
378 * Constructors of a class with virtual bases carry a hidden trailing
379 * `__is_complete` boolean parameter that models the Itanium C1/C2 split:
380 * only the most-derived (complete-object) constructor initialises the
381 * shared virtual base subobjects, while base-object constructor calls skip
382 * them. This appends that parameter (and its symbol) for such constructors;
383 * classes without virtual bases are left with their original signature.
384 * See esbmc/esbmc#938.
385 */
387 const clang::CXXConstructorDecl &cxxcd,
388 code_typet::argumentt &param);
389
390 /*
391 * This is an ancillary function deciding whether we need
392 * need to build an new_object when dealing with constructor_call
393 */
394 bool need_new_object(
395 const clang::Stmt *parentStmt,
396 const clang::CXXConstructExpr &call);
397
398 /*
399 * Methods to pull bases in
400 */
401 // Bases are collected in declaration order, ancestors first, not
402 // alphabetical. That order defines the flattened component layout, which is
403 // the only offset oracle the base-offset paths (dtor/cast/thunk) may use:
404 // clang's getBaseClassOffset disagrees with it once a virtual base makes the
405 // primary-base rule apply (#7025). See #1866, #3894 and
406 // docs/design/cpp-multiple-inheritance-subobjects.md.
407 using base_map =
408 std::vector<std::pair<std::string, const clang::CXXRecordDecl *>>;
409 /*
410 * Recursively get the bases for this derived class.
411 *
412 * Params:
413 * - cxxrd: clang AST representing the class/struct we are currently dealing
414 * with
415 * - map: ordered list of (class_id, base clang AST) in declaration order,
416 * deduped
417 */
418 bool get_base_map(const clang::CXXRecordDecl &cxxrd, base_map &map);
419 /*
420 * Check whether we've already got this component in a class type
421 * Avoid copying duplicate component from a base class type to the derived
422 * class type.
423 *
424 * Params:
425 * - component: the component to be copied from a base class to the derived
426 * class type
427 * - type: ESBMC IR representing the derived class type
428 */
430 const struct_typet::componentt &component,
431 const struct_union_typet &type);
432 /*
433 * Check whether we've already got this method in a class type
434 * Avoid copying duplicate method from a base class type to the derived class
435 * type.
436 *
437 * Params:
438 * - method: the method to be copied from a base class to the derived class
439 * type
440 * - type: ESBMC IR representing the derived class type
441 */
443 const struct_typet::componentt &method,
444 const struct_union_typet &type);
445 /*
446 * Copy components and methods from base class(es) to the derived class type
447 * For virtual base class, we only copy it once.
448 *
449 * Params:
450 * - map: this map contains all base class(es) of this class
451 * std::map<class_id, pointer to clang AST of base class>
452 * - type: ESBMC IR representing the class' type
453 */
454 /* When the class has any virtual base, nesting is disabled and the legacy
455 * flattened layout is used for all of its bases: a shared virtual base must
456 * appear once in the most-derived object, which nested per-path subobjects
457 * cannot express yet (P5). See #1866, #3894. */
459 base_map &map,
460 struct_union_typet &type,
461 bool has_virtual_bases,
462 const clang::CXXRecordDecl &cxxrd);
463
464 /*
465 * Methods for virtual tables and virtual pointers
466 * TODO: add link to wiki page
467 */
468 std::string vtable_type_prefix = "virtual_table::";
469 std::string vtable_ptr_suffix = "@vtable_pointer";
470 /* Leading component of every vtable type: a pointer to the printed name of
471 * the most-derived class the vtable belongs to. Reading it through an
472 * object's vptr is how `typeid` recovers the dynamic type (#6310). */
473 static irep_idt rtti_name_component_id(const irep_idt &vtable_type_id);
475 rtti_name_component(const irep_idt &vtable_type_id);
476 /* The single spelling of a type used as typeid identity; see #6310. */
477 std::string rtti_type_name(const clang::QualType &qtype);
478 std::string rtti_type_name(const clang::CXXRecordDecl &rd);
480 const exprt &value,
481 const std::string &type_name,
482 const clang::Stmt &stmt,
483 bool dynamic);
484 // if a class/struct has vptr component, it needs to be initialized in ctor
485 bool has_vptr_component = false;
486 std::string thunk_prefix = "thunk::";
487 std::string vcall_prefix = "virtual_call::";
488 using function_switch = std::map<irep_idt, exprt>;
489 using switch_table = std::map<irep_idt, function_switch>;
490 using overriden_map = std::map<std::string, const clang::CXXMethodDecl &>;
491 /*
492 * traverse methods to:
493 * 1. convert virtual methods and add them to class' type
494 * 2. If there is no existing vtable type symbol,
495 * add virtual table type symbol in the context
496 * and the virtual pointer.
497 * Then add a new entry in the vtable.
498 * 3. If vtable type symbol exists, do not add it or the vptr,
499 * just add a new entry in the existing vtable.
500 * 4. If method X overrides a base method,
501 * add a thunk function that does late casting of the `this` parameter
502 * and redirects the call to the overriding function (i.e. method X itself)
503 *
504 * Last but not least, set up the vtable varaible symbols (i.e. these are the
505 * struct variables instantiated from the vtable type symbols)
506 */
508 const clang::CXXRecordDecl &cxxrd,
509 struct_typet &type);
510 /*
511 * additional annotations for virtual or overriding methods
512 *
513 * Params:
514 * - md: the virtual method AST we are currently dealing with
515 * - comp: the `component` as in `components` list in class type IR
516 * this `component` represents the type of the virtual method
517 */
519 const clang::CXXMethodDecl &md,
521 /*
522 * Check the existence of virtual table type symbol.
523 * If it exists, return its pointer. Otherwise, return nullptr.
524 */
526 /*
527 * Add virtual table(vtable) type symbol.
528 * This is added as a type symbol in the symbol table.
529 *
530 * This is done the first time when we encounter a virtual method in a class
531 */
533 const struct_typet::componentt &comp,
534 struct_typet &type);
535 /*
536 * Add virtual pointer(vptr).
537 * Vptr is NOT a symbol but rather simply added as a component to the class'
538 * type.
539 *
540 * This is done the first time we encounter a virtual method in a class
541 */
542 void add_vptr(struct_typet &type);
543 /*
544 * Add an entry to the virtual table type
545 *
546 * This is done when NOT the first time we encounter a virtual method in a
547 * class in which case we just want to add a new entry to the virtual table
548 * type
549 */
551 struct_typet &type,
553 symbolt *vtable_type_symbol);
554
555 /*
556 * Get the overriden methods to which we need to create thunks.
557 *
558 * Params:
559 * - md: clang AST of the overriding method
560 * - map: key: a map that takes method id as key and pointer to the overriden
561 * method AST
562 */
563 void
564 get_overriden_methods(const clang::CXXMethodDecl &md, overriden_map &map);
565 /*
566 * add a thunk function for each overriding method
567 *
568 * Params:
569 * - md: clang AST of the overriden method in base class
570 * - component: ESBMC IR representing the the overriding method in derived
571 * class' type
572 * - type: ESBMC IR representing the derived class' type
573 */
574 void add_thunk_method(
575 const clang::CXXMethodDecl &md,
576 const struct_typet::componentt &component,
577 struct_typet &type);
578 /*
579 * change the type of 'this' pointer from derived class type to base class
580 * type
581 */
583 typet &thunk_symbol_type,
584 const std::string &base_class_id);
585 /*
586 * Add symbol for arguments of the thunk method
587 * Params:
588 * - thunk_func_symb: function symbol for the thunk method
589 */
590 void add_thunk_method_arguments(symbolt &thunk_func_symb);
591 /*
592 * Add thunk function body
593 * Params:
594 * - thunk_func_symb: function symbol for the thunk method
595 * - component: ESBMC IR representing the the overriding method in derived
596 * class' type
597 */
599 symbolt &thunk_func_symb,
600 const struct_typet::componentt &component);
601 /*
602 * Add thunk body that contains return value
603 * Params:
604 * - thunk_func_symb: function symbol for the thunk method
605 * - component: ESBMC IR representing the the overriding method in derived
606 * class' type
607 * - late_cast_this: late casting of `this`
608 */
610 symbolt &thunk_func_symb,
611 const struct_typet::componentt &component,
612 const exprt &late_cast_this);
613 /*
614 * Add thunk body that does NOT contain return value
615 * Params:
616 * - thunk_func_symb: function symbol for the thunk method
617 * - component: ESBMC IR representing the the overriding method in derived
618 * class' type
619 * - late_cast_this: late casting of `this`
620 */
622 symbolt &thunk_func_symb,
623 const struct_typet::componentt &component,
624 const exprt &late_cast_this);
625 /*
626 * Add thunk function as a `method` in the derived class' type
627 * Params:
628 * - thunk_func_symbol: thunk function symbol
629 * - type: derived class' type
630 * - comp: `component` representing the overriding function
631 */
633 const symbolt &thunk_func_symb,
634 struct_typet &type,
635 const struct_typet::componentt &comp,
636 const irep_idt &virtual_name);
637 /*
638 * Set an intuitive name to thunk function
639 */
640 void
641 set_thunk_name(symbolt &thunk_func_symb, const std::string &base_class_id);
642 /*
643 * Recall that we mode the virtual function table as struct of function
644 * pointers. This function adds the symbols for these struct variables.
645 *
646 * Params:
647 * - cxxrd: clang AST node representing the class/struct we are currently
648 * dealing with
649 * - type: ESBMC IR representing the type the class/struct we are currently
650 * dealing with
651 * - vft_value_map: representing the vtable value maps for this class/struct
652 * we are currently dealing with
653 */
655 const clang::CXXRecordDecl &cxxrd,
656 const struct_typet &type);
657 /*
658 * This function builds the vtable value map -
659 * a map representing the function switch table
660 * with each key-value pair in the form of:
661 * Class X : {VirtualName Y : FunctionID}
662 *
663 * where X represents the name of a virtual/thunk/overriding function and
664 * function ID represents the actual function we are calling when calling the
665 * virtual/thunk/overriding function via a Class X* pointer, something like:
666 * xptr->Y()
667 *
668 * Params:
669 * - struct_type: ESBMC IR representing the type of the class/struct we are
670 * currently dealing with
671 * - vtable_value_map: representing the vtable value maps for this
672 * class/struct we are currently dealing with
673 */
674 void build_vtable_map(
675 const struct_typet &struct_type,
676 switch_table &vtable_value_map);
677 /*
678 * Create the vtable variable symbols and add them to the symbol table.
679 * Each vtable variable represents the actual function switch table, which
680 * is modelled as a struct of function pointers, e.g.:
681 * Vtable tag.Base@Base =
682 * {
683 * .do_something = &TagBase::do_someting();
684 * };
685 *
686 * Params:
687 * - cxxrd: clang AST node representing the class/struct we are currently
688 * dealing with
689 * - struct_type: ESBMC IR representing the type the class/struct we are
690 * currently dealing with
691 * - vtable_value_map: representing the vtable value maps for this
692 * class/struct we are currently dealing with
693 */
695 const clang::CXXRecordDecl &cxxrd,
696 const struct_typet &struct_type,
697 const switch_table &vtable_value_map);
698
699 /*
700 * Lower a C++ dynamic_cast expression. Lives next to the vtable code in
701 * clang_cpp_convert_vft.cpp because the runtime check compares against
702 * vtable variable addresses, which this file already names. Falls back
703 * to a structural typecast for the cases the helper does not yet cover
704 * (void*, dynamic_cast<T&>, virtual inheritance, missing vtable
705 * symbols) so it stays compatible with the legacy CK_Dynamic behaviour
706 * for those.
707 */
708 bool
709 build_dynamic_cast(const clang::CXXDynamicCastExpr &cast, exprt &new_expr);
710
711 /*
712 * Side table populated as we register vtable variables in
713 * add_vtable_variable_symbols: maps a vptr-owning class id (e.g.
714 * "tag-Base") to every concrete class that has a vtable variable for
715 * that vptr. build_dynamic_cast consults it directly instead of walking
716 * every CXXRecordDecl in the TU and probing the symbol table per cast.
717 *
718 * Pre-registered for the class currently being processed (via
719 * pre_register_inherited_vtables) so that dynamic_cast inside an inline
720 * method body sees its own class as a candidate D — the "real"
721 * registration in add_vtable_variable_symbols runs after method bodies
722 * are converted, which is too late for that body.
723 */
724 std::map<irep_idt, std::unordered_set<const clang::CXXRecordDecl *>>
726
727 /*
728 * Pre-register cxxrd in vtable_classes_per_vptr_ for every base whose
729 * vtable type symbol already exists, so that dynamic_cast<T&>(src) inside
730 * cxxrd's own inline method bodies can identify cxxrd as a candidate D.
731 * Bases are processed before derived classes, so any inherited vptr-class
732 * already has its vtable type symbol in the table.
733 */
734 void pre_register_inherited_vtables(const clang::CXXRecordDecl &cxxrd);
735
736 /*
737 * Methods for resolving a clang::MemberExpr to virtual/overriding method
738 */
739 bool perform_virtual_dispatch(const clang::MemberExpr &member) override;
740 bool is_md_virtual_or_overriding(const clang::CXXMethodDecl &cxxmd);
741 bool is_fd_virtual_or_overriding(const clang::FunctionDecl &fd) override;
742 bool get_vft_binding_expr(const clang::MemberExpr &member, exprt &new_expr)
743 override;
744 /*
745 * Get the base dereference for VFT bound MemberExpr
746 *
747 * Params:
748 * - member: the method to which this MemberExpr refers
749 * - new_expr: ESBMC IR to represent x dereferencing as in
750 * `x->X@vtable_ptr->F`
751 */
752 bool
753 get_vft_binding_expr_base(const clang::MemberExpr &member, exprt &new_expr);
754 /*
755 * Get the vtable poitner dereferencing for VFT bound MemberExpr
756 *
757 * Params:
758 * - md: the method to which this MemberExpr refers
759 * - new_expr: ESBMC IR to represent X@Vtable_ptr dereferencing as in
760 * `x->X@vtable_ptr->F`
761 * - base_deref: the base dereferencing expression incorporated in vtable
762 * pointer dereferencing expression
763 */
765 const clang::CXXMethodDecl &md,
766 exprt &new_expr,
767 const exprt &base_deref);
768 /*
769 * Get the Function for VFT bound MemberExpr
770 *
771 * Params:
772 * - md: the method to which this MemberExpr refers
773 * - new_expr: ESBMC IR to represent F in `x->X@vtable_ptr->F`
774 * - vtable_ptr_deref: the vtable pointer dereferencing expression
775 */
777 const clang::CXXMethodDecl &md,
778 exprt &new_expr,
779 const exprt &vtable_ptr_deref);
780 /*
781 * Get the function a pointer to the virtual member function md points to
782 */
784 const clang::CXXMethodDecl &md,
785 exprt &new_expr);
787 const clang::UnaryOperator &uniop,
788 exprt &new_expr) override;
789
790 bool is_aggregate_type(const clang::QualType &q_type) override;
791 /*
792 * check if a method is Copy assignment Operator or
793 * Move assignment Operator
794 * Arguments:
795 * md: clang AST representing a C++ method
796 */
797 bool is_CopyOrMoveOperator(const clang::CXXMethodDecl &md);
798 /*
799 * check if a method is constructor or destructor
800 * Arguments:
801 * md: clang AST representing a C++ method
802 */
803 bool is_ConstructorOrDestructor(const clang::CXXMethodDecl &md);
804 /*
805 * Check if expr is a temporary object
806 * if not, convert expr to a temporary object
807 * Arguments:
808 * expr: ESBMC IR to represent Function call
809 */
810 void make_temporary(exprt &expr);
811
812 /* Lower a class-typed conditional operator to a single temporary_object whose
813 * initializer branches, so both constructors target one object (guaranteed
814 * elision). Sets `elided` when it applied; leaves it false for shapes that
815 * keep the generic if_exprt lowering. Returns true on conversion error. */
817 const clang::ConditionalOperator &ternary,
818 exprt &new_expr,
819 bool &elided);
820
821 bool get_new_storage(const clang::CXXNewExpr &ne, exprt &new_expr);
822 bool get_dealloc_function(const clang::CXXDeleteExpr &de, exprt &new_expr);
823 bool get_align_val(
824 const clang::QualType &type,
825 const clang::ParmVarDecl &param,
826 exprt &align);
827
828 /* Lower a non-allocating placement new to
829 * comma(<initialize *(T*)place>, (T*)place); a side-effecting place is
830 * first bound to a local, ({ void *p = place; <that comma on p>; }).
831 * Returns true on error. */
833 const clang::CXXNewExpr &ne,
834 const typet &t,
835 const locationt &location,
836 exprt &new_expr);
837
838 bool get_member_expr(const clang::MemberExpr &memb, exprt &new_expr) override;
839};
840
841#endif /* CLANG_CPP_FRONTEND_CLANG_CPP_CONVERT_H_ */
static const twodig_t base
Definition bigint.cpp:28
clang_c_convertert(contextt &_context, std::unique_ptr< clang::ASTUnit > &_AST, irep_idt _mode)
Definition clang_c_convert.cpp:42
const clang::FunctionDecl * current_functionDecl
Definition clang_c_convert.h:125
bool build_dynamic_cast(const clang::CXXDynamicCastExpr &cast, exprt &new_expr)
Definition clang_cpp_convert_vft.cpp:959
bool get_new_storage(const clang::CXXNewExpr &ne, exprt &new_expr)
Definition clang_cpp_convert.cpp:4191
void gen_typecast_base_ctor_call(const exprt &callee_decl, side_effect_expr_function_callt &call, exprt &initializer)
Definition clang_cpp_convert.cpp:3754
bool need_new_object(const clang::Stmt *parentStmt, const clang::CXXConstructExpr &call)
Definition clang_cpp_convert.cpp:3821
bool get_align_val(const clang::QualType &type, const clang::ParmVarDecl &param, exprt &align)
Definition clang_cpp_convert.cpp:4269
bool get_dealloc_function(const clang::CXXDeleteExpr &de, exprt &new_expr)
Definition clang_cpp_convert.cpp:4239
void add_thunk_method(const clang::CXXMethodDecl &md, const struct_typet::componentt &component, struct_typet &type)
Definition clang_cpp_convert_vft.cpp:349
bool build_lambda_static_invoker(const clang::CXXMethodDecl &invoker, exprt &new_expr)
Body for a lambda's static invoker: forward to the closure's operator().
Definition clang_cpp_convert.cpp:2558
bool get_decl_ref(const clang::Decl &decl, exprt &new_expr) override
Get reference to a declared variable or function, e.g:
Definition clang_cpp_convert.cpp:3434
bool get_template_decl_specialization(const SpecializationDecl *D, bool DumpExplicitInst, exprt &new_expr)
Definition clang_cpp_convert.cpp:3386
void get_base_components_methods(base_map &map, struct_union_typet &type, bool has_virtual_bases, const clang::CXXRecordDecl &cxxrd)
Definition clang_cpp_convert.cpp:3899
void build_member_from_component(const clang::FunctionDecl &fd, exprt &component)
Definition clang_cpp_convert.cpp:2080
std::string vtable_ptr_suffix
Definition clang_cpp_convert.h:469
bool get_function_params(const clang::FunctionDecl &fd, code_typet::argumentst &params) override
Get function params for C++ contains conversion routines specific to C++ class member functions.
Definition clang_cpp_convert.cpp:3263
bool get_access_from_decl(const clang::Decl &decl, std::string &access)
Definition clang_cpp_convert.cpp:3594
exprt typeid_object(const exprt &value, const std::string &type_name, const clang::Stmt &stmt, bool dynamic)
The object a typeid expression refers to, which has static storage duration ([expr....
Definition clang_cpp_convert.cpp:827
bool get_struct_union_class_fields(const clang::RecordDecl &rd, struct_union_typet &type) override
Definition clang_cpp_convert.cpp:548
bool get_function_body(const clang::FunctionDecl &fd, exprt &new_expr, const code_typet &ftype) override
Definition clang_cpp_convert.cpp:2709
symbolt * check_vtable_type_symbol_existence(const struct_typet &type)
Definition clang_cpp_convert_vft.cpp:166
void add_vtable_type_entry(struct_typet &type, struct_typet::componentt &comp, symbolt *vtable_type_symbol)
Definition clang_cpp_convert_vft.cpp:300
bool get_placement_new(const clang::CXXNewExpr &ne, const typet &t, const locationt &location, exprt &new_expr)
Definition clang_cpp_convert.cpp:4284
bool annotate_class_field(const clang::FieldDecl &field, const struct_union_typet &type, struct_typet::componentt &comp)
Definition clang_cpp_convert.cpp:3559
exprt base_dtor_this(const clang::CXXRecordDecl &base, const exprt &deref, const irep_idt &this_id, const typet &this_ptr_type)
Definition clang_cpp_convert.cpp:2114
std::string constref_suffix
Definition clang_cpp_convert.h:129
void get_overriden_methods(const clang::CXXMethodDecl &md, overriden_map &map)
Definition clang_cpp_convert_vft.cpp:860
void add_thunk_method_arguments(symbolt &thunk_func_symb)
Definition clang_cpp_convert_vft.cpp:485
bool get_vft_binding_expr(const clang::MemberExpr &member, exprt &new_expr) override
Definition clang_cpp_convert_bind.cpp:85
void add_thunk_method_body(symbolt &thunk_func_symb, const struct_typet::componentt &component)
Definition clang_cpp_convert_vft.cpp:552
bool get_conditional_class_prvalue(const clang::ConditionalOperator &ternary, exprt &new_expr, bool &elided)
Definition clang_cpp_convert.cpp:4134
std::map< std::string, const clang::CXXMethodDecl & > overriden_map
Definition clang_cpp_convert.h:490
cap_mapt cap_map
Definition clang_cpp_convert.h:80
std::map< irep_idt, function_switch > switch_table
Definition clang_cpp_convert.h:489
void name_param_and_continue(const clang::ParmVarDecl &pd, std::string &id, std::string &name, exprt &param) override
Definition clang_cpp_convert.cpp:3326
void make_temporary(exprt &expr)
Definition clang_cpp_convert.cpp:4381
bool annotate_virtual_overriding_methods(const clang::CXXMethodDecl &md, struct_typet::componentt &comp)
Definition clang_cpp_convert_vft.cpp:146
bool get_method_declaration(const clang::CXXMethodDecl &md, const symbolt *&symbol)
Definition clang_cpp_convert.cpp:472
this_mapt this_map
Definition clang_cpp_convert.h:24
void annotate_exception_specification(const clang::FunctionDecl &fd, typet &type) override
Since this class is inherited by clang-cpp-frontend, some get_* functions are made `virtual' to deal ...
Definition clang_cpp_convert.cpp:3129
std::string rtti_type_name(const clang::QualType &qtype)
Definition clang_cpp_convert_vft.cpp:178
std::string thunk_prefix
Definition clang_cpp_convert.h:486
code_function_callt base_destructor(const symbolt &sym, const clang::CXXRecordDecl &base, const clang::CXXMethodDecl &md)
Definition clang_cpp_convert.cpp:2221
void annotate_ctor_dtor_rtn_type(const clang::CXXMethodDecl &cxxmdd, typet &rtn_type)
Definition clang_cpp_convert.cpp:4042
bool get_base_map(const clang::CXXRecordDecl &cxxrd, base_map &map)
Definition clang_cpp_convert.cpp:3860
const clang::Expr & elided_copy_source(const clang::Expr &init) override
Definition clang_cpp_convert.cpp:2676
virtual ~clang_cpp_convertert()=default
bool get_method(const clang::CXXMethodDecl &md, exprt &new_expr)
Definition clang_cpp_convert.cpp:508
bool is_lambda() const
Definition clang_cpp_convert.h:82
bool get_decl(const clang::Decl &decl, exprt &new_expr) override
Definition clang_cpp_convert.cpp:48
bool get_struct_union_class(const clang::RecordDecl &rd) override
Definition clang_cpp_convert.cpp:539
bool user_code_uses_exceptions()
Definition clang_cpp_convert.cpp:2336
bool get_vft_binding_expr_base(const clang::MemberExpr &member, exprt &new_expr)
Definition clang_cpp_convert_bind.cpp:114
symbolt * get_fd_symbol(const clang::FunctionDecl &fd)
Definition clang_cpp_convert.cpp:3852
clang_cpp_convertert(contextt &_context, std::unique_ptr< clang::ASTUnit > &_AST, irep_idt _mode)
Definition clang_cpp_convert.cpp:40
bool get_constructor_call(const clang::CXXConstructExpr &constructor_call, exprt &new_expr)
Get reference for constructor callsite.
Definition clang_cpp_convert.cpp:1979
bool member_destructor(const clang::FieldDecl &field, const exprt &deref, code_blockt &calls)
Definition clang_cpp_convert.cpp:2170
bool get_struct_class_virtual_methods(const clang::CXXRecordDecl &cxxrd, struct_typet &type)
Definition clang_cpp_convert_vft.cpp:42
static irep_idt rtti_name_component_id(const irep_idt &vtable_type_id)
Definition clang_cpp_convert_vft.cpp:210
bool insert_constructor_initializers(const clang::CXXConstructorDecl &cd, exprt::operandst &initializers, std::vector< std::size_t > starts, const symbolt *array_init_sym, code_blockt &body)
Definition clang_cpp_convert.cpp:2503
bool get_member_expr(const clang::MemberExpr &memb, exprt &new_expr) override
Definition clang_cpp_convert.cpp:3724
void add_thunk_method_body_no_return(symbolt &thunk_func_symb, const struct_typet::componentt &component, const exprt &late_cast_this)
Definition clang_cpp_convert_vft.cpp:649
bool get_new_initializer(const clang::CXXNewExpr &ne, exprt &new_expr)
Attach a new-expression's initializer, and for an array its braced list's filler: a run-time element ...
Definition clang_cpp_convert.cpp:788
void get_vft_binding_expr_vtable_ptr(const clang::CXXMethodDecl &md, exprt &new_expr, const exprt &base_deref)
Definition clang_cpp_convert_bind.cpp:134
bool has_vptr_component
Definition clang_cpp_convert.h:485
std::unordered_map< std::size_t, std::pair< std::string, typet > > this_mapt
Definition clang_cpp_convert.h:23
bool get_function_this_pointer_param(const clang::CXXMethodDecl &fd, code_typet::argumentst &params)
Add implicit this' when parsing C++ class member functions, e.g: class t1 { int i; t1(){i = 1}...
Definition clang_cpp_convert.cpp:3171
void set_thunk_name(symbolt &thunk_func_symb, const std::string &base_class_id)
Definition clang_cpp_convert_vft.cpp:448
symbolt * add_vtable_type_symbol(const struct_typet::componentt &comp, struct_typet &type)
Definition clang_cpp_convert_vft.cpp:226
void build_vtable_map(const struct_typet &struct_type, switch_table &vtable_value_map)
Definition clang_cpp_convert_vft.cpp:716
bool get_cxx_constructor_is_complete_param(const clang::CXXConstructorDecl &cxxcd, code_typet::argumentt &param)
Definition clang_cpp_convert.cpp:3222
void add_vtable_variable_symbols(const clang::CXXRecordDecl &cxxrd, const struct_typet &struct_type, const switch_table &vtable_value_map)
Definition clang_cpp_convert_vft.cpp:760
bool destroy_object_on_body_unwind(const clang::CXXConstructorDecl &cd, std::size_t body_start, code_blockt &body)
Definition clang_cpp_convert.cpp:2396
void annotate_implicit_copy_move_ctor_union(const clang::CXXMethodDecl &cxxmdd, typet &ctor_return_type)
Definition clang_cpp_convert.cpp:4015
void pre_register_inherited_vtables(const clang::CXXRecordDecl &cxxrd)
Definition clang_cpp_convert_vft.cpp:889
bool is_fd_virtual_or_overriding(const clang::FunctionDecl &fd) override
Definition clang_cpp_convert_bind.cpp:76
bool build_destructor_chain(const clang::CXXDestructorDecl &dd, code_blockt &body)
Definition clang_cpp_convert.cpp:2530
std::map< irep_idt, exprt > function_switch
Definition clang_cpp_convert.h:488
bool annotate_class_method(const clang::CXXMethodDecl &cxxmdd, exprt &new_expr)
Definition clang_cpp_convert.cpp:3625
void get_decl_name(const clang::NamedDecl &nd, std::string &name, std::string &id) override
Definition clang_cpp_convert.cpp:222
bool is_md_virtual_or_overriding(const clang::CXXMethodDecl &cxxmd)
Definition clang_cpp_convert_bind.cpp:68
bool get_type(const clang::QualType &type, typet &new_type) override
Definition clang_cpp_convert.cpp:354
static struct_typet::componentt rtti_name_component(const irep_idt &vtable_type_id)
Definition clang_cpp_convert_vft.cpp:216
bool get_template_decl(const TemplateDecl &D, bool DumpExplicitInst, exprt &new_expr)
Definition clang_cpp_convert.cpp:3422
std::unordered_map< std::size_t, std::pair< field_mapt, clang::FieldDecl * > > cap_mapt
Definition clang_cpp_convert.h:79
bool is_defaulted_ctor(const clang::CXXMethodDecl &md)
Definition clang_cpp_convert.cpp:4033
bool get_struct_union_class_methods_decls(const clang::RecordDecl &rd, typet &type) override
Definition clang_cpp_convert.cpp:591
const symbolt * nontrivial_destructor(const clang::CXXRecordDecl *rec)
Definition clang_cpp_convert.cpp:2140
codet rethrowing_catch(const code_blockt &tried, code_blockt handler)
Definition clang_cpp_convert.cpp:2382
bool get_virtual_member_function_pointer(const clang::CXXMethodDecl &md, exprt &new_expr)
Definition clang_cpp_convert_bind.cpp:180
bool is_copy_or_move_ctor(const clang::DeclContext &dcxt)
Definition clang_cpp_convert.cpp:4025
bool is_duplicate_method(const struct_typet::componentt &method, const struct_union_typet &type)
Definition clang_cpp_convert.cpp:4001
std::string vcall_prefix
Definition clang_cpp_convert.h:487
bool is_CopyOrMoveOperator(const clang::CXXMethodDecl &md)
Definition clang_cpp_convert.cpp:4092
bool get_member_initializer(const clang::Expr &init, const typet &member_type, exprt &rhs)
Definition clang_cpp_convert.cpp:2689
void setup_vtable_struct_variables(const clang::CXXRecordDecl &cxxrd, const struct_typet &type)
Definition clang_cpp_convert_vft.cpp:693
void update_thunk_this_type(typet &thunk_symbol_type, const std::string &base_class_id)
Definition clang_cpp_convert_vft.cpp:464
bool get_ctor_dtor_ref(const clang::CXXMethodDecl &md, exprt &new_expr)
Definition clang_cpp_convert.cpp:3538
bool get_vft_binding_expr_function(const clang::CXXMethodDecl &md, exprt &new_expr, const exprt &vtable_ptr_deref)
Definition clang_cpp_convert_bind.cpp:154
bool perform_virtual_dispatch(const clang::MemberExpr &member) override
Definition clang_cpp_convert_bind.cpp:36
bool annotate_class_field_access(const clang::FieldDecl &field, struct_typet::componentt &comp)
Definition clang_cpp_convert.cpp:3581
void add_thunk_component_to_type(const symbolt &thunk_func_symb, struct_typet &type, const struct_typet::componentt &comp, const irep_idt &virtual_name)
Definition clang_cpp_convert_vft.cpp:680
bool get_unary_operator_expr(const clang::UnaryOperator &uniop, exprt &new_expr) override
Definition clang_cpp_convert_bind.cpp:252
void add_thunk_method_body_return(symbolt &thunk_func_symb, const struct_typet::componentt &component, const exprt &late_cast_this)
Definition clang_cpp_convert_vft.cpp:586
bool is_ConstructorOrDestructor(const clang::CXXMethodDecl &md)
Definition clang_cpp_convert.cpp:4097
llvm::DenseMap< const CAPTURE_VARIABLE_TYPE *, clang::FieldDecl * > field_mapt
Definition clang_cpp_convert.h:76
void add_vptr(struct_typet &type)
Definition clang_cpp_convert_vft.cpp:273
bool is_duplicate_component(const struct_typet::componentt &component, const struct_union_typet &type)
Definition clang_cpp_convert.cpp:3987
std::map< irep_idt, std::unordered_set< const clang::CXXRecordDecl * > > vtable_classes_per_vptr_
Definition clang_cpp_convert.h:725
std::optional< bool > uses_exceptions
Definition clang_cpp_convert.h:228
bool subobject_destructors(const clang::CXXMethodDecl &md, std::vector< subobject_destructort > &out)
Definition clang_cpp_convert.cpp:2235
bool get_expr(const clang::Stmt &stmt, exprt &new_expr) override
Definition clang_cpp_convert.cpp:936
bool get_var(const clang::VarDecl &vd, exprt &new_expr) override
Definition clang_cpp_convert.cpp:463
std::vector< std::pair< std::string, const clang::CXXRecordDecl * > > base_map
Definition clang_cpp_convert.h:407
const this_mapt::mapped_type & method_this(const clang::CXXMethodDecl &md) const
Definition clang_cpp_convert.cpp:2161
bool unwind_constructed_subobjects(const clang::CXXConstructorDecl &cd, const std::vector< std::size_t > &starts, code_blockt &body)
Definition clang_cpp_convert.cpp:2429
std::string vtable_type_prefix
Definition clang_cpp_convert.h:468
bool is_aggregate_type(const clang::QualType &q_type) override
Definition clang_cpp_convert.cpp:4053
Definition std_code.h:49
A `switch' instruction */ class code_switcht : public codet { public: inline code_switcht() : codet("...
Definition std_code.h:574
Definition std_types.h:297
Definition std_types.h:280
std::vector< argumentt > argumentst
Definition std_types.h:283
Definition std_code.h:8
Definition context.h:57
Definition expr.h:34
std::vector< exprt > operandst
Definition expr.h:39
Definition irep_idt.h:12
Definition location.h:7
Definition std_code.h:905
Definition std_types.h:232
Definition std_types.h:87
Definition std_types.h:78
Definition symbol.h:12
Definition type.h:9
Definition toml.hpp:1531
Definition clang_cpp_convert.h:197
std::size_t position
Definition clang_cpp_convert.h:198
code_blockt calls
Definition clang_cpp_convert.h:199