Skip to content

Commit fef6d08

Browse files
author
svorenova
authored
Merge pull request #4893 from svorenova/not-null-annotation-check-location
Correct the source location of methods and not null annotation checks [TG-8270]
2 parents e7a78aa + 85a1e8b commit fef6d08

File tree

7 files changed

+35
-14
lines changed

7 files changed

+35
-14
lines changed
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
abstract class MainKotlin(val scope: String, val kind: String) {
2+
}

jbmc/regression/jbmc/parameter-annotation-not-null/test_array.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Main.class
44
^EXIT=10$
55
^SIGNAL=0$
66
^VERIFICATION FAILED$
7-
\[not-null-annotation-check\.1\] line \d+ Not null annotation check: FAILURE
8-
\[not-null-annotation-check\.2\] line \d+ Not null annotation check: SUCCESS
7+
\[java::Main\.bar:\(Ljava/lang/Integer;ZLjava/lang/Object;\[Ljava/lang/String;\)Ljava/lang/Integer;\.not-null-annotation-check\.1\] line \d+ Not null annotation check: FAILURE
8+
\[java::Main\.bar:\(Ljava/lang/Integer;ZLjava/lang/Object;\[Ljava/lang/String;\)Ljava/lang/Integer;\.not-null-annotation-check\.2\] line \d+ Not null annotation check: SUCCESS
99
--
1010
^warning: ignoring
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
MainKotlin.class
3+
--function "MainKotlin.<init>" --show-properties
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
Property java::MainKotlin.<init>:\(Ljava/lang/String;Ljava/lang/String;\)V.not-null-annotation-check.1:
7+
Property java::MainKotlin.<init>:\(Ljava/lang/String;Ljava/lang/String;\)V.not-null-annotation-check.2:
8+
file MainKotlin.kt line 1 function java::MainKotlin.<init>:\(Ljava/lang/String;Ljava/lang/String;\)V$
9+
--
10+
--
11+
Test that the not-null-annotation-check property name is correctly prefixed with
12+
the method name and has line number assigned

jbmc/regression/jbmc/parameter-annotation-not-null/test_object.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Main.class
44
^EXIT=10$
55
^SIGNAL=0$
66
^VERIFICATION FAILED$
7-
\[not-null-annotation-check\.1\] line \d+ Not null annotation check: SUCCESS
8-
\[not-null-annotation-check\.2\] line \d+ Not null annotation check: FAILURE
7+
\[java::Main\.foo:\(Ljava/lang/Integer;ZLjava/lang/Object;\[Ljava/lang/String;\)Ljava/lang/Integer;\.not-null-annotation-check\.1\] line \d+ Not null annotation check: SUCCESS
8+
\[java::Main\.foo:\(Ljava/lang/Integer;ZLjava/lang/Object;\[Ljava/lang/String;\)Ljava/lang/Integer;\.not-null-annotation-check\.2\] line \d+ Not null annotation check: FAILURE
99
--
1010
^warning: ignoring

jbmc/regression/jbmc/parameter-annotation-not-null/test_success.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Main.class
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
7-
\[not-null-annotation-check\.1\] line \d+ Not null annotation check: SUCCESS
8-
\[not-null-annotation-check\.2\] line \d+ Not null annotation check: SUCCESS
7+
\[java::Main\.foo:\(Ljava/lang/Integer;ZLjava/lang/Object;\[Ljava/lang/String;\)Ljava/lang/Integer;\.not-null-annotation-check\.1\] line \d+ Not null annotation check: SUCCESS
8+
\[java::Main\.foo:\(Ljava/lang/Integer;ZLjava/lang/Object;\[Ljava/lang/String;\)Ljava/lang/Integer;\.not-null-annotation-check\.2\] line \d+ Not null annotation check: SUCCESS
99
--
1010
^warning: ignoring

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,11 @@ void java_bytecode_parsert::rmethod_attribute(methodt &method)
12381238
for(std::size_t j=0; j<attributes_count; j++)
12391239
rcode_attribute(method);
12401240

1241+
// method name
1242+
method.source_location.set_function(
1243+
"java::" + id2string(parse_tree.parsed_class.name) + "." +
1244+
id2string(method.name) + ":" + method.descriptor);
1245+
12411246
irep_idt line_number;
12421247

12431248
// add missing line numbers
@@ -1250,16 +1255,18 @@ void java_bytecode_parsert::rmethod_attribute(methodt &method)
12501255
line_number=it->source_location.get_line();
12511256
else if(!line_number.empty())
12521257
it->source_location.set_line(line_number);
1253-
it->source_location
1254-
.set_function(
1255-
"java::"+id2string(parse_tree.parsed_class.name)+"."+
1256-
id2string(method.name)+":"+method.descriptor);
1258+
it->source_location.set_function(method.source_location.get_function());
12571259
}
12581260

1259-
// line number of method
1260-
if(!method.instructions.empty())
1261-
method.source_location.set_line(
1262-
method.instructions.begin()->source_location.get_line());
1261+
// line number of method (the first line number available)
1262+
const auto it = std::find_if(
1263+
method.instructions.begin(),
1264+
method.instructions.end(),
1265+
[&](const instructiont &instruction) {
1266+
return !instruction.source_location.get_line().empty();
1267+
});
1268+
if(it != method.instructions.end())
1269+
method.source_location.set_line(it->source_location.get_line());
12631270
}
12641271
else if(attribute_name=="Signature")
12651272
{

0 commit comments

Comments
 (0)