Skip to content

Commit 73a2c88

Browse files
committed
Java frontend: set parameter identifiers for forcibly-stubbed methods
org.cprover.CProver methods are sometimes deliberately ignored in order to invite the front-end program to produce stub bodies. This means the symbols are discovered through normal class loading, not through usage (how stub methods usually get their parameter identifiers), but they are not subject to the usual java_bytecode_convert_method routine (which sets the parameter identifiers for normal methods). This commit handles this in- between special case and adds a test checking these methods are usable without crashing, typically in goto-symex which requires these identifiers to be set.
1 parent eabc411 commit 73a2c88

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed
292 Bytes
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class Test {
2+
3+
public static void main() {
4+
5+
org.cprover.CProver.startThread(1);
6+
7+
}
8+
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
Test.class
3+
--function Test.main --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
This calls to CProver.startThread, which are special-cased by the Java front-end (which omits the method's body
10+
in hope of the front-end handling it like a stub), but which don't get their parameter names assigned by the usual
11+
mechanism (setting the names when the stub is discovered for the first time)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
Test.class
3+
--function Test.main --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --show-goto-functions
4+
org\.cprover\.CProver\.startThread:\(I\)V
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
Companion to the main test.desc that checks the function under test uses org.cprover.CProver.startThread(int)

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,15 @@ void java_bytecode_convert_method_lazy(
398398
symbol_table.add(method_symbol);
399399
}
400400

401+
static irep_idt get_method_identifier(
402+
const irep_idt &class_identifier,
403+
const java_bytecode_parse_treet::methodt &method)
404+
{
405+
return
406+
id2string(class_identifier) + "." + id2string(method.name) + ":" +
407+
method.descriptor;
408+
}
409+
401410
void java_bytecode_convert_methodt::convert(
402411
const symbolt &class_symbol,
403412
const methodt &m)
@@ -406,8 +415,9 @@ void java_bytecode_convert_methodt::convert(
406415
// (e.g. "my.package.ClassName.myMethodName:(II)I") and query the symbol table
407416
// to retrieve the symbol (constructed by java_bytecode_convert_method_lazy)
408417
// associated to the method
409-
const irep_idt method_identifier=
410-
id2string(class_symbol.name)+"."+id2string(m.name)+":"+m.descriptor;
418+
const irep_idt method_identifier =
419+
get_method_identifier(class_symbol.name, m);
420+
411421
method_id=method_identifier;
412422

413423
// Obtain a std::vector of java_method_typet::parametert objects from the
@@ -3084,6 +3094,17 @@ void java_bytecode_convert_method(
30843094
{
30853095
// Ignore these methods; fall back to the driver program's
30863096
// stubbing behaviour.
3097+
3098+
// Assign parameter names -- this would normally be done either by the
3099+
// normal method conversion routine or upon discovering the stub method,
3100+
// but this fake stubbing awkwardly falls between the two ways.
3101+
const irep_idt method_id = get_method_identifier(class_symbol.name, method);
3102+
symbolt &method_symbol = symbol_table.get_writeable_ref(method_id);
3103+
assign_parameter_names(
3104+
to_java_method_type(method_symbol.type),
3105+
method_symbol.name,
3106+
symbol_table);
3107+
30873108
return;
30883109
}
30893110

0 commit comments

Comments
 (0)