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"
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)
625 symbol_table.
add(symbol);
632 const irep_idt &identifier_with_type,
635 const std::vector<symbol_exprt> ¶meter_exprs,
644 result_symbol(identifier_with_type, type, source_location, symbol_table)
661 irep_idt op_id = identifier == ID___atomic_fetch_add
663 : identifier == ID___atomic_fetch_sub
665 : identifier == ID___atomic_fetch_or
667 : identifier == ID___atomic_fetch_and
669 : identifier == ID___atomic_fetch_xor
671 : identifier == ID___atomic_fetch_nand
674 binary_exprt op_expr{result, op_id, parameter_exprs[1], type};
679 {parameter_exprs[2]},
694 const irep_idt &identifier_with_type,
697 const std::vector<symbol_exprt> ¶meter_exprs,
706 result_symbol(identifier_with_type, type, source_location, symbol_table)
721 irep_idt op_id = identifier == ID___atomic_add_fetch
723 : identifier == ID___atomic_sub_fetch
725 : identifier == ID___atomic_or_fetch
727 : identifier == ID___atomic_and_fetch
729 : identifier == ID___atomic_xor_fetch
731 : identifier == ID___atomic_nand_fetch
734 binary_exprt op_expr{deref_ptr, op_id, parameter_exprs[1], type};
742 {parameter_exprs[2]},
757 const irep_idt &identifier_with_type,
760 const std::vector<symbol_exprt> ¶meter_exprs,
764 std::string atomic_name =
"__atomic_" +
id2string(identifier).substr(7);
765 atomic_name.replace(atomic_name.find(
"_and_"), 5,
"_");
774 std::move(arguments),
780 const irep_idt &identifier_with_type,
783 const std::vector<symbol_exprt> ¶meter_exprs,
807 const irep_idt &identifier_with_type,
810 const std::vector<symbol_exprt> ¶meter_exprs,
819 result_symbol(identifier_with_type, type, source_location, symbol_table)
857 const irep_idt &identifier_with_type,
860 const std::vector<symbol_exprt> ¶meter_exprs,
877 result_symbol(identifier_with_type, type, source_location, symbol_table)
913 const irep_idt &identifier_with_type,
916 const std::vector<symbol_exprt> ¶meter_exprs,
953 const irep_idt &identifier_with_type,
956 const std::vector<symbol_exprt> ¶meter_exprs,
974 {parameter_exprs[2]},
986 const irep_idt &identifier_with_type,
989 const std::vector<symbol_exprt> ¶meter_exprs,
999 result_symbol(identifier_with_type, type, source_location, symbol_table)
1013 const irep_idt &identifier_with_type,
1016 const std::vector<symbol_exprt> ¶meter_exprs,
1034 {parameter_exprs[2]},
1046 const irep_idt &identifier_with_type,
1049 const std::vector<symbol_exprt> ¶meter_exprs,
1058 {parameter_exprs[0],
1060 parameter_exprs[2]},
1066 const irep_idt &identifier_with_type,
1069 const std::vector<symbol_exprt> ¶meter_exprs,
1089 {parameter_exprs[3]},
1101 const irep_idt &identifier_with_type,
1104 const std::vector<symbol_exprt> ¶meter_exprs,
1114 result_symbol(identifier_with_type, type, source_location, symbol_table)
1120 {parameter_exprs[0],
1123 parameter_exprs[2]},
1131 const irep_idt &identifier_with_type,
1134 const std::vector<symbol_exprt> ¶meter_exprs,
1151 identifier_with_type,
c_bool_type(), source_location, symbol_table)
1177 {parameter_exprs[4]},
1180 success_fence.add_source_location() = source_location;
1187 {parameter_exprs[5]},
1190 failure_fence.add_source_location() = source_location;
1194 code_blockt{{std::move(assign), std::move(success_fence)}},
1195 code_blockt{{std::move(assign_not_equal), std::move(failure_fence)}}});
1207 const irep_idt &identifier_with_type,
1210 const std::vector<symbol_exprt> ¶meter_exprs,
1218 {parameter_exprs[0],
1223 parameter_exprs[5]},
1236 std::vector<symbol_exprt> parameter_exprs;
1237 parameter_exprs.reserve(code_type.
parameters().size());
1238 for(
const auto ¶meter : code_type.
parameters())
1246 identifier == ID___atomic_fetch_add ||
1247 identifier == ID___atomic_fetch_sub || identifier == ID___atomic_fetch_or ||
1248 identifier == ID___atomic_fetch_and ||
1249 identifier == ID___atomic_fetch_xor || identifier == ID___atomic_fetch_nand)
1253 identifier_with_type,
1261 identifier == ID___atomic_add_fetch ||
1262 identifier == ID___atomic_sub_fetch || identifier == ID___atomic_or_fetch ||
1263 identifier == ID___atomic_and_fetch ||
1264 identifier == ID___atomic_xor_fetch || identifier == ID___atomic_nand_fetch)
1268 identifier_with_type,
1276 identifier == ID___sync_fetch_and_add ||
1277 identifier == ID___sync_fetch_and_sub ||
1278 identifier == ID___sync_fetch_and_or ||
1279 identifier == ID___sync_fetch_and_and ||
1280 identifier == ID___sync_fetch_and_xor ||
1281 identifier == ID___sync_fetch_and_nand ||
1282 identifier == ID___sync_add_and_fetch ||
1283 identifier == ID___sync_sub_and_fetch ||
1284 identifier == ID___sync_or_and_fetch ||
1285 identifier == ID___sync_and_and_fetch ||
1286 identifier == ID___sync_xor_and_fetch ||
1287 identifier == ID___sync_nand_and_fetch)
1291 identifier_with_type,
1297 else if(identifier == ID___sync_bool_compare_and_swap)
1300 identifier_with_type, code_type, source_location, parameter_exprs, block);
1302 else if(identifier == ID___sync_val_compare_and_swap)
1305 identifier_with_type,
1312 else if(identifier == ID___sync_lock_test_and_set)
1315 identifier_with_type,
1322 else if(identifier == ID___sync_lock_release)
1325 identifier_with_type, code_type, source_location, parameter_exprs, block);
1327 else if(identifier == ID___atomic_load)
1330 identifier_with_type, code_type, source_location, parameter_exprs, block);
1332 else if(identifier == ID___atomic_load_n)
1335 identifier_with_type,
1342 else if(identifier == ID___atomic_store)
1345 identifier_with_type, code_type, source_location, parameter_exprs, block);
1347 else if(identifier == ID___atomic_store_n)
1350 identifier_with_type, code_type, source_location, parameter_exprs, block);
1352 else if(identifier == ID___atomic_exchange)
1355 identifier_with_type, code_type, source_location, parameter_exprs, block);
1357 else if(identifier == ID___atomic_exchange_n)
1360 identifier_with_type,
1367 else if(identifier == ID___atomic_compare_exchange)
1370 identifier_with_type,
1377 else if(identifier == ID___atomic_compare_exchange_n)
1380 identifier_with_type, code_type, source_location, parameter_exprs, block);
1388 statement.add_source_location() = source_location;
1402 if(identifier ==
"__builtin_shuffle")
1406 if(arguments.size() != 2 && arguments.size() != 3)
1409 error() <<
"__builtin_shuffle expects two or three arguments" <<
eom;
1413 for(
exprt &arg : arguments)
1415 if(arg.type().id() != ID_vector)
1418 error() <<
"__builtin_shuffle expects vector arguments" <<
eom;
1423 const exprt &arg0 = arguments[0];
1427 if(arguments.size() == 3)
1429 if(arguments[1].type() != input_vec_type)
1432 error() <<
"__builtin_shuffle expects input vectors of the same type"
1436 arg1 = arguments[1];
1438 const exprt &indices = arguments.back();
1440 const std::size_t indices_size =
1441 numeric_cast_v<std::size_t>(indices_type.
size());
1444 operands.reserve(indices_size);
1446 auto input_size = numeric_cast<mp_integer>(input_vec_type.
size());
1448 if(arg1.has_value())
1449 input_size = *input_size * 2;
1453 for(std::size_t i = 0; i < indices_size; ++i)
1459 operands.push_back(std::move(mod_index));
1464 else if(identifier ==
"__builtin_shufflevector")
1467 if(arguments.size() < 2)
1470 error() <<
"__builtin_shufflevector expects two or more arguments" <<
eom;
1475 operands.reserve(arguments.size() - 2);
1477 for(std::size_t i = 0; i < arguments.size(); ++i)
1479 exprt &arg_i = arguments[i];
1481 if(i <= 1 && arg_i.
type().
id() != ID_vector)
1484 error() <<
"__builtin_shufflevector expects two vectors as argument"
1493 error() <<
"__builtin_shufflevector expects integer index" <<
eom;
1499 const auto int_index = numeric_cast<mp_integer>(arg_i);
1502 if(*int_index == -1)
1505 operands.back().add_source_location() = source_location;
1508 operands.push_back(arg_i);
void base_type(typet &type, const namespacet &ns)
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(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_tablet &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 symbolt result_symbol(const irep_idt &identifier, const typet &type, const source_locationt &source_location, symbol_tablet &symbol_table)
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_tablet &symbol_table, code_blockt &block)
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_tablet &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_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 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_tablet &symbol_table, code_blockt &block)
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_tablet &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_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_tablet &symbol_table, 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_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_tablet &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.
virtual void make_constant(exprt &expr)
symbol_tablet & symbol_table
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.
void add(const codet &code)
code_operandst & statements()
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.
codet representation of a "return from a function" statement.
std::vector< parametert > parameterst
const typet & return_type() const
const parameterst & parameters() 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
source_locationt & add_source_location()
const source_locationt & source_location() const
typet & type()
Return the type of the expression.
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)).
const symbolt & lookup(const irep_idt &name) const
Lookup a symbol in the namespace.
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.
vector_exprt lower() const
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
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
irep_idt base_name
Base (non-scoped) name.
source_locationt location
Source code location of definition of symbol.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
irep_idt name
The unique identifier.
irep_idt mode
Language mode.
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.