Skip to content

Commit ea0e1b1

Browse files
authored
Merge pull request #6995 from tautschnig/bugfixes/6994-to_array_expr-source-loc
string_constantt::to_array_expr must maintain the source location
2 parents 21ff086 + 917f9a0 commit ea0e1b1

File tree

6 files changed

+47
-5
lines changed

6 files changed

+47
-5
lines changed

regression/cbmc/String_Literal1/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@ int main()
5252

5353
// generic wide string, OS-dependent
5454
assert(sizeof(L""[0])==sizeof(wchar_t));
55+
56+
assert(0);
5557
}
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
CORE
22
main.c
3-
4-
^EXIT=0$
3+
--trace
4+
^State \d+ file main.c function main line 20 thread 0$
5+
^State \d+ file main.c function main line 36 thread 0$
6+
^State \d+ file main.c function main line 44 thread 0$
7+
^\*\* 1 of \d+ failed \(\d+ iterations\)$
8+
^VERIFICATION FAILED$
9+
^EXIT=10$
510
^SIGNAL=0$
6-
^VERIFICATION SUCCESSFUL$
711
--
812
^warning: ignoring
13+
^State \d+ (function main )?thread 0$
14+
--
15+
Each step in the trace must have a full source location, including line numbers.

src/util/expr.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,30 @@ class exprt:public irept
9898
const operandst &operands() const
9999
{ return (const operandst &)get_sub(); }
100100

101+
/// Add the source location from \p other, if it has any.
102+
template <typename T>
103+
T &with_source_location(const exprt &other) &
104+
{
105+
static_assert(
106+
std::is_base_of<exprt, T>::value,
107+
"The template argument T must be derived from exprt.");
108+
if(other.source_location().is_not_nil())
109+
add_source_location() = other.source_location();
110+
return *static_cast<T *>(this);
111+
}
112+
113+
/// Add the source location from \p other, if it has any.
114+
template <typename T>
115+
T &&with_source_location(const exprt &other) &&
116+
{
117+
static_assert(
118+
std::is_base_of<exprt, T>::value,
119+
"The template argument T must be derived from exprt.");
120+
if(other.source_location().is_not_nil())
121+
add_source_location() = other.source_location();
122+
return std::move(*static_cast<T *>(this));
123+
}
124+
101125
protected:
102126
exprt &op0()
103127
{ return operands().front(); }

src/util/std_expr.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,16 @@ class array_exprt : public multi_ary_exprt
15711571
{
15721572
return static_cast<array_typet &>(multi_ary_exprt::type());
15731573
}
1574+
1575+
array_exprt &with_source_location(const exprt &other) &
1576+
{
1577+
return exprt::with_source_location<array_exprt>(other);
1578+
}
1579+
1580+
array_exprt &&with_source_location(const exprt &other) &&
1581+
{
1582+
return std::move(*this).exprt::with_source_location<array_exprt>(other);
1583+
}
15741584
};
15751585

15761586
template <>

src/util/string_constant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ array_exprt string_constantt::to_array_expr() const
5353
*it = from_integer(ch, char_type);
5454
}
5555

56-
return dest;
56+
return std::move(dest).with_source_location(*this);
5757
}

src/util/string_constant.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class string_constantt : public nullary_exprt
2424
}
2525

2626
array_exprt to_array_expr() const;
27-
bool from_array_expr(const array_exprt &);
2827
};
2928

3029
template <>

0 commit comments

Comments
 (0)