37 if(expr.
id()==ID_already_typechecked)
58 if(expr.
id()==ID_div ||
63 if(expr.
type().
id()==ID_floatbv &&
72 expr.
id(ID_floatbv_div);
73 else if(expr.
id()==ID_mult)
74 expr.
id(ID_floatbv_mult);
75 else if(expr.
id()==ID_plus)
76 expr.
id(ID_floatbv_plus);
77 else if(expr.
id()==ID_minus)
78 expr.
id(ID_floatbv_minus);
94 if(type1.
id()==ID_symbol)
96 else if(type2.
id()==ID_symbol)
103 if(type1.
id()==ID_c_enum_tag)
105 else if(type2.
id()==ID_c_enum_tag)
108 if(type1.
id()==ID_c_enum)
110 if(type2.
id()==ID_c_enum)
112 else if(type2==type1.
subtype())
115 else if(type2.
id()==ID_c_enum)
120 else if(type1.
id()==ID_pointer &&
121 type2.
id()==ID_pointer)
125 else if(type1.
id()==ID_array &&
126 type2.
id()==ID_array)
131 else if(type1.
id()==ID_code &&
145 for(std::size_t i=0; i<c_type1.
parameters().size(); i++)
161 if(type1.
get(ID_C_c_type)==type2.
get(ID_C_c_type))
171 if(expr.
id()==ID_side_effect)
173 else if(expr.
id()==ID_constant)
175 else if(expr.
id()==ID_infinity)
179 else if(expr.
id()==ID_symbol)
181 else if(expr.
id()==ID_unary_plus ||
182 expr.
id()==ID_unary_minus ||
183 expr.
id()==ID_bitnot)
185 else if(expr.
id()==ID_not)
187 else if(expr.
id()==ID_and || expr.
id()==ID_or || expr.
id()==ID_implies)
189 else if(expr.
id()==ID_address_of)
191 else if(expr.
id()==ID_dereference)
193 else if(expr.
id()==ID_member)
195 else if(expr.
id()==ID_ptrmember)
197 else if(expr.
id()==ID_equal ||
198 expr.
id()==ID_notequal ||
204 else if(expr.
id()==ID_index)
206 else if(expr.
id()==ID_typecast)
208 else if(expr.
id()==ID_sizeof)
210 else if(expr.
id()==ID_alignof)
212 else if(expr.
id()==ID_plus || expr.
id()==ID_minus ||
213 expr.
id()==ID_mult || expr.
id()==ID_div ||
215 expr.
id()==ID_bitand || expr.
id()==ID_bitxor || expr.
id()==ID_bitor)
217 else if(expr.
id()==ID_shl || expr.
id()==ID_shr)
219 else if(expr.
id()==ID_comma)
221 else if(expr.
id()==ID_if)
223 else if(expr.
id()==ID_code)
226 error() <<
"typecheck_expr_main got code: " << expr.
pretty() <<
eom;
229 else if(expr.
id()==ID_gcc_builtin_va_arg)
231 else if(expr.
id()==ID_cw_va_arg_typeof)
233 else if(expr.
id()==ID_gcc_builtin_types_compatible_p)
237 assert(subtypes.size()==2);
243 subtypes[0].
remove(ID_C_constant);
244 subtypes[0].remove(ID_C_volatile);
245 subtypes[0].remove(ID_C_restricted);
246 subtypes[1].remove(ID_C_constant);
247 subtypes[1].remove(ID_C_volatile);
248 subtypes[1].remove(ID_C_restricted);
253 else if(expr.
id()==ID_clang_builtin_convertvector)
257 else if(expr.
id()==ID_builtin_offsetof)
259 else if(expr.
id()==ID_string_constant)
262 expr.
set(ID_C_lvalue,
true);
264 else if(expr.
id()==ID_arguments)
268 else if(expr.
id()==ID_designated_initializer)
270 exprt &designator=
static_cast<exprt &
>(expr.
add(ID_designator));
274 if(it->id()==ID_index)
276 assert(it->operands().size()==1);
281 else if(expr.
id()==ID_initializer_list)
286 else if(expr.
id()==ID_forall ||
287 expr.
id()==ID_exists)
294 if(expr.
op0().
get(ID_statement)!=ID_decl)
297 error() <<
"expected declaration as operand of quantifier" <<
eom;
305 else if(expr.
id()==ID_label)
309 else if(expr.
id()==ID_array)
313 else if(expr.
id()==ID_complex)
318 else if(expr.
id()==ID_complex_real ||
319 expr.
id()==ID_complex_imag)
324 if(op_type.id()!=ID_complex)
329 error() <<
"real/imag expect numerical operand, " 344 expr.
set(ID_C_lvalue,
true);
347 expr.
set(ID_C_constant,
true);
350 else if(expr.
id()==ID_generic_selection)
359 error() <<
"_Generic expects one operand" <<
eom;
374 if(it->get(ID_type_arg)!=ID_default)
376 typet &type=
static_cast<typet &
>(it->add(ID_type_arg));
388 if(it->get(ID_type_arg)==ID_default)
389 default_match=static_cast<const exprt &>(it->find(ID_value));
391 follow(static_cast<const typet &>(it->find(ID_type_arg))))
392 assoc_match=static_cast<const exprt &>(it->find(ID_value));
398 expr.
swap(default_match);
402 error() <<
"unmatched generic selection: " 408 expr.
swap(assoc_match);
413 else if(expr.
id()==ID_gcc_asm_input ||
414 expr.
id()==ID_gcc_asm_output ||
415 expr.
id()==ID_gcc_asm_clobbered_register)
418 else if(expr.
id()==ID_lshr || expr.
id()==ID_ashr ||
419 expr.
id()==ID_assign_lshr || expr.
id()==ID_assign_ashr)
436 error() <<
"comma operator expects two operands" <<
eom;
444 expr.
set(ID_C_lvalue,
true);
482 symbol.
name=ID_gcc_builtin_va_arg;
483 symbol.
type=symbol_type;
512 error() <<
"builtin_offsetof expects no operands" <<
eom;
527 if(m_it->id()==ID_member)
529 if(type.
id()!=ID_union && type.
id()!=ID_struct)
532 error() <<
"offsetof of member expects struct/union type, " 538 irep_idt component_name=m_it->get(ID_component_name);
542 assert(type.
id()==ID_union || type.
id()==ID_struct);
548 if(struct_union_type.has_component(component_name))
552 if(type.
id()==ID_struct)
561 error() <<
"offsetof failed to determine offset of `" 562 << component_name <<
"'" <<
eom;
572 type=struct_union_type.get_component(component_name).type();
579 struct_union_type.components();
583 for(struct_union_typet::componentst::const_iterator
584 c_it=components.begin();
585 c_it!=components.end();
588 if(c_it->get_anonymous() &&
589 (
follow(c_it->type()).
id()==ID_struct ||
590 follow(c_it->type()).
id()==ID_union))
594 if(type.
id()==ID_struct)
603 error() <<
"offsetof failed to determine offset of `" 604 << component_name <<
"'" <<
eom;
616 assert(type.id()==ID_union || type.id()==ID_struct);
626 error() <<
"offset-of of member failed to find component `" 627 << component_name <<
"' in `" 634 else if(m_it->id()==ID_index)
636 assert(m_it->operands().size()==1);
638 if(type.
id()!=ID_array)
641 error() <<
"offsetof of index expects array type" <<
eom;
670 if(expr.
id()==ID_side_effect &&
671 expr.
get(ID_statement)==ID_function_call)
678 else if(expr.
id()==ID_side_effect &&
679 expr.
get(ID_statement)==ID_statement_expression)
683 else if(expr.
id()==ID_forall || expr.
id()==ID_exists)
692 if(declaration.declarators().size()!=1)
695 error() <<
"expected one declarator exactly" <<
eom;
700 declaration.declarators().front().get_name();
703 symbol_tablet::symbolst::const_iterator s_it=
709 error() <<
"failed to find decl symbol `" << identifier
710 <<
"' in symbol table" <<
eom;
714 const symbolt &symbol=s_it->second;
720 error() <<
"unexpected quantified symbol" <<
eom;
743 id_type_mapt::const_iterator p_it=
parameter_map.find(identifier);
747 expr.
type()=p_it->second;
748 expr.
set(ID_C_lvalue,
true);
753 asm_label_mapt::const_iterator entry=
757 identifier=entry->second;
763 if(
lookup(identifier, symbol_ptr))
766 error() <<
"failed to find symbol `" 767 << identifier <<
"'" <<
eom;
771 const symbolt &symbol=*symbol_ptr;
776 error() <<
"did not expect a type symbol here, but got `" 794 if(expr.
id()==ID_constant &&
796 expr.
set(ID_C_cformat, base_name);
811 else if(identifier==
"__func__" ||
812 identifier==
"__FUNCTION__" ||
813 identifier==
"__PRETTY_FUNCTION__")
819 s.
set(ID_C_lvalue,
true);
830 expr.
set(ID_C_lvalue,
true);
832 if(expr.
type().
id()==ID_code)
835 tmp.
set(ID_C_implicit,
true);
848 error() <<
"statement expression expects one operand" <<
eom;
859 irep_idt last_statement=last.get_statement();
861 if(last_statement==ID_expression)
863 assert(last.operands().size()==1);
867 if(op.type().id()==ID_array)
870 expr.
type()=op.type();
872 else if(last_statement==ID_function_call)
887 expr.
type()=sideeffect.type();
893 last.
swap(code_expr);
904 last.
swap(code_expr);
917 type.
swap(static_cast<typet &>(expr.
add(ID_type_arg)));
927 error() <<
"sizeof operator expects zero or one operand, " 934 if(type.
id()==ID_c_bit_field)
937 error() <<
"sizeof cannot be applied to bit fields" <<
eom;
940 else if(type.
id() == ID_empty)
960 expr.
add(ID_C_c_sizeof_type)=type;
968 decl_block.set_statement(ID_decl_block);
969 side_effect_expr.copy_to_operands(decl_block);
980 expr.
swap(comma_expr);
989 argument_type=expr.
op0().
type();
994 argument_type=op_type;
1011 error() <<
"typecast operator expects one operand" <<
eom;
1025 decl_block.set_statement(ID_decl_block);
1026 side_effect_expr.copy_to_operands(decl_block);
1037 op.
swap(comma_expr);
1042 if(expr_type.
id()==ID_union &&
1044 op.
id()!=ID_initializer_list)
1059 for(union_typet::componentst::const_iterator
1060 it=components.begin();
1061 it!=components.end();
1070 union_expr.set_component_name(it->get_name());
1072 expr.
set(ID_C_lvalue,
true);
1079 error() <<
"type cast to union: type `" 1087 if(op.
id()==ID_initializer_list)
1096 exprt tmp(ID_compound_literal, expr.
type());
1100 if(op.
id()==ID_array &&
1101 expr.
type().
id()==ID_array &&
1103 tmp.type()=op.
type();
1106 expr.
set(ID_C_lvalue,
true);
1111 if(expr_type.
id()==ID_empty)
1122 if(expr_type.
id()==ID_vector)
1125 if(op_type.
id()==ID_vector)
1127 else if(op_type.
id()==ID_signedbv ||
1128 op_type.
id()==ID_unsignedbv)
1135 error() <<
"type cast to `" 1136 <<
to_string(expr_type) <<
"' is not permitted" <<
eom;
1143 else if(op_type.
id()==ID_array)
1151 else if(op_type.
id()==ID_empty)
1153 if(expr_type.
id()!=ID_empty)
1156 error() <<
"type cast from void only permitted to void, but got `" 1161 else if(op_type.
id()==ID_vector)
1168 if((expr_type.
id()==ID_signedbv ||
1169 expr_type.
id()==ID_unsignedbv) &&
1177 error() <<
"type cast from vector to `" 1185 error() <<
"type cast from `" 1201 if(expr_type.
id()==ID_pointer)
1202 expr.
set(ID_C_lvalue,
true);
1216 error() <<
"operator `" << expr.
id()
1217 <<
"' expects two operands" <<
eom;
1230 if(array_full_type.
id()!=ID_array &&
1231 array_full_type.
id()!=ID_pointer &&
1232 array_full_type.
id()!=ID_vector &&
1233 (index_full_type.id()==ID_array ||
1234 index_full_type.id()==ID_pointer ||
1235 index_full_type.id()==ID_vector))
1236 std::swap(array_expr, index_expr);
1246 if(final_array_type.
id()==ID_array ||
1247 final_array_type.
id()==ID_vector)
1249 if(array_expr.
get_bool(ID_C_lvalue))
1250 expr.
set(ID_C_lvalue,
true);
1252 else if(final_array_type.
id()==ID_pointer)
1257 exprt addition(ID_plus, array_expr.
type());
1260 expr.
id(ID_dereference);
1261 expr.
set(ID_C_lvalue,
true);
1266 error() <<
"operator [] must take array/vector or pointer but got `" 1281 if(expr.
id()==ID_equal)
1282 expr.
id(ID_ieee_float_equal);
1283 else if(expr.
id()==ID_notequal)
1284 expr.
id(ID_ieee_float_notequal);
1297 if(
follow(o_type0).
id()==ID_vector ||
1298 follow(o_type1).
id()==ID_vector)
1306 if(expr.
id()==ID_equal || expr.
id()==ID_notequal)
1311 if(final_type.
id()!=ID_array &&
1312 final_type.
id()!=ID_incomplete_struct)
1333 if(type0.
id()==ID_pointer)
1335 if(expr.
id()==ID_equal || expr.
id()==ID_notequal)
1338 if(expr.
id()==ID_le || expr.
id()==ID_lt ||
1339 expr.
id()==ID_ge || expr.
id()==ID_gt)
1343 if(type0.
id()==ID_string_constant)
1345 if(expr.
id()==ID_equal || expr.
id()==ID_notequal)
1352 if(type0.
id()==ID_pointer &&
1359 if(type1.
id()==ID_pointer &&
1379 if(type0.
id()==ID_pointer && type1.
id()==ID_pointer)
1387 error() <<
"operator `" << expr.
id()
1388 <<
"' not defined for types `" 1403 if(o_type0.
id()!=ID_vector ||
1404 o_type1.id()!=ID_vector ||
1408 error() <<
"vector operator `" << expr.
id()
1409 <<
"' not defined for types `" 1425 error() <<
"ptrmember operator expects one operand" <<
eom;
1431 if(final_op0_type.
id()==ID_array)
1436 index_expr.
set(ID_C_lvalue,
true);
1439 else if(final_op0_type.
id()==ID_pointer)
1450 error() <<
"ptrmember operator requires pointer or array type " 1451 "on left hand side, but got `" 1465 error() <<
"member operator expects one operand" <<
eom;
1474 if(type.
id()==ID_incomplete_struct)
1477 error() <<
"member operator got incomplete struct type " 1478 "on left hand side" <<
eom;
1482 if(type.
id()==ID_incomplete_union)
1485 error() <<
"member operator got incomplete union type " 1486 "on left hand side" <<
eom;
1490 if(type.
id()!=ID_struct &&
1491 type.
id()!=ID_union)
1494 error() <<
"member operator requires structure type " 1495 "on left hand side but got `" 1504 expr.
get(ID_component_name);
1520 error() <<
"member `" << component_name
1521 <<
"' not found in `" 1534 expr.
set(ID_C_lvalue,
true);
1537 expr.
set(ID_C_constant,
true);
1540 const irep_idt &identifier=component.
get(ID_C_identifier);
1542 if(!identifier.
empty())
1543 expr.
set(ID_C_identifier, identifier);
1547 if(access==ID_private)
1550 error() <<
"member `" << component_name
1551 <<
"' is " << access <<
eom;
1560 assert(operands.size()==3);
1563 const typet o_type0=operands[0].type();
1564 const typet o_type1=operands[1].type();
1565 const typet o_type2=operands[2].type();
1570 if(operands[1].type().
id()==ID_pointer &&
1571 operands[2].type().
id()!=ID_pointer)
1573 else if(operands[2].type().
id()==ID_pointer &&
1574 operands[1].type().
id()!=ID_pointer)
1577 if(operands[1].type().
id()==ID_pointer &&
1578 operands[2].type().
id()==ID_pointer &&
1579 operands[1].type()!=operands[2].type())
1586 if(operands[1].type().subtype().
id()==ID_empty &&
1590 else if(operands[2].type().subtype().id()==ID_empty &&
1594 else if(operands[1].type().subtype().id()!=ID_code ||
1595 operands[2].type().subtype().id()!=ID_code)
1619 if(operands[1].type().id()==ID_empty ||
1620 operands[2].type().id()==ID_empty)
1626 if(
follow(operands[1].type())==
follow(operands[2].type()))
1628 expr.
type()=operands[1].type();
1634 if(operands[1].get_bool(ID_C_lvalue) &&
1635 operands[2].get_bool(ID_C_lvalue))
1636 expr.
set(ID_C_lvalue,
true);
1642 error() <<
"operator ?: not defined for types `" 1656 if(operands.size()!=2)
1659 error() <<
"gcc conditional_expr expects two operands" <<
eom;
1666 if_expr.
cond()=operands[0];
1674 expr.
op0()=if_expr.
op1();
1675 expr.
op1()=if_expr.
op2();
1684 error() <<
"unary operator & expects one operand" <<
eom;
1690 if(op.
type().
id()==ID_c_bit_field)
1693 error() <<
"cannot take address of a bit field" <<
eom;
1698 if(op.
id()==ID_label)
1710 if(op.
id()==ID_address_of &&
1718 tmp.
set(ID_C_implicit,
false);
1723 if(op.
id()==ID_struct ||
1724 op.
id()==ID_union ||
1725 op.
id()==ID_array ||
1726 op.
id()==ID_string_constant)
1734 else if(op.
type().
id()==ID_code)
1742 <<
"' not an lvalue" <<
eom;
1754 error() <<
"unary operator * expects one operand" <<
eom;
1762 if(op_type.
id()==ID_array)
1770 else if(op_type.
id()==ID_pointer)
1778 <<
"' is not a pointer, but got `" 1783 expr.
set(ID_C_lvalue,
true);
1794 if(expr.
type().
id()==ID_code)
1797 tmp.
set(ID_C_implicit,
true);
1807 if(statement==ID_preincrement ||
1808 statement==ID_predecrement ||
1809 statement==ID_postincrement ||
1810 statement==ID_postdecrement)
1815 error() << statement <<
"operator expects one operand" <<
eom;
1826 <<
"' not an lvalue" <<
eom;
1834 <<
"' is constant" <<
eom;
1838 if(final_type0.
id()==ID_c_enum_tag)
1841 ID_incomplete_c_enum)
1844 error() <<
"operator `" << statement
1845 <<
"' given incomplete type `" 1852 else if(final_type0.
id()==ID_c_bit_field)
1857 expr.
type()=underlying_type;
1863 else if(final_type0.
id()==ID_pointer)
1871 error() <<
"operator `" << statement
1872 <<
"' not defined for type `" 1879 else if(statement==ID_function_call)
1882 else if(statement==ID_statement_expression)
1884 else if(statement==ID_gcc_conditional_expression)
1889 error() <<
"unknown side effect: " << statement <<
eom;
1900 error() <<
"function_call side effect expects two operands" <<
eom;
1909 if(f_op.
id()==ID_symbol)
1913 asm_label_mapt::const_iterator entry=
1916 identifier=entry->second;
1936 if(identifier==
"malloc" ||
1937 identifier==
"realloc" ||
1938 identifier==
"reallocf" ||
1939 identifier==
"valloc")
1944 new_symbol.
name=identifier;
1948 new_symbol.
type.
set(ID_C_incomplete,
true);
1957 warning() <<
"function `" << identifier <<
"' is not declared" <<
eom;
1967 if(f_op_type.
id()!=ID_pointer)
1970 error() <<
"expected function/function pointer as argument but got `" 1976 if(f_op.
id()==ID_address_of &&
1987 tmp.
set(ID_C_implicit,
true);
1992 if(f_op.
type().
id()!=ID_code)
1995 error() <<
"expected code as argument" <<
eom;
2018 if(f_op.
id()!=ID_symbol)
2028 error() <<
"same_object expects two operands" <<
eom;
2032 exprt same_object_expr=
2036 return same_object_expr;
2043 error() <<
"get_must expects two operands" <<
eom;
2053 return get_must_expr;
2060 error() <<
"get_may expects two operands" <<
eom;
2070 return get_may_expr;
2077 error() <<
"invalid_pointer expects one operand" <<
eom;
2084 return same_object_expr;
2091 error() <<
"buffer_size expects one operand" <<
eom;
2099 return buffer_size_expr;
2106 error() <<
"is_zero_string expects one operand" <<
eom;
2112 is_zero_string_expr.
set(ID_C_lvalue,
true);
2115 return is_zero_string_expr;
2122 error() <<
"zero_string_length expects one operand" <<
eom;
2126 exprt zero_string_length_expr(
"zero_string_length",
size_type());
2128 zero_string_length_expr.
set(ID_C_lvalue,
true);
2131 return zero_string_length_expr;
2138 error() <<
"dynamic_object expects one argument" <<
eom;
2146 return dynamic_object_expr;
2153 error() <<
"pointer_offset expects one argument" <<
eom;
2167 error() <<
"pointer_object expects one argument" <<
eom;
2176 else if(identifier==
"__builtin_bswap16" ||
2177 identifier==
"__builtin_bswap32" ||
2178 identifier==
"__builtin_bswap64")
2185 error() << identifier <<
" expects one operand" <<
eom;
2196 identifier ==
"__builtin_fpclassify" ||
2202 error() << identifier <<
" expects six arguments" <<
eom;
2213 if(fp_value.
type().
id() != ID_floatbv)
2216 error() <<
"non-floating-point argument for " << identifier <<
eom;
2224 const auto &arguments = expr.
arguments();
2243 identifier==
"__builtin_isnan")
2248 error() <<
"isnan expects one operand" <<
eom;
2264 error() <<
"isfinite expects one operand" <<
eom;
2274 identifier==
"__builtin_inf")
2311 error() <<
"abs-functions expect one operand" <<
eom;
2325 error() <<
"allocate expects two operands" <<
eom;
2340 error() << identifier <<
" expects two operands" <<
eom;
2354 identifier==
"__builtin_isinf")
2359 error() << identifier <<
" expects one operand" <<
eom;
2368 else if(identifier ==
"__builtin_isinf_sign")
2373 error() << identifier <<
" expects one operand" <<
eom;
2395 identifier ==
"__builtin_isnormal")
2400 error() << identifier <<
" expects one operand" <<
eom;
2406 if(fp_value.
type().
id() != ID_floatbv)
2409 error() <<
"non-floating-point argument for " << identifier <<
eom;
2421 identifier==
"__builtin_signbit" ||
2422 identifier==
"__builtin_signbitf" ||
2423 identifier==
"__builtin_signbitl")
2428 error() << identifier <<
" expects one operand" <<
eom;
2437 else if(identifier==
"__builtin_popcount" ||
2438 identifier==
"__builtin_popcountl" ||
2439 identifier==
"__builtin_popcountll" ||
2440 identifier==
"__popcnt16" ||
2441 identifier==
"__popcnt" ||
2442 identifier==
"__popcnt64")
2447 error() << identifier <<
" expects one operand" <<
eom;
2454 return popcount_expr;
2461 error() <<
"equal expects two operands" <<
eom;
2470 equality_expr.
rhs().
type(), *
this))
2473 error() <<
"equal expects two operands of same type" <<
eom;
2477 return equality_expr;
2479 else if(identifier==
"__builtin_expect")
2490 error() <<
"__builtin_expect expects two arguments" <<
eom;
2496 else if(identifier==
"__builtin_object_size")
2505 error() <<
"__builtin_object_size expects two arguments" <<
eom;
2520 error() <<
"__builtin_object_size expects constant as second argument, " 2528 if(arg1==0 || arg1==1)
2541 else if(identifier==
"__builtin_choose_expr")
2547 error() <<
"__builtin_choose_expr expects three arguments" <<
eom;
2559 else if(identifier==
"__builtin_constant_p")
2566 error() <<
"__builtin_constant_p expects one argument" <<
eom;
2574 bool is_constant=
false;
2578 if(tmp1.
id()==ID_typecast &&
2580 tmp1.
op0().
id()==ID_address_of &&
2596 else if(identifier==
"__builtin_classify_type")
2603 error() <<
"__builtin_classify_type expects one argument" <<
eom;
2614 if(type.
id() == ID_c_bit_field)
2617 unsigned type_number;
2619 if(type.
id() == ID_bool || type.
id() == ID_c_bool)
2630 type.
id() == ID_empty
2632 : (type.
id() == ID_bool || type.
id() == ID_c_bool)
2634 : (type.
id() == ID_pointer || type.
id() == ID_array)
2636 : type.
id() == ID_floatbv
2638 : (type.
id() == ID_complex && type.
subtype().
id() == ID_floatbv)
2640 : type.
id() == ID_struct
2642 : type.
id() == ID_union
2658 error() <<
"float_debug expects two operands" <<
eom;
2664 "float_debug1":
"float_debug2";
2666 exprt float_debug_expr(
id, expr.
type());
2668 float_debug_expr.add_source_location()=source_location;
2670 return float_debug_expr;
2672 else if(identifier==
"__sync_fetch_and_add" ||
2673 identifier==
"__sync_fetch_and_sub" ||
2674 identifier==
"__sync_fetch_and_or" ||
2675 identifier==
"__sync_fetch_and_and" ||
2676 identifier==
"__sync_fetch_and_xor" ||
2677 identifier==
"__sync_fetch_and_nand" ||
2678 identifier==
"__sync_add_and_fetch" ||
2679 identifier==
"__sync_sub_and_fetch" ||
2680 identifier==
"__sync_or_and_fetch" ||
2681 identifier==
"__sync_and_and_fetch" ||
2682 identifier==
"__sync_xor_and_fetch" ||
2683 identifier==
"__sync_nand_and_fetch" ||
2684 identifier==
"__sync_val_compare_and_swap" ||
2685 identifier==
"__sync_lock_test_and_set" ||
2686 identifier==
"__sync_lock_release")
2695 error() <<
"__sync_* primitives take as least one argument" <<
eom;
2701 if(ptr_arg.
type().
id()!=ID_pointer)
2704 error() <<
"__sync_* primitives take pointer as first argument" <<
eom;
2729 if(code_type.
get_bool(ID_C_incomplete))
2733 else if(code_type.
is_KnR())
2738 while(parameter_types.size()>arguments.size())
2743 if(parameter_types.size()>arguments.size())
2746 error() <<
"not enough function arguments" <<
eom;
2750 else if(parameter_types.size()!=arguments.size())
2753 error() <<
"wrong number of function arguments: " 2754 <<
"expected " << parameter_types.size()
2755 <<
", but got " << arguments.size() <<
eom;
2759 for(std::size_t i=0; i<arguments.size(); i++)
2761 exprt &op=arguments[i];
2767 else if(i<parameter_types.size())
2772 const typet &op_type=parameter_type.
type();
2774 if(op_type.
id()==ID_bool &&
2775 op.
id()==ID_side_effect &&
2776 op.
get(ID_statement)==ID_assign &&
2780 warning() <<
"assignment where Boolean argument is expected" <<
eom;
2790 if(type.
id()==ID_array)
2793 dest_type.
subtype().
set(ID_C_constant, ID_1);
2810 error() <<
"operator `" << expr.
id()
2811 <<
"' expects one operand" <<
eom;
2819 if(o_type.
id()==ID_vector)
2838 error() <<
"operator `" << expr.
id()
2839 <<
"' not defined for type `" 2849 error() <<
"operator `" << expr.
id()
2850 <<
"' expects one operand" <<
eom;
2882 if((type0.
subtype().
id()==ID_signedbv ||
2898 error() <<
"operator `" << expr.
id()
2899 <<
"' expects two operands" <<
eom;
2909 if(o_type0.
id()==ID_vector &&
2910 o_type1.id()==ID_vector)
2917 if(o_type0!=o_type1)
2931 if(expr.
id()==ID_plus || expr.
id()==ID_minus ||
2932 expr.
id()==ID_mult || expr.
id()==ID_div)
2934 if(type0.
id()==ID_pointer || type1.id()==ID_pointer)
2939 else if(type0==type1)
2948 else if(expr.
id()==ID_mod)
2952 if(type0.
id()==ID_signedbv || type0.
id()==ID_unsignedbv)
2959 else if(expr.
id()==ID_bitand ||
2960 expr.
id()==ID_bitxor ||
2961 expr.
id()==ID_bitor)
2970 else if(type0.
id()==ID_bool)
2972 if(expr.
id()==ID_bitand)
2974 else if(expr.
id()==ID_bitor)
2976 else if(expr.
id()==ID_bitxor)
2987 error() <<
"operator `" << expr.
id()
2988 <<
"' not defined for types `" 2996 assert(expr.
id()==ID_shl || expr.
id()==ID_shr);
3004 if(o_type0.
id()==ID_vector &&
3005 o_type1.id()==ID_vector)
3013 expr.
type()=op0.type();
3018 if(o_type0.
id()==ID_vector &&
3023 expr.
type()=op0.type();
3034 expr.
type()=op0.type();
3036 if(expr.
id()==ID_shr)
3040 if(op0_type.
id()==ID_unsignedbv)
3045 else if(op0_type.
id()==ID_signedbv)
3056 error() <<
"operator `" << expr.
id()
3057 <<
"' not defined for types `" 3066 assert(type.
id()==ID_pointer);
3070 if(subtype.id()==ID_symbol)
3073 if(subtype.id()==ID_incomplete_struct)
3076 error() <<
"pointer arithmetic with unknown object size" <<
eom;
3091 if(expr.
id()==ID_minus ||
3092 (expr.
id()==ID_side_effect && expr.
get(ID_statement)==ID_assign_minus))
3094 if(type0.
id()==ID_pointer &&
3095 type1.id()==ID_pointer)
3105 if(type0.
id()==ID_pointer &&
3106 (type1.id()==ID_bool ||
3107 type1.id()==ID_c_bool ||
3108 type1.id()==ID_unsignedbv ||
3109 type1.id()==ID_signedbv ||
3110 type1.id()==ID_c_bit_field ||
3111 type1.id()==ID_c_enum_tag))
3119 else if(expr.
id()==ID_plus ||
3120 (expr.
id()==ID_side_effect && expr.
get(ID_statement)==ID_assign_plus))
3122 exprt *p_op, *int_op;
3124 if(type0.
id()==ID_pointer)
3129 else if(type1.id()==ID_pointer)
3136 p_op=int_op=
nullptr;
3142 if(int_op_type.
id()==ID_bool ||
3143 int_op_type.
id()==ID_c_bool ||
3144 int_op_type.
id()==ID_unsignedbv ||
3145 int_op_type.
id()==ID_signedbv ||
3146 int_op_type.
id()==ID_c_bit_field ||
3147 int_op_type.
id()==ID_c_enum_tag)
3158 if(expr.
id()==ID_side_effect)
3164 error() <<
"operator `" << op_name
3165 <<
"' not defined for types `" 3176 error() <<
"operator `" << expr.
id()
3177 <<
"' expects two operands" <<
eom;
3199 <<
"' expects two operands" <<
eom;
3211 if(type0.
id()==ID_empty)
3214 error() <<
"cannot assign void" <<
eom;
3222 <<
"' not an lvalue" <<
eom;
3230 <<
"' is constant" <<
eom;
3235 if(type0.
id()==ID_array ||
3236 type0.
id()==ID_incomplete_array)
3239 error() <<
"direct assignments to arrays not permitted" <<
eom;
3246 if(op0.
type().
id()==ID_c_bit_field)
3252 expr.
type()=o_type0;
3254 if(statement==ID_assign)
3259 else if(statement==ID_assign_shl ||
3260 statement==ID_assign_shr)
3266 if(statement==ID_assign_shl)
3276 if(underlying_type.
id()==ID_c_enum_tag)
3278 const typet &c_enum_type=
3280 underlying_type=c_enum_type.
subtype();
3283 if(underlying_type.
id()==ID_unsignedbv ||
3284 underlying_type.
id()==ID_c_bool)
3286 expr.
set(ID_statement, ID_assign_lshr);
3289 else if(underlying_type.
id()==ID_signedbv)
3291 expr.
set(ID_statement, ID_assign_ashr);
3297 else if(statement==ID_assign_bitxor ||
3298 statement==ID_assign_bitand ||
3299 statement==ID_assign_bitor)
3302 if(o_type0.
id()==ID_bool ||
3303 o_type0.
id()==ID_c_bool)
3306 if(op1.
type().
id()==ID_bool ||
3307 op1.
type().
id()==ID_c_bool ||
3308 op1.
type().
id()==ID_c_enum_tag ||
3309 op1.
type().
id()==ID_unsignedbv ||
3310 op1.
type().
id()==ID_signedbv)
3313 else if(o_type0.
id()==ID_c_enum_tag ||
3314 o_type0.
id()==ID_unsignedbv ||
3315 o_type0.
id()==ID_signedbv ||
3316 o_type0.
id()==ID_c_bit_field)
3321 else if(o_type0.
id()==ID_vector &&
3322 o_type1.
id()==ID_vector)
3328 if(o_type0!=o_type1)
3336 if(o_type0.
id()==ID_pointer &&
3337 (statement==ID_assign_minus || statement==ID_assign_plus))
3342 else if(o_type0.
id()==ID_vector &&
3343 o_type1.
id()==ID_vector)
3349 if(o_type0!=o_type1)
3354 else if(o_type0.
id()==ID_bool ||
3355 o_type0.
id()==ID_c_bool)
3358 if(op1.
type().
id()==ID_bool ||
3359 op1.
type().
id()==ID_c_bool ||
3360 op1.
type().
id()==ID_c_enum_tag ||
3361 op1.
type().
id()==ID_unsignedbv ||
3362 op1.
type().
id()==ID_signedbv)
3370 op1.
type().
id()==ID_bool ||
3371 op1.
type().
id()==ID_c_bool ||
3372 op1.
type().
id()==ID_c_enum_tag)
3378 error() <<
"assignment `" << statement
3379 <<
"' not defined for types `" 3391 const auto rounding_mode =
3398 expr.
id()!=ID_infinity)
3401 error() <<
"expected constant expression, but got `" 3414 expr.
id()!=ID_infinity)
3417 error() <<
"conversion to integer constant failed" <<
eom;
const if_exprt & to_if_expr(const exprt &expr)
Cast a generic exprt to an if_exprt.
virtual void typecheck_expr_binary_boolean(exprt &expr)
side_effect_expr_function_callt & to_side_effect_expr_function_call(exprt &expr)
The type of an expression.
irep_idt name
The unique identifier.
exprt size_of_expr(const typet &type, const namespacet &ns)
std::map< irep_idt, source_locationt > labels_used
struct configt::ansi_ct ansi_c
virtual void typecheck_side_effect_assignment(side_effect_exprt &expr)
virtual void implicit_typecast_bool(exprt &expr)
virtual bool is_complete_type(const typet &type) const
void typecheck_declaration(ansi_c_declarationt &)
exprt member_offset_expr(const member_exprt &member_expr, const namespacet &ns)
A generic base class for relations, i.e., binary predicates.
const std::string & id2string(const irep_idt &d)
pointer_typet pointer_type(const typet &subtype)
asm_label_mapt asm_label_map
virtual void typecheck_expr_index(exprt &expr)
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
constant_exprt to_expr() const
exprt simplify_expr(const exprt &src, const namespacet &ns)
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a generic typet to a bitvector_typet.
Fixed-width bit-vector with IEEE floating-point interpretation.
std::vector< irept > subt
virtual void make_constant(exprt &expr)
bool base_type_eq(const typet &type1, const typet &type2, const namespacet &ns)
Evaluates to true if the operand is infinite.
void move_symbol(symbolt &symbol, symbolt *&new_symbol)
bool has_ellipsis() const
virtual void typecheck_expr_rel_vector(binary_relation_exprt &expr)
unsignedbv_typet unsigned_int_type()
const code_typet & to_code_type(const typet &type)
Cast a generic typet to a code_typet.
const irep_idt & get_function() const
void copy_to_operands(const exprt &expr)
const irep_idt & get_identifier() const
std::vector< componentt > componentst
void move_to_operands(exprt &expr)
const irep_idt & get_value() const
std::vector< parametert > parameterst
const componentst & components() const
id_type_mapt parameter_map
The trinary if-then-else operator.
Evaluates to true if the operand is a normal number.
bool has_component_rec(const typet &type, const irep_idt &component_name, const namespacet &ns)
mp_integer pointer_offset_bits(const typet &type, const namespacet &ns)
unsignedbv_typet size_type()
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
A constant literal expression.
void make_bool(bool value)
static mstreamt & eom(mstreamt &m)
bool get_bool(const irep_namet &name) const
signedbv_typet pointer_diff_type()
virtual std::string to_string(const exprt &expr)
const typet & follow_tag(const union_tag_typet &) const
virtual void typecheck_side_effect_gcc_conditional_expression(side_effect_exprt &expr)
exprt get_component_rec(const exprt &struct_union, const irep_idt &component_name, const namespacet &ns)
void adjust_float_expressions(exprt &expr, const exprt &rounding_mode)
This adds the rounding mode to floating-point operations, including those in vectors and complex numb...
side_effect_exprt & to_side_effect_expr(exprt &expr)
static ieee_float_spect double_precision()
bool builtin_factory(const irep_idt &identifier, symbol_tablet &symbol_table, message_handlert &mh)
Check whether given identifier is a compiler built-in.
symbol_tablet & symbol_table
mstreamt & warning() const
virtual void typecheck_expr_cw_va_arg_typeof(exprt &expr)
preprocessort preprocessor
void follow_macros(exprt &) const
virtual void typecheck_expr_symbol(exprt &expr)
static bool is_numeric_type(const typet &src)
const irep_idt & id() const
Evaluates to true if the operand is NaN.
An expression denoting infinity.
class symbol_exprt symbol_expr() const
produces a symbol_exprt for a symbol
virtual void typecheck_expr_side_effect(side_effect_exprt &expr)
virtual void typecheck_expr_operands(exprt &expr)
ANSI-C Language Type Checking.
ANSI-C Language Type Checking.
A declaration of a local variable.
virtual void typecheck_expr_member(exprt &expr)
const source_locationt & find_source_location() const
source_locationt source_location
Operator to dereference a pointer.
A constant-size array type.
exprt pointer_object(const exprt &p)
virtual void make_index_type(exprt &expr)
virtual void typecheck_expr_binary_arithmetic(exprt &expr)
union constructor from single element
mp_integer alignment(const typet &type, const namespacet &ns)
const irep_idt & get(const irep_namet &name) const
virtual void typecheck_expr_trinary(if_exprt &expr)
virtual void typecheck_expr_unary_boolean(exprt &expr)
static ieee_float_spect single_precision()
virtual void typecheck_side_effect_function_call(side_effect_expr_function_callt &expr)
const exprt & size() const
const binary_relation_exprt & to_binary_relation_expr(const exprt &expr)
Cast a generic exprt to a binary_relation_exprt.
const vector_typet & to_vector_type(const typet &type)
Cast a generic typet to a vector_typet.
bool has_prefix(const std::string &s, const std::string &prefix)
virtual void typecheck_expr(exprt &expr)
#define forall_operands(it, expr)
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast a generic exprt to a symbol_exprt.
void err_location(const source_locationt &loc)
virtual void typecheck_side_effect_statement_expression(side_effect_exprt &expr)
virtual void typecheck_expr_typecast(exprt &expr)
const typet & follow(const typet &) const
bitvector_typet index_type()
#define Forall_irep(it, irep)
const struct_typet & to_struct_type(const typet &type)
Cast a generic typet to a struct_typet.
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
std::list< codet > clean_code
codet & find_last_statement()
Operator to return the address of an object.
std::vector< typet > subtypest
Various predicates over pointers in programs.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast a generic exprt to a constant_exprt.
virtual void typecheck_expr_function_identifier(exprt &expr)
const c_enum_tag_typet & to_c_enum_tag_type(const typet &type)
Cast a generic typet to a c_enum_tag_typet.
static exprt conditional_cast(const exprt &expr, const typet &type)
std::vector< exprt > operandst
virtual void typecheck_expr_builtin_offsetof(exprt &expr)
bitvector_typet long_double_type()
bool gcc_vector_types_compatible(const vector_typet &, const vector_typet &)
const irep_idt & display_name() const
virtual void typecheck_function_call_arguments(side_effect_expr_function_callt &expr)
A function call side effect.
Complex numbers made of pair of given subtype.
virtual exprt do_special_functions(side_effect_expr_function_callt &expr)
virtual void implicit_typecast(exprt &expr, const typet &type)
virtual void typecheck_expr_unary_arithmetic(exprt &expr)
typet type
Type of symbol.
source_locationt location
Source code location of definition of symbol.
virtual void typecheck_expr_sizeof(exprt &expr)
message_handlert & get_message_handler()
const irep_idt & get_access() const
const shift_exprt & to_shift_expr(const exprt &expr)
Cast a generic exprt to a shift_exprt.
Base type of C structs and unions, and C++ classes.
mstreamt & result() const
bool is_number(const typet &type)
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a generic typet to a floatbv_typet.
The popcount (counting the number of bits set to 1) expression.
Evaluates to true if the operand is finite.
exprt invalid_pointer(const exprt &pointer)
const array_typet & to_array_type(const typet &type)
Cast a generic typet to an array_typet.
Base class for all expressions.
virtual void typecheck_expr_builtin_va_arg(exprt &expr)
const parameterst & parameters() const
irep_idt base_name
Base (non-scoped) name.
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a generic typet to a struct_union_typet.
exprt pointer_offset(const exprt &pointer)
const union_typet & to_union_type(const typet &type)
Cast a generic typet to a union_typet.
virtual void typecheck_expr_pointer_arithmetic(exprt &expr)
const source_locationt & source_location() const
virtual void typecheck_expr_dereference(exprt &expr)
virtual void make_constant_index(exprt &expr)
irept & add(const irep_namet &name)
exprt::operandst & arguments()
void set_identifier(const irep_idt &identifier)
#define Forall_operands(it, expr)
virtual bool gcc_types_compatible_p(const typet &, const typet &)
source_locationt & add_source_location()
const codet & to_code(const exprt &expr)
virtual void implicit_typecast_arithmetic(exprt &expr)
const c_bit_field_typet & to_c_bit_field_type(const typet &type)
Cast a generic typet to a c_bit_field_typet.
static void add_rounding_mode(exprt &)
Expression to hold a symbol (variable)
static ieee_floatt plus_infinity(const ieee_float_spect &_spec)
const code_blockt & to_code_block(const codet &code)
virtual void typecheck_type(typet &type)
virtual void typecheck_expr_rel(binary_relation_exprt &expr)
virtual void do_initializer(exprt &initializer, const typet &type, bool force_constant)
A statement in a programming language.
A generic base class for expressions that are predicates, i.e., boolean-typed, and that take exactly ...
signedbv_typet signed_int_type()
ansi_c_declarationt & to_ansi_c_declaration(exprt &expr)
void remove(const irep_namet &name)
const typet & subtype() const
virtual void typecheck_expr_address_of(exprt &expr)
virtual void typecheck_expr_constant(exprt &expr)
virtual void typecheck_expr_comma(exprt &expr)
An expression containing a side effect.
virtual void typecheck_expr_main(exprt &expr)
virtual void typecheck_arithmetic_pointer(const exprt &expr)
virtual void typecheck_expr_alignof(exprt &expr)
exprt same_object(const exprt &p1, const exprt &p2)
void make_typecast(const typet &_type)
const irept & find(const irep_namet &name) const
A base class for shift operators.
bitvector_typet char_type()
const typet & return_type() const
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See namespace_baset::lookup().
The byte swap expression.
void set(const irep_namet &name, const irep_idt &value)
virtual void typecheck_expr_shifts(shift_exprt &expr)
const componentt & get_component(const irep_idt &component_name) const
const irep_idt & get_statement() const
virtual void typecheck_expr_ptrmember(exprt &expr)
virtual std::pair< symbolt &, bool > insert(symbolt symbol) override
Author: Diffblue Ltd.
virtual void typecheck_code(codet &code)
const code_function_callt & to_code_function_call(const codet &code)
bool simplify(exprt &expr, const namespacet &ns)
A generic base class for expressions that are predicates, i.e., boolean-typed.
static ieee_floatt zero(const floatbv_typet &type)
IEEE-floating-point equality.
#define forall_irep(it, irep)
C Language Type Checking.
virtual void adjust_float_rel(exprt &expr)