36 if(arguments.size() < 2)
39 log.
error() << identifier <<
" expects at least two arguments"
44 const exprt &ptr_arg = arguments.front();
46 if(ptr_arg.
type().
id() != ID_pointer)
49 log.
error() << identifier <<
" takes a pointer as first argument"
61 result.add_source_location() = source_location;
75 if(arguments.size() < 3)
78 log.
error() << identifier <<
" expects at least three arguments"
83 const exprt &ptr_arg = arguments.front();
85 if(ptr_arg.
type().
id() != ID_pointer)
88 log.
error() << identifier <<
" takes a pointer as first argument"
94 typet sync_return_type = base_type;
95 if(identifier == ID___sync_bool_compare_and_swap)
104 result.add_source_location() = source_location;
118 if(arguments.empty())
121 log.
error() << identifier <<
" expects at least one argument"
126 const exprt &ptr_arg = arguments.front();
128 if(ptr_arg.
type().
id() != ID_pointer)
131 log.
error() << identifier <<
" takes a pointer as first argument"
139 result.add_source_location() = source_location;
153 if(arguments.size() != 2)
160 const exprt &ptr_arg = arguments.front();
162 if(ptr_arg.
type().
id() != ID_pointer)
165 log.
error() << identifier <<
" takes a pointer as first argument"
175 result.add_source_location() = source_location;
188 if(arguments.size() != 3)
195 const exprt &ptr_arg = arguments.front();
197 if(ptr_arg.
type().
id() != ID_pointer)
200 log.
error() << identifier <<
" takes a pointer as first argument"
213 result.add_source_location() = source_location;
226 if(arguments.size() != 3)
233 const exprt &ptr_arg = arguments.front();
235 if(ptr_arg.
type().
id() != ID_pointer)
238 log.
error() << identifier <<
" takes a pointer as first argument"
251 result.add_source_location() = source_location;
265 if(arguments.size() != 3)
272 if(arguments[0].type().
id() != ID_pointer)
275 log.
error() << identifier <<
" takes a pointer as first argument"
280 if(arguments[1].type().
id() != ID_pointer)
283 log.
error() << identifier <<
" takes a pointer as second argument"
288 const exprt &ptr_arg = arguments.front();
296 result.add_source_location() = source_location;
309 if(arguments.size() != 4)
316 if(arguments[0].type().
id() != ID_pointer)
319 log.
error() << identifier <<
" takes a pointer as first argument"
324 if(arguments[1].type().
id() != ID_pointer)
327 log.
error() << identifier <<
" takes a pointer as second argument"
332 if(arguments[2].type().
id() != ID_pointer)
335 log.
error() << identifier <<
" takes a pointer as third argument"
340 const exprt &ptr_arg = arguments.front();
349 result.add_source_location() = source_location;
365 if(arguments.size() != 6)
372 if(arguments[0].type().
id() != ID_pointer)
375 log.
error() << identifier <<
" takes a pointer as first argument"
380 if(arguments[1].type().
id() != ID_pointer)
383 log.
error() << identifier <<
" takes a pointer as second argument"
389 identifier == ID___atomic_compare_exchange &&
390 arguments[2].type().
id() != ID_pointer)
393 log.
error() << identifier <<
" takes a pointer as third argument"
398 const exprt &ptr_arg = arguments.front();
404 if(identifier == ID___atomic_compare_exchange)
407 parameters.push_back(
427 if(arguments.size() != 3)
430 log.
error() <<
"__atomic_*_fetch primitives take three arguments"
435 const exprt &ptr_arg = arguments.front();
437 if(ptr_arg.
type().
id() != ID_pointer)
441 <<
"__atomic_*_fetch primitives take a pointer as first argument"
452 result.add_source_location() = source_location;
464 if(arguments.size() != 3)
467 log.
error() <<
"__atomic_fetch_* primitives take three arguments"
472 const exprt &ptr_arg = arguments.front();
474 if(ptr_arg.
type().
id() != ID_pointer)
478 <<
"__atomic_fetch_* primitives take a pointer as first argument"
489 result.add_source_location() = source_location;
502 identifier == ID___sync_fetch_and_add ||
503 identifier == ID___sync_fetch_and_sub ||
504 identifier == ID___sync_fetch_and_or ||
505 identifier == ID___sync_fetch_and_and ||
506 identifier == ID___sync_fetch_and_xor ||
507 identifier == ID___sync_fetch_and_nand ||
508 identifier == ID___sync_add_and_fetch ||
509 identifier == ID___sync_sub_and_fetch ||
510 identifier == ID___sync_or_and_fetch ||
511 identifier == ID___sync_and_and_fetch ||
512 identifier == ID___sync_xor_and_fetch ||
513 identifier == ID___sync_nand_and_fetch ||
514 identifier == ID___sync_lock_test_and_set)
522 identifier == ID___sync_bool_compare_and_swap ||
523 identifier == ID___sync_val_compare_and_swap)
530 else if(identifier == ID___sync_lock_release)
537 else if(identifier == ID___atomic_load_n)
544 else if(identifier == ID___atomic_store_n)
551 else if(identifier == ID___atomic_exchange_n)
558 else if(identifier == ID___atomic_load || identifier == ID___atomic_store)
565 else if(identifier == ID___atomic_exchange)
573 identifier == ID___atomic_compare_exchange_n ||
574 identifier == ID___atomic_compare_exchange)
582 identifier == ID___atomic_add_fetch ||
583 identifier == ID___atomic_sub_fetch ||
584 identifier == ID___atomic_and_fetch ||
585 identifier == ID___atomic_xor_fetch || identifier == ID___atomic_or_fetch ||
586 identifier == ID___atomic_nand_fetch)
594 identifier == ID___atomic_fetch_add ||
595 identifier == ID___atomic_fetch_sub ||
596 identifier == ID___atomic_fetch_and ||
597 identifier == ID___atomic_fetch_xor || identifier == ID___atomic_fetch_or ||
598 identifier == ID___atomic_fetch_nand)
616 symbol.base_name =
"result";
617 symbol.location = source_location;
618 symbol.is_file_local =
true;
619 symbol.is_lvalue =
true;
620 symbol.is_thread_local =
true;
622 symbol_table.
add(symbol);
629 const irep_idt &identifier_with_type,
632 const std::vector<symbol_exprt> ¶meter_exprs,
641 result_symbol(identifier_with_type, type, source_location, symbol_table)
658 irep_idt op_id = identifier == ID___atomic_fetch_add
660 : identifier == ID___atomic_fetch_sub
662 : identifier == ID___atomic_fetch_or
664 : identifier == ID___atomic_fetch_and
666 : identifier == ID___atomic_fetch_xor
668 : identifier == ID___atomic_fetch_nand
671 binary_exprt op_expr{result, op_id, parameter_exprs[1], type};
676 {parameter_exprs[2]},
691 const irep_idt &identifier_with_type,
694 const std::vector<symbol_exprt> ¶meter_exprs,
703 result_symbol(identifier_with_type, type, source_location, symbol_table)
718 irep_idt op_id = identifier == ID___atomic_add_fetch
720 : identifier == ID___atomic_sub_fetch
722 : identifier == ID___atomic_or_fetch
724 : identifier == ID___atomic_and_fetch
726 : identifier == ID___atomic_xor_fetch
728 : identifier == ID___atomic_nand_fetch
731 binary_exprt op_expr{deref_ptr, op_id, parameter_exprs[1], type};
739 {parameter_exprs[2]},
754 const irep_idt &identifier_with_type,
757 const std::vector<symbol_exprt> ¶meter_exprs,
761 std::string atomic_name =
"__atomic_" +
id2string(identifier).substr(7);
762 atomic_name.replace(atomic_name.find(
"_and_"), 5,
"_");
771 std::move(arguments),
777 const irep_idt &identifier_with_type,
780 const std::vector<symbol_exprt> ¶meter_exprs,
804 const irep_idt &identifier_with_type,
807 const std::vector<symbol_exprt> ¶meter_exprs,
816 result_symbol(identifier_with_type, type, source_location, symbol_table)
833 assign.add_source_location() = source_location;
854 const irep_idt &identifier_with_type,
857 const std::vector<symbol_exprt> ¶meter_exprs,
874 result_symbol(identifier_with_type, type, source_location, symbol_table)
910 const irep_idt &identifier_with_type,
913 const std::vector<symbol_exprt> ¶meter_exprs,
950 const irep_idt &identifier_with_type,
953 const std::vector<symbol_exprt> ¶meter_exprs,
971 {parameter_exprs[2]},
983 const irep_idt &identifier_with_type,
986 const std::vector<symbol_exprt> ¶meter_exprs,
996 result_symbol(identifier_with_type, type, source_location, symbol_table)
1010 const irep_idt &identifier_with_type,
1013 const std::vector<symbol_exprt> ¶meter_exprs,
1031 {parameter_exprs[2]},
1043 const irep_idt &identifier_with_type,
1046 const std::vector<symbol_exprt> ¶meter_exprs,
1055 {parameter_exprs[0],
1057 parameter_exprs[2]},
1063 const irep_idt &identifier_with_type,
1066 const std::vector<symbol_exprt> ¶meter_exprs,
1086 {parameter_exprs[3]},
1098 const irep_idt &identifier_with_type,
1101 const std::vector<symbol_exprt> ¶meter_exprs,
1111 result_symbol(identifier_with_type, type, source_location, symbol_table)
1117 {parameter_exprs[0],
1120 parameter_exprs[2]},
1128 const irep_idt &identifier_with_type,
1131 const std::vector<symbol_exprt> ¶meter_exprs,
1148 identifier_with_type,
c_bool_type(), source_location, symbol_table)
1171 assign.add_source_location() = source_location;
1174 {parameter_exprs[4]},
1177 success_fence.add_source_location() = source_location;
1181 assign_not_equal.add_source_location() = source_location;
1184 {parameter_exprs[5]},
1187 failure_fence.add_source_location() = source_location;
1191 code_blockt{{std::move(assign), std::move(success_fence)}},
1192 code_blockt{{std::move(assign_not_equal), std::move(failure_fence)}}});
1204 const irep_idt &identifier_with_type,
1207 const std::vector<symbol_exprt> ¶meter_exprs,
1215 {parameter_exprs[0],
1220 parameter_exprs[5]},
1233 std::vector<symbol_exprt> parameter_exprs;
1234 parameter_exprs.reserve(code_type.
parameters().size());
1235 for(
const auto ¶meter : code_type.
parameters())
1237 parameter_exprs.push_back(
lookup(parameter.get_identifier()).symbol_expr());
1243 identifier == ID___atomic_fetch_add ||
1244 identifier == ID___atomic_fetch_sub || identifier == ID___atomic_fetch_or ||
1245 identifier == ID___atomic_fetch_and ||
1246 identifier == ID___atomic_fetch_xor || identifier == ID___atomic_fetch_nand)
1250 identifier_with_type,
1258 identifier == ID___atomic_add_fetch ||
1259 identifier == ID___atomic_sub_fetch || identifier == ID___atomic_or_fetch ||
1260 identifier == ID___atomic_and_fetch ||
1261 identifier == ID___atomic_xor_fetch || identifier == ID___atomic_nand_fetch)
1265 identifier_with_type,
1273 identifier == ID___sync_fetch_and_add ||
1274 identifier == ID___sync_fetch_and_sub ||
1275 identifier == ID___sync_fetch_and_or ||
1276 identifier == ID___sync_fetch_and_and ||
1277 identifier == ID___sync_fetch_and_xor ||
1278 identifier == ID___sync_fetch_and_nand ||
1279 identifier == ID___sync_add_and_fetch ||
1280 identifier == ID___sync_sub_and_fetch ||
1281 identifier == ID___sync_or_and_fetch ||
1282 identifier == ID___sync_and_and_fetch ||
1283 identifier == ID___sync_xor_and_fetch ||
1284 identifier == ID___sync_nand_and_fetch)
1288 identifier_with_type,
1294 else if(identifier == ID___sync_bool_compare_and_swap)
1297 identifier_with_type, code_type, source_location, parameter_exprs, block);
1299 else if(identifier == ID___sync_val_compare_and_swap)
1302 identifier_with_type,
1309 else if(identifier == ID___sync_lock_test_and_set)
1312 identifier_with_type,
1319 else if(identifier == ID___sync_lock_release)
1322 identifier_with_type, code_type, source_location, parameter_exprs, block);
1324 else if(identifier == ID___atomic_load)
1327 identifier_with_type, code_type, source_location, parameter_exprs, block);
1329 else if(identifier == ID___atomic_load_n)
1332 identifier_with_type,
1339 else if(identifier == ID___atomic_store)
1342 identifier_with_type, code_type, source_location, parameter_exprs, block);
1344 else if(identifier == ID___atomic_store_n)
1347 identifier_with_type, code_type, source_location, parameter_exprs, block);
1349 else if(identifier == ID___atomic_exchange)
1352 identifier_with_type, code_type, source_location, parameter_exprs, block);
1354 else if(identifier == ID___atomic_exchange_n)
1357 identifier_with_type,
1364 else if(identifier == ID___atomic_compare_exchange)
1367 identifier_with_type,
1374 else if(identifier == ID___atomic_compare_exchange_n)
1377 identifier_with_type, code_type, source_location, parameter_exprs, block);
1385 statement.add_source_location() = source_location;
1399 if(identifier ==
"__builtin_shuffle")
1403 if(arguments.size() != 2 && arguments.size() != 3)
1406 error() <<
"__builtin_shuffle expects two or three arguments" <<
eom;
1410 for(
exprt &arg : arguments)
1412 if(arg.type().id() != ID_vector)
1415 error() <<
"__builtin_shuffle expects vector arguments" <<
eom;
1420 const exprt &arg0 = arguments[0];
1424 if(arguments.size() == 3)
1426 if(arguments[1].type() != input_vec_type)
1429 error() <<
"__builtin_shuffle expects input vectors of the same type"
1433 arg1 = arguments[1];
1435 const exprt &indices = arguments.back();
1437 const std::size_t indices_size =
1441 operands.reserve(indices_size);
1445 if(arg1.has_value())
1446 input_size = *input_size * 2;
1450 for(std::size_t i = 0; i < indices_size; ++i)
1456 operands.push_back(std::move(mod_index));
1461 else if(identifier ==
"__builtin_shufflevector")
1464 if(arguments.size() < 2)
1467 error() <<
"__builtin_shufflevector expects two or more arguments" <<
eom;
1472 operands.reserve(arguments.size() - 2);
1474 for(std::size_t i = 0; i < arguments.size(); ++i)
1476 exprt &arg_i = arguments[i];
1478 if(i <= 1 && arg_i.
type().
id() != ID_vector)
1481 error() <<
"__builtin_shufflevector expects two vectors as argument"
1490 error() <<
"__builtin_shufflevector expects integer index" <<
eom;
1499 if(*int_index == -1)
1502 operands.back().add_source_location() = source_location;
1505 operands.push_back(arg_i);
1510 arguments[0], arguments[1], std::move(operands)};
bool is_signed_or_unsigned_bitvector(const typet &type)
This method tests, if the given typet is a signed or unsigned bitvector.
API to expression classes that are internal to the C frontend.
ANSI-C Language Type Checking.
static void instantiate_atomic_exchange_n(const irep_idt &identifier_with_type, const code_typet &code_type, const source_locationt &source_location, const std::vector< symbol_exprt > ¶meter_exprs, symbol_table_baset &symbol_table, code_blockt &block)
static void instantiate_atomic_exchange(const irep_idt &identifier_with_type, const code_typet &code_type, const source_locationt &source_location, const std::vector< symbol_exprt > ¶meter_exprs, code_blockt &block)
static symbol_exprt typecheck_atomic_fetch_op(const irep_idt &identifier, const exprt::operandst &arguments, const source_locationt &source_location, message_handlert &message_handler)
static void instantiate_atomic_op_fetch(const irep_idt &identifier, const irep_idt &identifier_with_type, const code_typet &code_type, const source_locationt &source_location, const std::vector< symbol_exprt > ¶meter_exprs, symbol_table_baset &symbol_table, code_blockt &block)
static void instantiate_atomic_load(const irep_idt &identifier_with_type, const code_typet &code_type, const source_locationt &source_location, const std::vector< symbol_exprt > ¶meter_exprs, code_blockt &block)
static symbol_exprt typecheck_atomic_compare_exchange(const irep_idt &identifier, const exprt::operandst &arguments, const source_locationt &source_location, message_handlert &message_handler)
static void instantiate_sync_lock_test_and_set(const irep_idt &identifier_with_type, const code_typet &code_type, const source_locationt &source_location, const std::vector< symbol_exprt > ¶meter_exprs, symbol_table_baset &symbol_table, code_blockt &block)
static symbol_exprt typecheck_sync_with_pointer_parameter(const irep_idt &identifier, const exprt::operandst &arguments, const source_locationt &source_location, message_handlert &message_handler)
static void instantiate_atomic_store(const irep_idt &identifier_with_type, const code_typet &code_type, const source_locationt &source_location, const std::vector< symbol_exprt > ¶meter_exprs, code_blockt &block)
static void instantiate_atomic_load_n(const irep_idt &identifier_with_type, const code_typet &code_type, const source_locationt &source_location, const std::vector< symbol_exprt > ¶meter_exprs, symbol_table_baset &symbol_table, code_blockt &block)
static void instantiate_atomic_compare_exchange_n(const irep_idt &identifier_with_type, const code_typet &code_type, const source_locationt &source_location, const std::vector< symbol_exprt > ¶meter_exprs, code_blockt &block)
static symbol_exprt typecheck_atomic_exchange(const irep_idt &identifier, const exprt::operandst &arguments, const source_locationt &source_location, message_handlert &message_handler)
static symbolt result_symbol(const irep_idt &identifier, const typet &type, const source_locationt &source_location, symbol_table_baset &symbol_table)
static void instantiate_sync_val_compare_and_swap(const irep_idt &identifier_with_type, const code_typet &code_type, const source_locationt &source_location, const std::vector< symbol_exprt > ¶meter_exprs, symbol_table_baset &symbol_table, code_blockt &block)
static void instantiate_atomic_compare_exchange(const irep_idt &identifier_with_type, const code_typet &code_type, const source_locationt &source_location, const std::vector< symbol_exprt > ¶meter_exprs, symbol_table_baset &symbol_table, code_blockt &block)
static symbol_exprt typecheck_atomic_op_fetch(const irep_idt &identifier, const exprt::operandst &arguments, const source_locationt &source_location, message_handlert &message_handler)
static symbol_exprt typecheck_atomic_store_n(const irep_idt &identifier, const exprt::operandst &arguments, const source_locationt &source_location, message_handlert &message_handler)
static void instantiate_sync_bool_compare_and_swap(const irep_idt &identifier_with_type, const code_typet &code_type, const source_locationt &source_location, const std::vector< symbol_exprt > ¶meter_exprs, code_blockt &block)
static symbol_exprt typecheck_sync_lock_release(const irep_idt &identifier, const exprt::operandst &arguments, const source_locationt &source_location, message_handlert &message_handler)
static symbol_exprt typecheck_atomic_load_n(const irep_idt &identifier, const exprt::operandst &arguments, const source_locationt &source_location, message_handlert &message_handler)
static symbol_exprt typecheck_atomic_exchange_n(const irep_idt &identifier, const exprt::operandst &arguments, const source_locationt &source_location, message_handlert &message_handler)
static void instantiate_sync_lock_release(const irep_idt &identifier_with_type, const code_typet &code_type, const source_locationt &source_location, const std::vector< symbol_exprt > ¶meter_exprs, code_blockt &block)
static void instantiate_sync_fetch(const irep_idt &identifier, const irep_idt &identifier_with_type, const code_typet &code_type, const source_locationt &source_location, const std::vector< symbol_exprt > ¶meter_exprs, code_blockt &block)
static void instantiate_atomic_store_n(const irep_idt &identifier_with_type, const code_typet &code_type, const source_locationt &source_location, const std::vector< symbol_exprt > ¶meter_exprs, code_blockt &block)
static symbol_exprt typecheck_sync_compare_swap(const irep_idt &identifier, const exprt::operandst &arguments, const source_locationt &source_location, message_handlert &message_handler)
static void instantiate_atomic_fetch_op(const irep_idt &identifier, const irep_idt &identifier_with_type, const code_typet &code_type, const source_locationt &source_location, const std::vector< symbol_exprt > ¶meter_exprs, symbol_table_baset &symbol_table, code_blockt &block)
static symbol_exprt typecheck_atomic_load_store(const irep_idt &identifier, const exprt::operandst &arguments, const source_locationt &source_location, message_handlert &message_handler)
signedbv_typet signed_int_type()
pointer_typet pointer_type(const typet &subtype)
bitvector_typet c_index_type()
Operator to return the address of an object.
A base class for binary expressions.
symbol_table_baset & symbol_table
virtual void make_constant(exprt &expr)
virtual code_blockt instantiate_gcc_polymorphic_builtin(const irep_idt &identifier, const symbol_exprt &function_symbol)
virtual optionalt< symbol_exprt > typecheck_gcc_polymorphic_builtin(const irep_idt &identifier, const exprt::operandst &arguments, const source_locationt &source_location)
virtual exprt typecheck_shuffle_vector(const side_effect_expr_function_callt &expr)
A codet representing sequential composition of program statements.
code_operandst & statements()
void add(const codet &code)
codet representation of an expression statement.
A codet representing an assignment in the program.
A codet representing the declaration of a local variable.
codet representation of an if-then-else statement.
goto_instruction_codet representation of a "return from afunction" statement.
std::vector< parametert > parameterst
const parameterst & parameters() const
const typet & return_type() const
Data structure for representing an arbitrary statement in a program.
A constant literal expression.
Operator to dereference a pointer.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
std::vector< exprt > operandst
typet & type()
Return the type of the expression.
const source_locationt & source_location() const
source_locationt & add_source_location()
const irep_idt & id() const
source_locationt source_location
Class that provides messages with a built-in verbosity 'level'.
message_handlert & get_message_handler()
Modulo defined as lhs-(rhs * truncate(lhs/rhs)).
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
const typet & base_type() const
The type of the data what we point to.
Shuffle elements of one or two vectors, modelled after Clang's __builtin_shufflevector.
A side_effect_exprt representation of a function call side effect.
exprt::operandst & arguments()
Expression to hold a symbol (variable)
static symbol_exprt typeless(const irep_idt &id)
Generate a symbol_exprt without a proper type.
const irep_idt & get_identifier() const
The symbol table base class interface.
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
const constant_exprt & size() const
const typet & element_type() const
The type of the elements of the vector.
const std::string & id2string(const irep_idt &d)
nonstd::optional< T > optionalt
API to expression classes for Pointers.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
#define CHECK_RETURN(CONDITION)
#define UNREACHABLE
This should be used to mark dead code.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const vector_typet & to_vector_type(const typet &type)
Cast a typet to a vector_typet.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.