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

24 files changed

+256
-48
lines changed

jbmc/src/java_bytecode/nondet.cpp

+3-1
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

+1
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

+1
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 \
+22
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+
}
+12
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.
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+
)
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int foo();
2+
3+
int bar()
4+
{
5+
return foo();
6+
}
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

+13-6
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
}

src/ansi-c/c_typecheck_gcc_polymorphic_builtins.cpp

+35-23
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,8 @@ static void instantiate_atomic_fetch_op(
673673
block.add(code_frontend_assignt{deref_ptr, std::move(op_expr)});
674674

675675
block.add(code_expressiont{side_effect_expr_function_callt{
676-
symbol_exprt::typeless("__atomic_thread_fence"),
676+
symbol_exprt::typeless("__atomic_thread_fence")
677+
.with_source_location(source_location),
677678
{parameter_exprs[2]},
678679
typet{},
679680
source_location}});
@@ -736,7 +737,8 @@ static void instantiate_atomic_op_fetch(
736737

737738
// this instruction implies an mfence, i.e., WRfence
738739
block.add(code_expressiont{side_effect_expr_function_callt{
739-
symbol_exprt::typeless("__atomic_thread_fence"),
740+
symbol_exprt::typeless("__atomic_thread_fence")
741+
.with_source_location(source_location),
740742
{parameter_exprs[2]},
741743
typet{},
742744
source_location}});
@@ -767,11 +769,11 @@ static void instantiate_sync_fetch(
767769
parameter_exprs[1],
768770
from_integer(std::memory_order_seq_cst, signed_int_type())};
769771

770-
block.add(code_returnt{
771-
side_effect_expr_function_callt{symbol_exprt::typeless(atomic_name),
772-
std::move(arguments),
773-
typet{},
774-
source_location}});
772+
block.add(code_returnt{side_effect_expr_function_callt{
773+
symbol_exprt::typeless(atomic_name).with_source_location(source_location),
774+
std::move(arguments),
775+
typet{},
776+
source_location}});
775777
}
776778

777779
static void instantiate_sync_bool_compare_and_swap(
@@ -790,7 +792,8 @@ static void instantiate_sync_bool_compare_and_swap(
790792
// _Bool __sync_bool_compare_and_swap(type *ptr, type old, type new, ...)
791793

792794
block.add(code_returnt{side_effect_expr_function_callt{
793-
symbol_exprt::typeless(ID___atomic_compare_exchange),
795+
symbol_exprt::typeless(ID___atomic_compare_exchange)
796+
.with_source_location(source_location),
794797
{parameter_exprs[0],
795798
address_of_exprt{parameter_exprs[1]},
796799
address_of_exprt{parameter_exprs[2]},
@@ -968,7 +971,8 @@ static void instantiate_atomic_load(
968971
dereference_exprt{parameter_exprs[0]}});
969972

970973
block.add(code_expressiont{side_effect_expr_function_callt{
971-
symbol_exprt::typeless("__atomic_thread_fence"),
974+
symbol_exprt::typeless("__atomic_thread_fence")
975+
.with_source_location(source_location),
972976
{parameter_exprs[2]},
973977
typet{},
974978
source_location}});
@@ -999,7 +1003,8 @@ static void instantiate_atomic_load_n(
9991003
block.add(codet{ID_decl_block, {code_frontend_declt{result}}});
10001004

10011005
block.add(code_expressiont{side_effect_expr_function_callt{
1002-
symbol_exprt::typeless(ID___atomic_load),
1006+
symbol_exprt::typeless(ID___atomic_load)
1007+
.with_source_location(source_location),
10031008
{parameter_exprs[0], address_of_exprt{result}, parameter_exprs[1]},
10041009
typet{},
10051010
source_location}});
@@ -1028,7 +1033,8 @@ static void instantiate_atomic_store(
10281033
dereference_exprt{parameter_exprs[1]}});
10291034

10301035
block.add(code_expressiont{side_effect_expr_function_callt{
1031-
symbol_exprt::typeless("__atomic_thread_fence"),
1036+
symbol_exprt::typeless("__atomic_thread_fence")
1037+
.with_source_location(source_location),
10321038
{parameter_exprs[2]},
10331039
typet{},
10341040
source_location}});
@@ -1051,13 +1057,14 @@ static void instantiate_atomic_store_n(
10511057
// This built-in function implements an atomic store operation. It writes
10521058
// val into *ptr.
10531059

1054-
block.add(code_expressiont{
1055-
side_effect_expr_function_callt{symbol_exprt::typeless(ID___atomic_store),
1056-
{parameter_exprs[0],
1057-
address_of_exprt{parameter_exprs[1]},
1058-
parameter_exprs[2]},
1059-
typet{},
1060-
source_location}});
1060+
block.add(code_expressiont{side_effect_expr_function_callt{
1061+
symbol_exprt::typeless(ID___atomic_store)
1062+
.with_source_location(source_location),
1063+
{parameter_exprs[0],
1064+
address_of_exprt{parameter_exprs[1]},
1065+
parameter_exprs[2]},
1066+
typet{},
1067+
source_location}});
10611068
}
10621069

10631070
static void instantiate_atomic_exchange(
@@ -1083,7 +1090,8 @@ static void instantiate_atomic_exchange(
10831090
dereference_exprt{parameter_exprs[1]}});
10841091

10851092
block.add(code_expressiont{side_effect_expr_function_callt{
1086-
symbol_exprt::typeless("__atomic_thread_fence"),
1093+
symbol_exprt::typeless("__atomic_thread_fence")
1094+
.with_source_location(source_location),
10871095
{parameter_exprs[3]},
10881096
typet{},
10891097
source_location}});
@@ -1114,7 +1122,8 @@ static void instantiate_atomic_exchange_n(
11141122
block.add(codet{ID_decl_block, {code_frontend_declt{result}}});
11151123

11161124
block.add(code_expressiont{side_effect_expr_function_callt{
1117-
symbol_exprt::typeless(ID___atomic_exchange),
1125+
symbol_exprt::typeless(ID___atomic_exchange)
1126+
.with_source_location(source_location),
11181127
{parameter_exprs[0],
11191128
address_of_exprt{parameter_exprs[1]},
11201129
address_of_exprt{result},
@@ -1171,7 +1180,8 @@ static void instantiate_atomic_compare_exchange(
11711180
dereference_exprt{parameter_exprs[2]}};
11721181
assign.add_source_location() = source_location;
11731182
code_expressiont success_fence{side_effect_expr_function_callt{
1174-
symbol_exprt::typeless("__atomic_thread_fence"),
1183+
symbol_exprt::typeless("__atomic_thread_fence")
1184+
.with_source_location(source_location),
11751185
{parameter_exprs[4]},
11761186
typet{},
11771187
source_location}};
@@ -1181,7 +1191,8 @@ static void instantiate_atomic_compare_exchange(
11811191
deref_ptr};
11821192
assign_not_equal.add_source_location() = source_location;
11831193
code_expressiont failure_fence{side_effect_expr_function_callt{
1184-
symbol_exprt::typeless("__atomic_thread_fence"),
1194+
symbol_exprt::typeless("__atomic_thread_fence")
1195+
.with_source_location(source_location),
11851196
{parameter_exprs[5]},
11861197
typet{},
11871198
source_location}};
@@ -1212,7 +1223,8 @@ static void instantiate_atomic_compare_exchange_n(
12121223
// desired, bool weak, int success_memorder, int failure_memorder)
12131224

12141225
block.add(code_returnt{side_effect_expr_function_callt{
1215-
symbol_exprt::typeless(ID___atomic_compare_exchange),
1226+
symbol_exprt::typeless(ID___atomic_compare_exchange)
1227+
.with_source_location(source_location),
12161228
{parameter_exprs[0],
12171229
parameter_exprs[1],
12181230
address_of_exprt{parameter_exprs[2]},

src/assembler/remove_asm.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ void remove_asmt::gcc_asm_function_call(
133133
arguments.size(), code_typet::parametert{void_pointer}},
134134
empty_typet()};
135135

136-
symbol_exprt fkt(function_identifier, fkt_type);
136+
auto fkt = symbol_exprt{function_identifier, fkt_type}.with_source_location(
137+
code.source_location());
137138

138139
code_function_callt function_call(std::move(fkt), std::move(arguments));
139140

@@ -189,8 +190,8 @@ void remove_asmt::msc_asm_function_call(
189190
arguments.size(), code_typet::parametert{void_pointer}},
190191
empty_typet()};
191192

192-
symbol_exprt fkt(function_identifier, fkt_type);
193-
193+
auto fkt = symbol_exprt{function_identifier, fkt_type}.with_source_location(
194+
code.source_location());
194195
code_function_callt function_call(std::move(fkt), std::move(arguments));
195196

196197
dest.add(

src/goto-programs/goto_clean_expr.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,14 @@ void goto_convertt::clean_expr(
284284

285285
// generate guard for argument side-effects
286286
generate_ifthenelse(
287-
if_expr.cond(), tmp_true, tmp_false, source_location, dest, mode);
287+
if_expr.cond(),
288+
source_location,
289+
tmp_true,
290+
if_expr.true_case().source_location(),
291+
tmp_false,
292+
if_expr.false_case().source_location(),
293+
dest,
294+
mode);
288295

289296
return;
290297
}

0 commit comments

Comments
 (0)