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);
486 symbol.
name=ID_gcc_builtin_va_arg;
487 symbol.
type=symbol_type;
516 error() <<
"builtin_offsetof expects no operands" <<
eom;
529 if(type.
id()==ID_symbol)
532 if(m_it->id()==ID_member)
534 if(type.
id()!=ID_union && type.
id()!=ID_struct)
537 error() <<
"offsetof of member expects struct/union type, " 543 irep_idt component_name=m_it->get(ID_component_name);
547 assert(type.
id()==ID_union || type.
id()==ID_struct);
553 if(struct_union_type.has_component(component_name))
557 if(type.
id()==ID_struct)
564 error() <<
"offsetof failed to determine offset of `" 565 << component_name <<
"'" <<
eom;
575 type=struct_union_type.get_component(component_name).type();
582 struct_union_type.components();
586 for(struct_union_typet::componentst::const_iterator
587 c_it=components.begin();
588 c_it!=components.end();
591 if(c_it->get_anonymous() &&
592 (
follow(c_it->type()).
id()==ID_struct ||
593 follow(c_it->type()).
id()==ID_union))
597 if(type.
id()==ID_struct)
605 error() <<
"offsetof failed to determine offset of `" 606 << component_name <<
"'" <<
eom;
618 assert(type.id()==ID_union || type.id()==ID_struct);
628 error() <<
"offset-of of member failed to find component `" 629 << component_name <<
"' in `" 636 else if(m_it->id()==ID_index)
638 assert(m_it->operands().size()==1);
640 if(type.
id()!=ID_array)
643 error() <<
"offsetof of index expects array type" <<
eom;
672 if(expr.
id()==ID_side_effect &&
673 expr.
get(ID_statement)==ID_function_call)
680 else if(expr.
id()==ID_side_effect &&
681 expr.
get(ID_statement)==ID_statement_expression)
685 else if(expr.
id()==ID_forall || expr.
id()==ID_exists)
694 if(declaration.declarators().size()!=1)
697 error() <<
"expected one declarator exactly" <<
eom;
702 declaration.declarators().front().get_name();
705 symbol_tablet::symbolst::iterator s_it=
711 error() <<
"failed to find decl symbol `" << identifier
712 <<
"' in symbol table" <<
eom;
722 error() <<
"unexpected quantified symbol" <<
eom;
746 id_type_mapt::const_iterator p_it=
parameter_map.find(identifier);
750 expr.
type()=p_it->second;
751 expr.
set(ID_C_lvalue,
true);
756 asm_label_mapt::const_iterator entry=
760 identifier=entry->second;
766 if(
lookup(identifier, symbol_ptr))
769 error() <<
"failed to find symbol `" 770 << identifier <<
"'" <<
eom;
774 const symbolt &symbol=*symbol_ptr;
779 error() <<
"did not expect a type symbol here, but got `" 797 if(expr.
id()==ID_constant &&
799 expr.
set(ID_C_cformat, base_name);
814 else if(identifier==
"__func__" ||
815 identifier==
"__FUNCTION__" ||
816 identifier==
"__PRETTY_FUNCTION__")
822 s.
set(ID_C_lvalue,
true);
833 expr.
set(ID_C_lvalue,
true);
835 if(expr.
type().
id()==ID_code)
838 tmp.
set(
"#implicit",
true);
851 error() <<
"statement expression expects one operand" <<
eom;
862 irep_idt last_statement=last.get_statement();
864 if(last_statement==ID_expression)
866 assert(last.operands().size()==1);
870 if(op.type().id()==ID_array)
873 expr.
type()=op.type();
875 else if(last_statement==ID_function_call)
897 codet code_expr(ID_expression);
900 last.swap(code_expr);
904 codet code_expr(ID_expression);
907 exprt assign(ID_side_effect);
908 assign.
set(ID_statement, ID_assign);
914 last.swap(code_expr);
927 type.
swap(static_cast<typet &>(expr.
add(ID_type_arg)));
937 error() <<
"sizeof operator expects zero or one operand, " 942 if(type.
id()==ID_c_bit_field)
945 error() <<
"sizeof cannot be applied to bit fields" <<
eom;
960 expr.
add(ID_C_c_sizeof_type)=type;
979 expr.
swap(comma_expr);
988 argument_type=expr.
op0().
type();
993 argument_type=op_type;
1010 error() <<
"typecast operator expects one operand" <<
eom;
1035 op.
swap(comma_expr);
1040 if(expr_type.
id()==ID_union &&
1042 op.
id()!=ID_initializer_list)
1057 for(union_typet::componentst::const_iterator
1058 it=components.begin();
1059 it!=components.end();
1068 union_expr.set_component_name(it->get_name());
1070 expr.
set(ID_C_lvalue,
true);
1077 error() <<
"type cast to union: type `" 1085 if(op.
id()==ID_initializer_list)
1094 exprt tmp(ID_compound_literal, expr.
type());
1097 expr.
set(ID_C_lvalue,
true);
1102 if(expr_type.
id()==ID_empty)
1113 if(expr_type.
id()==ID_vector)
1116 if(op_type.
id()==ID_vector)
1118 else if(op_type.
id()==ID_signedbv ||
1119 op_type.
id()==ID_unsignedbv)
1126 error() <<
"type cast to `" 1127 <<
to_string(expr_type) <<
"' is not permitted" <<
eom;
1134 else if(op_type.
id()==ID_array)
1142 else if(op_type.
id()==ID_empty)
1144 if(expr_type.
id()!=ID_empty)
1147 error() <<
"type cast from void only permitted to void, but got `" 1152 else if(op_type.
id()==ID_vector)
1159 if((expr_type.
id()==ID_signedbv ||
1160 expr_type.
id()==ID_unsignedbv) &&
1168 error() <<
"type cast from vector to `" 1176 error() <<
"type cast from `" 1192 if(expr_type.
id()==ID_pointer)
1193 expr.
set(ID_C_lvalue,
true);
1207 error() <<
"operator `" << expr.
id()
1208 <<
"' expects two operands" <<
eom;
1221 if(array_full_type.
id()!=ID_array &&
1222 array_full_type.
id()!=ID_pointer &&
1223 array_full_type.
id()!=ID_vector &&
1224 (index_full_type.id()==ID_array ||
1225 index_full_type.id()==ID_pointer ||
1226 index_full_type.id()==ID_vector))
1227 std::swap(array_expr, index_expr);
1234 if(final_array_type.
id()==ID_array ||
1235 final_array_type.
id()==ID_vector)
1237 if(array_expr.
get_bool(ID_C_lvalue))
1238 expr.
set(ID_C_lvalue,
true);
1240 else if(final_array_type.
id()==ID_pointer)
1245 exprt addition(ID_plus, array_expr.
type());
1248 expr.
id(ID_dereference);
1249 expr.
set(ID_C_lvalue,
true);
1254 error() <<
"operator [] must take array/vector or pointer but got `" 1269 if(expr.
id()==ID_equal)
1270 expr.
id(ID_ieee_float_equal);
1271 else if(expr.
id()==ID_notequal)
1272 expr.
id(ID_ieee_float_notequal);
1285 if(
follow(o_type0).
id()==ID_vector ||
1286 follow(o_type1).
id()==ID_vector)
1294 if(expr.
id()==ID_equal || expr.
id()==ID_notequal)
1299 if(final_type.
id()!=ID_array &&
1300 final_type.
id()!=ID_incomplete_struct)
1321 if(type0.
id()==ID_pointer)
1323 if(expr.
id()==ID_equal || expr.
id()==ID_notequal)
1326 if(expr.
id()==ID_le || expr.
id()==ID_lt ||
1327 expr.
id()==ID_ge || expr.
id()==ID_gt)
1331 if(type0.
id()==ID_string_constant)
1333 if(expr.
id()==ID_equal || expr.
id()==ID_notequal)
1340 if(type0.
id()==ID_pointer &&
1347 if(type1.
id()==ID_pointer &&
1367 if(type0.
id()==ID_pointer && type1.
id()==ID_pointer)
1375 error() <<
"operator `" << expr.
id()
1376 <<
"' not defined for types `" 1391 if(o_type0.
id()!=ID_vector ||
1392 o_type1.id()!=ID_vector ||
1396 error() <<
"vector operator `" << expr.
id()
1397 <<
"' not defined for types `" 1413 error() <<
"ptrmember operator expects one operand" <<
eom;
1419 if(final_op0_type.
id()!=ID_pointer &&
1420 final_op0_type.
id()!=ID_array)
1423 error() <<
"ptrmember operator requires pointer type " 1424 "on left hand side, but got `" 1431 exprt deref(ID_dereference);
1448 error() <<
"member operator expects one operand" <<
eom;
1457 if(type.
id()==ID_incomplete_struct)
1460 error() <<
"member operator got incomplete struct type " 1461 "on left hand side" <<
eom;
1465 if(type.
id()==ID_incomplete_union)
1468 error() <<
"member operator got incomplete union type " 1469 "on left hand side" <<
eom;
1473 if(type.
id()!=ID_struct &&
1474 type.
id()!=ID_union)
1477 error() <<
"member operator requires structure type " 1478 "on left hand side but got `" 1487 expr.
get(ID_component_name);
1503 error() <<
"member `" << component_name
1504 <<
"' not found in `" 1517 expr.
set(ID_C_lvalue,
true);
1520 expr.
set(ID_C_constant,
true);
1523 const irep_idt &identifier=component.
get(ID_C_identifier);
1525 if(!identifier.
empty())
1526 expr.
set(ID_C_identifier, identifier);
1530 if(access==ID_private)
1533 error() <<
"member `" << component_name
1534 <<
"' is " << access <<
eom;
1543 assert(operands.size()==3);
1546 const typet o_type0=operands[0].type();
1547 const typet o_type1=operands[1].type();
1548 const typet o_type2=operands[2].type();
1553 if(operands[1].type().
id()==ID_pointer &&
1554 operands[2].type().
id()!=ID_pointer)
1556 else if(operands[2].type().
id()==ID_pointer &&
1557 operands[1].type().
id()!=ID_pointer)
1560 if(operands[1].type().
id()==ID_pointer &&
1561 operands[2].type().
id()==ID_pointer &&
1562 operands[1].type()!=operands[2].type())
1569 if(operands[1].type().subtype().
id()==ID_empty &&
1573 else if(operands[2].type().subtype().id()==ID_empty &&
1577 else if(operands[1].type().subtype().id()!=ID_code ||
1578 operands[2].type().subtype().id()!=ID_code)
1603 if(operands[1].type().id()==ID_empty ||
1604 operands[2].type().id()==ID_empty)
1610 if(
follow(operands[1].type())==
follow(operands[2].type()))
1612 expr.
type()=operands[1].type();
1618 if(operands[1].get_bool(ID_C_lvalue) &&
1619 operands[2].get_bool(ID_C_lvalue))
1620 expr.
set(ID_C_lvalue,
true);
1626 error() <<
"operator ?: not defined for types `" 1640 if(operands.size()!=2)
1643 error() <<
"gcc conditional_expr expects two operands" <<
eom;
1650 if_expr.
cond()=operands[0];
1658 expr.
op0()=if_expr.
op1();
1659 expr.
op1()=if_expr.
op2();
1668 error() <<
"unary operator & expects one operand" <<
eom;
1674 if(op.
type().
id()==ID_c_bit_field)
1677 error() <<
"cannot take address of a bit field" <<
eom;
1682 if(op.
id()==ID_label)
1694 if(op.
id()==ID_address_of &&
1702 tmp.
set(ID_C_implicit,
false);
1707 if(op.
id()==ID_struct ||
1708 op.
id()==ID_union ||
1709 op.
id()==ID_array ||
1710 op.
id()==ID_string_constant)
1718 else if(op.
type().
id()==ID_code)
1726 <<
"' not an lvalue" <<
eom;
1738 error() <<
"unary operator * expects one operand" <<
eom;
1746 if(op_type.
id()==ID_array)
1754 else if(op_type.
id()==ID_pointer)
1762 <<
"' is not a pointer, but got `" 1767 expr.
set(ID_C_lvalue,
true);
1778 if(expr.
type().
id()==ID_code)
1781 tmp.
set(ID_C_implicit,
true);
1791 if(statement==ID_preincrement ||
1792 statement==ID_predecrement ||
1793 statement==ID_postincrement ||
1794 statement==ID_postdecrement)
1799 error() << statement <<
"operator expects one operand" <<
eom;
1810 <<
"' not an lvalue" <<
eom;
1818 <<
"' is constant" <<
eom;
1822 if(final_type0.
id()==ID_c_enum_tag)
1825 ID_incomplete_c_enum)
1828 error() <<
"operator `" << statement
1829 <<
"' given incomplete type `" 1836 else if(final_type0.
id()==ID_c_bit_field)
1841 expr.
type()=underlying_type;
1847 else if(final_type0.
id()==ID_pointer)
1855 error() <<
"operator `" << statement
1856 <<
"' not defined for type `" 1863 else if(statement==ID_function_call)
1866 else if(statement==ID_statement_expression)
1868 else if(statement==ID_gcc_conditional_expression)
1873 error() <<
"unknown side effect: " << statement <<
eom;
1884 error() <<
"function_call side effect expects two operands" <<
eom;
1893 if(f_op.
id()==ID_symbol)
1897 asm_label_mapt::const_iterator entry=
1900 identifier=entry->second;
1911 if(identifier==
"malloc" ||
1912 identifier==
"realloc" ||
1913 identifier==
"reallocf" ||
1914 identifier==
"valloc")
1919 new_symbol.
name=identifier;
1923 new_symbol.
type.
set(ID_C_incomplete,
true);
1932 warning() <<
"function `" << identifier <<
"' is not declared" <<
eom;
1941 if(f_op_type.
id()!=ID_pointer)
1944 error() <<
"expected function/function pointer as argument but got `" 1950 if(f_op.
id()==ID_address_of &&
1961 tmp.
set(ID_C_implicit,
true);
1963 tmp.move_to_operands(f_op);
1967 if(f_op.
type().
id()!=ID_code)
1970 error() <<
"expected code as argument" <<
eom;
1993 if(f_op.
id()!=ID_symbol)
2003 error() <<
"same_object expects two operands" <<
eom;
2007 exprt same_object_expr=
2011 return same_object_expr;
2018 error() <<
"get_must expects two operands" <<
eom;
2024 exprt get_must_expr=
2029 return get_must_expr;
2036 error() <<
"get_may expects two operands" <<
eom;
2047 return get_may_expr;
2054 error() <<
"invalid_pointer expects one operand" <<
eom;
2062 return same_object_expr;
2069 error() <<
"buffer_size expects one operand" <<
eom;
2077 return buffer_size_expr;
2084 error() <<
"is_zero_string expects one operand" <<
eom;
2090 is_zero_string_expr.
set(ID_C_lvalue,
true);
2093 return is_zero_string_expr;
2100 error() <<
"zero_string_length expects one operand" <<
eom;
2104 exprt zero_string_length_expr(
"zero_string_length",
size_type());
2106 zero_string_length_expr.
set(ID_C_lvalue,
true);
2109 return zero_string_length_expr;
2116 error() <<
"dynamic_object expects one argument" <<
eom;
2124 return dynamic_object_expr;
2131 error() <<
"pointer_offset expects one argument" <<
eom;
2138 if(expr.
type()!=pointer_offset_expr.
type())
2141 return pointer_offset_expr;
2148 error() <<
"pointer_object expects one argument" <<
eom;
2156 return pointer_object_expr;
2158 else if(identifier==
"__builtin_bswap16" ||
2159 identifier==
"__builtin_bswap32" ||
2160 identifier==
"__builtin_bswap64")
2167 error() << identifier <<
" expects one operand" <<
eom;
2171 exprt bswap_expr(ID_bswap, expr.
type());
2173 bswap_expr.add_source_location()=source_location;
2180 identifier==
"__builtin_isnan")
2185 error() <<
"isnan expects one operand" <<
eom;
2202 error() <<
"isfinite expects one operand" <<
eom;
2210 return isfinite_expr;
2213 identifier==
"__builtin_inf")
2250 error() <<
"abs-functions expect one operand" <<
eom;
2256 abs_expr.add_source_location()=source_location;
2265 error() <<
"malloc expects one operand" <<
eom;
2279 identifier==
"__builtin_isinf")
2284 error() <<
"isinf expects one operand" <<
eom;
2301 error() <<
"isnormal expects one operand" <<
eom;
2309 return isnormal_expr;
2314 identifier==
"__builtin_signbit" ||
2315 identifier==
"__builtin_signbitf" ||
2316 identifier==
"__builtin_signbitl")
2321 error() <<
"sign expects one operand" <<
eom;
2331 else if(identifier==
"__builtin_popcount" ||
2332 identifier==
"__builtin_popcountl" ||
2333 identifier==
"__builtin_popcountll" ||
2334 identifier==
"__popcnt16" ||
2335 identifier==
"__popcnt" ||
2336 identifier==
"__popcnt64")
2341 error() << identifier <<
" expects one operand" <<
eom;
2345 exprt popcount_expr(ID_popcount, expr.
type());
2347 popcount_expr.add_source_location()=source_location;
2349 return popcount_expr;
2356 error() <<
"equal expects two operands" <<
eom;
2365 equality_expr.
rhs().
type(), *
this))
2368 error() <<
"equal expects two operands of same type" <<
eom;
2372 return equality_expr;
2374 else if(identifier==
"__builtin_expect")
2385 error() <<
"__builtin_expect expects two arguments" <<
eom;
2391 else if(identifier==
"__builtin_object_size")
2400 error() <<
"__builtin_object_size expects two arguments" <<
eom;
2415 error() <<
"__builtin_object_size expects constant as second argument, " 2423 if(arg1==0 || arg1==1)
2436 else if(identifier==
"__builtin_choose_expr")
2442 error() <<
"__builtin_choose_expr expects three arguments" <<
eom;
2454 else if(identifier==
"__builtin_constant_p")
2461 error() <<
"__builtin_constant_p expects one argument" <<
eom;
2469 bool is_constant=
false;
2473 if(tmp1.
id()==ID_typecast &&
2475 tmp1.
op0().
id()==ID_address_of &&
2491 else if(identifier==
"__builtin_classify_type")
2498 error() <<
"__builtin_classify_type expects one argument" <<
eom;
2508 unsigned type_number=
2509 type.
id()==ID_empty?0:
2510 type.
id()==ID_c_enum_tag?3:
2511 (type.
id()==ID_bool || type.
id()==ID_c_bool)?4:
2512 type.
id()==ID_pointer?5:
2513 type.
id()==ID_floatbv?8:
2514 (type.
id()==ID_complex && type.
subtype().
id()==ID_floatbv)?9:
2515 type.
id()==ID_struct?12:
2516 type.
id()==ID_union?13:
2517 type.
id()==ID_array?14:
2534 error() <<
"float_debug expects two operands" <<
eom;
2540 "float_debug1":
"float_debug2";
2542 exprt float_debug_expr(
id, expr.
type());
2544 float_debug_expr.add_source_location()=source_location;
2546 return float_debug_expr;
2548 else if(identifier==
"__sync_fetch_and_add" ||
2549 identifier==
"__sync_fetch_and_sub" ||
2550 identifier==
"__sync_fetch_and_or" ||
2551 identifier==
"__sync_fetch_and_and" ||
2552 identifier==
"__sync_fetch_and_xor" ||
2553 identifier==
"__sync_fetch_and_nand" ||
2554 identifier==
"__sync_add_and_fetch" ||
2555 identifier==
"__sync_sub_and_fetch" ||
2556 identifier==
"__sync_or_and_fetch" ||
2557 identifier==
"__sync_and_and_fetch" ||
2558 identifier==
"__sync_xor_and_fetch" ||
2559 identifier==
"__sync_nand_and_fetch" ||
2560 identifier==
"__sync_val_compare_and_swap" ||
2561 identifier==
"__sync_lock_test_and_set" ||
2562 identifier==
"__sync_lock_release")
2571 error() <<
"__sync_* primitives take as least one argument" <<
eom;
2577 if(ptr_arg.
type().
id()!=ID_pointer)
2580 error() <<
"__sync_* primitives take pointer as first argument" <<
eom;
2605 if(code_type.
get_bool(ID_C_incomplete))
2609 else if(code_type.
is_KnR())
2614 while(parameter_types.size()>arguments.size())
2619 if(parameter_types.size()>arguments.size())
2622 error() <<
"not enough function arguments" <<
eom;
2626 else if(parameter_types.size()!=arguments.size())
2629 error() <<
"wrong number of function arguments: " 2630 <<
"expected " << parameter_types.size()
2631 <<
", but got " << arguments.size() <<
eom;
2635 for(
unsigned i=0; i<arguments.size(); i++)
2637 exprt &op=arguments[i];
2643 else if(i<parameter_types.size())
2648 const typet &op_type=parameter_type.
type();
2650 if(op_type.
id()==ID_bool &&
2651 op.
id()==ID_side_effect &&
2652 op.
get(ID_statement)==ID_assign &&
2656 warning() <<
"assignment where Boolean argument is expected" <<
eom;
2666 if(type.
id()==ID_array)
2669 dest_type.
subtype().
set(ID_C_constant, ID_1);
2686 error() <<
"operator `" << expr.
id()
2687 <<
"' expects one operand" <<
eom;
2695 if(o_type.
id()==ID_vector)
2714 error() <<
"operator `" << expr.
id()
2715 <<
"' not defined for type `" 2725 error() <<
"operator `" << expr.
id()
2726 <<
"' expects one operand" <<
eom;
2758 if((type0.
subtype().
id()==ID_signedbv ||
2774 error() <<
"operator `" << expr.
id()
2775 <<
"' expects two operands" <<
eom;
2785 if(o_type0.
id()==ID_vector &&
2786 o_type1.id()==ID_vector)
2793 if(o_type0!=o_type1)
2807 if(expr.
id()==ID_plus || expr.
id()==ID_minus ||
2808 expr.
id()==ID_mult || expr.
id()==ID_div)
2810 if(type0.
id()==ID_pointer || type1.id()==ID_pointer)
2815 else if(type0==type1)
2824 else if(expr.
id()==ID_mod)
2828 if(type0.
id()==ID_signedbv || type0.
id()==ID_unsignedbv)
2835 else if(expr.
id()==ID_bitand ||
2836 expr.
id()==ID_bitxor ||
2837 expr.
id()==ID_bitor)
2846 else if(type0.
id()==ID_bool)
2848 if(expr.
id()==ID_bitand)
2850 else if(expr.
id()==ID_bitor)
2852 else if(expr.
id()==ID_bitxor)
2863 error() <<
"operator `" << expr.
id()
2864 <<
"' not defined for types `" 2872 assert(expr.
id()==ID_shl || expr.
id()==ID_shr);
2880 if(o_type0.
id()==ID_vector &&
2881 o_type1.id()==ID_vector)
2889 expr.
type()=op0.type();
2894 if(o_type0.
id()==ID_vector &&
2899 expr.
type()=op0.type();
2910 expr.
type()=op0.type();
2912 if(expr.
id()==ID_shr)
2916 if(op0_type.
id()==ID_unsignedbv)
2921 else if(op0_type.
id()==ID_signedbv)
2932 error() <<
"operator `" << expr.
id()
2933 <<
"' not defined for types `" 2942 assert(type.
id()==ID_pointer);
2946 if(subtype.id()==ID_symbol)
2949 if(subtype.id()==ID_incomplete_struct)
2952 error() <<
"pointer arithmetic with unknown object size" <<
eom;
2967 if(expr.
id()==ID_minus ||
2968 (expr.
id()==ID_side_effect && expr.
get(ID_statement)==ID_assign_minus))
2970 if(type0.
id()==ID_pointer &&
2971 type1.id()==ID_pointer)
2981 if(type0.
id()==ID_pointer &&
2982 (type1.id()==ID_bool ||
2983 type1.id()==ID_c_bool ||
2984 type1.id()==ID_unsignedbv ||
2985 type1.id()==ID_signedbv ||
2986 type1.id()==ID_c_bit_field ||
2987 type1.id()==ID_c_enum_tag))
2995 else if(expr.
id()==ID_plus ||
2996 (expr.
id()==ID_side_effect && expr.
get(ID_statement)==ID_assign_plus))
2998 exprt *p_op, *int_op;
3000 if(type0.
id()==ID_pointer)
3005 else if(type1.id()==ID_pointer)
3012 p_op=int_op=
nullptr;
3018 if(int_op_type.
id()==ID_bool ||
3019 int_op_type.
id()==ID_c_bool ||
3020 int_op_type.
id()==ID_unsignedbv ||
3021 int_op_type.
id()==ID_signedbv ||
3022 int_op_type.
id()==ID_c_bit_field ||
3023 int_op_type.
id()==ID_c_enum_tag)
3034 if(expr.
id()==ID_side_effect)
3040 error() <<
"operator `" << op_name
3041 <<
"' not defined for types `" 3052 error() <<
"operator `" << expr.
id()
3053 <<
"' expects two operands" <<
eom;
3075 <<
"' expects two operands" <<
eom;
3087 if(type0.
id()==ID_empty)
3090 error() <<
"cannot assign void" <<
eom;
3098 <<
"' not an lvalue" <<
eom;
3106 <<
"' is constant" <<
eom;
3111 if(type0.
id()==ID_array ||
3112 type0.
id()==ID_incomplete_array)
3115 error() <<
"direct assignments to arrays not permitted" <<
eom;
3122 if(op0.
type().
id()==ID_c_bit_field)
3128 expr.
type()=o_type0;
3130 if(statement==ID_assign)
3135 else if(statement==ID_assign_shl ||
3136 statement==ID_assign_shr)
3142 if(statement==ID_assign_shl)
3152 if(underlying_type.
id()==ID_c_enum_tag)
3154 const typet &c_enum_type=
3156 underlying_type=c_enum_type.
subtype();
3159 if(underlying_type.
id()==ID_unsignedbv ||
3160 underlying_type.
id()==ID_c_bool)
3162 expr.
set(ID_statement, ID_assign_lshr);
3165 else if(underlying_type.
id()==ID_signedbv)
3167 expr.
set(ID_statement, ID_assign_ashr);
3173 else if(statement==ID_assign_bitxor ||
3174 statement==ID_assign_bitand ||
3175 statement==ID_assign_bitor)
3178 if(o_type0.
id()==ID_bool ||
3179 o_type0.
id()==ID_c_bool)
3182 if(op1.
type().
id()==ID_bool ||
3183 op1.
type().
id()==ID_c_bool ||
3184 op1.
type().
id()==ID_c_enum_tag ||
3185 op1.
type().
id()==ID_unsignedbv ||
3186 op1.
type().
id()==ID_signedbv)
3189 else if(o_type0.
id()==ID_c_enum_tag ||
3190 o_type0.
id()==ID_unsignedbv ||
3191 o_type0.
id()==ID_signedbv ||
3192 o_type0.
id()==ID_c_bit_field)
3197 else if(o_type0.
id()==ID_vector &&
3198 o_type1.
id()==ID_vector)
3204 if(o_type0!=o_type1)
3212 if(o_type0.
id()==ID_pointer &&
3213 (statement==ID_assign_minus || statement==ID_assign_plus))
3218 else if(o_type0.
id()==ID_vector &&
3219 o_type1.
id()==ID_vector)
3225 if(o_type0!=o_type1)
3230 else if(o_type0.
id()==ID_bool ||
3231 o_type0.
id()==ID_c_bool)
3234 if(op1.
type().
id()==ID_bool ||
3235 op1.
type().
id()==ID_c_bool ||
3236 op1.
type().
id()==ID_c_enum_tag ||
3237 op1.
type().
id()==ID_unsignedbv ||
3238 op1.
type().
id()==ID_signedbv)
3246 op1.
type().
id()==ID_bool ||
3247 op1.
type().
id()==ID_c_bool ||
3248 op1.
type().
id()==ID_c_enum_tag)
3254 error() <<
"assignment `" << statement
3255 <<
"' not defined for types `" 3268 expr.
id()!=ID_infinity)
3271 error() <<
"expected constant expression, but got `" 3284 expr.
id()!=ID_infinity)
3287 error() <<
"conversion to integer constant failed" <<
eom;
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.
std::map< irep_idt, source_locationt > labels_used
const typet & follow(const typet &src) const
virtual void typecheck_side_effect_assignment(side_effect_exprt &expr)
virtual void implicit_typecast_bool(exprt &expr)
virtual bool lookup(const irep_idt &name, const symbolt *&symbol) const
virtual bool is_complete_type(const typet &type) const
void typecheck_declaration(ansi_c_declarationt &)
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)
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)
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 union_typet & to_union_type(const typet &type)
Cast a generic typet to a union_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 shift_exprt & to_shift_expr(const exprt &expr)
Cast a generic exprt to a shift_exprt.
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.
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)
virtual void typecheck_side_effect_gcc_conditional_expression(side_effect_exprt &expr)
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a generic typet to a floatbv_typet.
exprt get_component_rec(const exprt &struct_union, const irep_idt &component_name, const namespacet &ns)
side_effect_exprt & to_side_effect_expr(exprt &expr)
static ieee_float_spect double_precision()
symbol_tablet & symbol_table
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a generic typet to a struct_union_typet.
const typet & follow_tag(const union_tag_typet &src) const
virtual void typecheck_expr_cw_va_arg_typeof(exprt &expr)
void follow_macros(exprt &expr) const
virtual void typecheck_expr_symbol(exprt &expr)
static bool is_numeric_type(const typet &src)
const irep_idt & id() const
exprt c_sizeof(const typet &src, const namespacet &ns)
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.
const c_enum_tag_typet & to_c_enum_tag_type(const typet &type)
Cast a generic typet to a c_enum_tag_typet.
ANSI-C Language Type Checking.
A declaration of a local variable.
virtual void typecheck_expr_member(exprt &expr)
const if_exprt & to_if_expr(const exprt &expr)
Cast a generic exprt to an if_exprt.
const source_locationt & find_source_location() const
source_locationt source_location
A constant-size array type.
virtual void make_index_type(exprt &expr)
virtual void typecheck_expr_binary_arithmetic(exprt &expr)
union constructor from single element
API to expression classes.
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
exprt c_offsetof(const struct_typet &src, const irep_idt &component_name, const namespacet &ns)
virtual void typecheck_expr(exprt &expr)
#define forall_operands(it, expr)
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 c_bit_field_typet & to_c_bit_field_type(const typet &type)
Cast a generic typet to a c_bit_field_typet.
bitvector_typet index_type()
#define Forall_irep(it, irep)
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.
bool move(symbolt &symbol, symbolt *&new_symbol)
Move a symbol into the symbol table.
virtual void typecheck_expr_function_identifier(exprt &expr)
std::vector< exprt > operandst
bool has_prefix(const std::string &s, const std::string &prefix)
const struct_typet & to_struct_type(const typet &type)
Cast a generic typet to a struct_typet.
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)
void follow_symbol(irept &irep) const
const irep_idt & get_access() const
Base type of C structs and unions, and C++ classes.
bool is_number(const typet &type)
void set_statement(const irep_idt &statement)
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 symbol_exprt & to_symbol_expr(const exprt &expr)
Cast a generic exprt to a symbol_exprt.
exprt pointer_offset(const exprt &pointer)
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()
const code_typet & to_code_type(const typet &type)
Cast a generic typet to a code_typet.
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)
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)
const binary_relation_exprt & to_binary_relation_expr(const exprt &expr)
Cast a generic exprt to a binary_relation_exprt.
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)
const constant_exprt & to_constant_expr(const exprt &expr)
Cast a generic exprt to a constant_exprt.
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 make_constant_rec(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)
const vector_typet & to_vector_type(const typet &type)
Cast a generic typet to a vector_typet.
void make_typecast(const typet &_type)
const irept & find(const irep_namet &name) const
A base class for shift operators.
const typet & return_type() const
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 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.
#define forall_irep(it, irep)
C Language Type Checking.
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a generic typet to a bitvector_typet.
virtual void adjust_float_rel(exprt &expr)