Skip to content

Commit 9411c77

Browse files
authored
Merge pull request #7856 from tautschnig/bugfixes/linking-location
Add missing source locations
2 parents 6f628d8 + 5d8abbe commit 9411c77

File tree

24 files changed

+256
-48
lines changed

24 files changed

+256
-48
lines changed

jbmc/src/java_bytecode/nondet.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ code_blockt generate_nondet_switch(
123123
this_block.add(switch_case);
124124
this_block.add(code_breakt());
125125
code_switch_caset this_case(
126-
from_integer(case_number, switch_value.type()), this_block);
126+
from_integer(case_number, switch_value.type())
127+
.with_source_location(source_location),
128+
this_block);
127129
switch_block.add(std::move(this_case));
128130
++case_number;
129131
}

regression/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ add_subdirectory(k-induction)
7777
add_subdirectory(goto-harness)
7878
add_subdirectory(goto-harness-multi-file-project)
7979
add_subdirectory(goto-cc-file-local)
80+
add_subdirectory(goto-cc-multi-file)
8081
add_subdirectory(goto-cc-regression-gh-issue-5380)
8182
add_subdirectory(linking-goto-binaries)
8283
add_subdirectory(symtab2gb)

regression/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ DIRS = cbmc-shadow-memory \
5050
goto-harness \
5151
goto-harness-multi-file-project \
5252
goto-cc-file-local \
53+
goto-cc-multi-file \
5354
goto-cc-regression-gh-issue-5380 \
5455
linking-goto-binaries \
5556
symtab2gb \
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
int main()
2+
{
3+
int b, c;
4+
5+
if(b)
6+
{
7+
if(c)
8+
{
9+
c = 1;
10+
}
11+
else
12+
{
13+
c = 2;
14+
}
15+
}
16+
else
17+
{
18+
b = 0;
19+
}
20+
21+
return 1;
22+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--cover location
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.coverage.\d+\] file main.c line 9 function main block \d+ \(lines main.c:main:9,10\): SATISFIED$
7+
^\[main.coverage.\d+\] file main.c line 15 function main block \d+ \(lines main.c:main:15\): SATISFIED$
8+
^\*\* 7 of 7 covered \(100.0%\)
9+
--
10+
^warning: ignoring
11+
--
12+
All gotos must have a source location annotated.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if(WIN32)
2+
set(is_windows true)
3+
else()
4+
set(is_windows false)
5+
endif()
6+
7+
add_test_pl_tests(
8+
"${CMAKE_CURRENT_SOURCE_DIR}/chain.sh $<TARGET_FILE:goto-cc> $<TARGET_FILE:cbmc> ${is_windows}"
9+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
int foo()
2+
{
3+
return 0;
4+
}
5+
6+
int main()
7+
{
8+
int result;
9+
result = foo();
10+
return result;
11+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int foo();
2+
3+
int bar()
4+
{
5+
return foo();
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
other.c
4+
file main.c line 9 function main
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
We previously lost the location attached to the call of `foo` in function main.

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,15 +1044,16 @@ void c_typecheck_baset::typecheck_expr_sizeof(exprt &expr)
10441044
new_expr = size_of_opt.value();
10451045
}
10461046

1047+
source_locationt location = expr.source_location();
10471048
new_expr.swap(expr);
1048-
1049+
expr.add_source_location() = location;
10491050
expr.add(ID_C_c_sizeof_type)=type;
10501051

10511052
// The type may contain side-effects.
10521053
if(!clean_code.empty())
10531054
{
10541055
side_effect_exprt side_effect_expr(
1055-
ID_statement_expression, void_type(), expr.source_location());
1056+
ID_statement_expression, void_type(), location);
10561057
auto decl_block=code_blockt::from_list(clean_code);
10571058
decl_block.set_statement(ID_decl_block);
10581059
side_effect_expr.copy_to_operands(decl_block);
@@ -1064,8 +1065,9 @@ void c_typecheck_baset::typecheck_expr_sizeof(exprt &expr)
10641065
// It is not obvious whether the type or 'e' should be evaluated
10651066
// first.
10661067

1067-
binary_exprt comma_expr{
1068-
std::move(side_effect_expr), ID_comma, expr, expr.type()};
1068+
exprt comma_expr =
1069+
binary_exprt{std::move(side_effect_expr), ID_comma, expr, expr.type()}
1070+
.with_source_location(location);
10691071
expr.swap(comma_expr);
10701072
}
10711073
}
@@ -4656,6 +4658,8 @@ class is_compile_time_constantt
46564658

46574659
void c_typecheck_baset::make_constant(exprt &expr)
46584660
{
4661+
source_locationt location = expr.find_source_location();
4662+
46594663
// Floating-point expressions may require a rounding mode.
46604664
// ISO 9899:1999 F.7.2 says that the default is "round to nearest".
46614665
// Some compilers have command-line options to override.
@@ -4664,10 +4668,11 @@ void c_typecheck_baset::make_constant(exprt &expr)
46644668
adjust_float_expressions(expr, rounding_mode);
46654669

46664670
simplify(expr, *this);
4671+
expr.add_source_location() = location;
46674672

46684673
if(!is_compile_time_constantt(*this)(expr))
46694674
{
4670-
error().source_location=expr.find_source_location();
4675+
error().source_location = location;
46714676
error() << "expected constant expression, but got '" << to_string(expr)
46724677
<< "'" << eom;
46734678
throw 0;
@@ -4676,13 +4681,15 @@ void c_typecheck_baset::make_constant(exprt &expr)
46764681

46774682
void c_typecheck_baset::make_constant_index(exprt &expr)
46784683
{
4684+
source_locationt location = expr.find_source_location();
46794685
make_constant(expr);
46804686
make_index_type(expr);
46814687
simplify(expr, *this);
4688+
expr.add_source_location() = location;
46824689

46834690
if(!is_compile_time_constantt(*this)(expr))
46844691
{
4685-
error().source_location=expr.find_source_location();
4692+
error().source_location = location;
46864693
error() << "conversion to integer constant failed" << eom;
46874694
throw 0;
46884695
}

0 commit comments

Comments
 (0)