Skip to content

Commit 8f8cda4

Browse files
marek-trtiktautschnig
authored andcommitted
Fixing issue 'implicit conversion not permitted' for alias variables.
There are several SV-COMP benchmarks where is used and alias variable with a global array variable. The alias varialbe is not array ariable and it wants to alias with the array, i.e. with the first element in the array. This commit prevents the type mismatch.
1 parent a695814 commit 8f8cda4

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/ansi-c/c_typecast.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,23 @@ void c_typecastt::implicit_typecast(
456456
implicit_typecast_followed(expr, src_type, type_qual, dest_type);
457457
}
458458

459+
static bool is_array_element_alias(const namespacet& ns, const symbolt* const orig_symbol, const typet &src_type, const typet &dest_type)
460+
{
461+
if(orig_symbol==nullptr)
462+
return false;
463+
const symbolt* aliased_symbol;
464+
if(ns.lookup(orig_symbol->name, aliased_symbol))
465+
return false;
466+
if(!aliased_symbol->is_macro)
467+
return false;
468+
if(src_type.id()!=ID_array)
469+
return false;
470+
const typet &src_subtype=ns.follow(src_type.subtype());
471+
if(src_subtype!=dest_type)
472+
return false;
473+
return true;
474+
}
475+
459476
void c_typecastt::implicit_typecast_followed(
460477
exprt &expr,
461478
const typet &src_type,
@@ -569,7 +586,7 @@ void c_typecastt::implicit_typecast_followed(
569586
}
570587
}
571588

572-
if(check_c_implicit_typecast(src_type, dest_type))
589+
if(check_c_implicit_typecast(src_type, dest_type) && !is_array_element_alias(ns, get_current_symbol(), src_type, dest_type))
573590
errors.push_back("implicit conversion not permitted");
574591
else if(src_type!=dest_type)
575592
do_typecast(expr, orig_dest_type);

src/ansi-c/c_typecast.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ bool c_implicit_typecast_arithmetic(
4141
class c_typecastt
4242
{
4343
public:
44-
explicit c_typecastt(const namespacet &_ns):ns(_ns)
44+
explicit c_typecastt(const namespacet &_ns):ns(_ns), current_symbol(nullptr)
4545
{
4646
}
4747

@@ -63,6 +63,9 @@ class c_typecastt
6363
std::list<std::string> errors;
6464
std::list<std::string> warnings;
6565

66+
void set_current_symbol(const symbolt * const symbol) { current_symbol=symbol; }
67+
const symbolt *get_current_symbol() const { return current_symbol; }
68+
6669
protected:
6770
const namespacet &ns;
6871

@@ -100,6 +103,9 @@ class c_typecastt
100103
void do_typecast(exprt &dest, const typet &type);
101104

102105
c_typet minimum_promotion(const typet &type) const;
106+
107+
private:
108+
const symbolt *current_symbol;
103109
};
104110

105111
#endif // CPROVER_ANSI_C_C_TYPECAST_H

src/ansi-c/c_typecheck_typecast.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void c_typecheck_baset::implicit_typecast(
1515
const typet &dest_type)
1616
{
1717
c_typecastt c_typecast(*this);
18+
c_typecast.set_current_symbol(&current_symbol);
1819

1920
typet src_type=expr.type();
2021

0 commit comments

Comments
 (0)