Skip to content

Commit 20cba10

Browse files
authored
Merge pull request #3014 from svorenova/mock-vararg-tg5038
Parse ACC_VARARGS method flag from bytecode [TG-5038]
2 parents ed4637b + b6589dd commit 20cba10

File tree

8 files changed

+57
-2
lines changed

8 files changed

+57
-2
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ void java_bytecode_convert_method_lazy(
373373
if(m.is_static)
374374
member_type.set(ID_is_static, true);
375375
member_type.set_native(m.is_native);
376+
member_type.set_is_varargs(m.is_varargs);
376377

377378
if(m.is_bridge)
378379
member_type.set(ID_is_bridge_method, m.is_bridge);

jbmc/src/java_bytecode/java_bytecode_parse_tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct java_bytecode_parse_treet
8686
struct methodt : public membert
8787
{
8888
irep_idt base_name;
89-
bool is_native, is_abstract, is_synchronized, is_bridge;
89+
bool is_native, is_abstract, is_synchronized, is_bridge, is_varargs;
9090
source_locationt source_location;
9191

9292
typedef std::vector<instructiont> instructionst;

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,6 @@ bool java_bytecode_parsert::parse()
452452
#define ACC_FINAL 0x0010
453453
#define ACC_SYNCHRONIZED 0x0020
454454
#define ACC_BRIDGE 0x0040
455-
#define ACC_VARARGS 0x0080
456455
#define ACC_NATIVE 0x0100
457456
#define ACC_INTERFACE 0x0200
458457
#define ACC_ABSTRACT 0x0400
@@ -1777,6 +1776,7 @@ void java_bytecode_parsert::rmethods(classt &parsed_class)
17771776
#define ACC_PROTECTED 0x0004
17781777
#define ACC_STATIC 0x0008
17791778
#define ACC_FINAL 0x0010
1779+
#define ACC_VARARGS 0x0080
17801780
#define ACC_SUPER 0x0020
17811781
#define ACC_VOLATILE 0x0040
17821782
#define ACC_TRANSIENT 0x0080
@@ -1803,6 +1803,7 @@ void java_bytecode_parsert::rmethod(classt &parsed_class)
18031803
method.is_synchronized=(access_flags&ACC_SYNCHRONIZED)!=0;
18041804
method.is_native=(access_flags&ACC_NATIVE)!=0;
18051805
method.is_bridge = (access_flags & ACC_BRIDGE) != 0;
1806+
method.is_varargs = (access_flags & ACC_VARARGS) != 0;
18061807
method.name=pool_entry(name_index).s;
18071808
method.base_name=pool_entry(name_index).s;
18081809
method.descriptor=id2string(pool_entry(descriptor_index).s);

jbmc/src/java_bytecode/java_types.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,16 @@ class java_method_typet : public code_typet
298298
{
299299
set(ID_is_native_method, is_native);
300300
}
301+
302+
bool get_is_varargs() const
303+
{
304+
return get_bool(ID_is_varargs_method);
305+
}
306+
307+
void set_is_varargs(bool is_varargs)
308+
{
309+
set(ID_is_varargs_method, is_varargs);
310+
}
301311
};
302312

303313
template <>
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class ClassWithVarArgsMethod {
2+
public int varArgsFunc(int... args) {
3+
return 0;
4+
}
5+
public int nonVarArgsFunc(int[] args) {
6+
return 0;
7+
}
8+
}

jbmc/unit/java_bytecode/java_bytecode_convert_method/convert_method.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,37 @@ SCENARIO(
141141
}
142142
}
143143
}
144+
145+
SCENARIO(
146+
"java_bytecode_convert_varargs_method",
147+
"[core][java_bytecode][java_bytecode_convert_method]")
148+
{
149+
GIVEN("A class with varargs and non-varargs methods")
150+
{
151+
const symbol_tablet symbol_table = load_java_class(
152+
"ClassWithVarArgsMethod", "./java_bytecode/java_bytecode_convert_method");
153+
154+
WHEN("When parsing a method with a variable number of arguments")
155+
{
156+
const symbolt method_symbol = symbol_table.lookup_ref(
157+
"java::ClassWithVarArgsMethod.varArgsFunc:([I)I");
158+
const java_method_typet &method_type =
159+
require_type::require_java_method(method_symbol.type);
160+
THEN("The method should be marked as varargs")
161+
{
162+
REQUIRE(method_type.get_is_varargs());
163+
}
164+
}
165+
WHEN("When parsing a method with constant number of arguments")
166+
{
167+
const symbolt method_symbol = symbol_table.lookup_ref(
168+
"java::ClassWithVarArgsMethod.nonVarArgsFunc:([I)I");
169+
const java_method_typet &method_type =
170+
require_type::require_java_method(method_symbol.type);
171+
THEN("The method should not be marked as varargs")
172+
{
173+
REQUIRE_FALSE(method_type.get_is_varargs());
174+
}
175+
}
176+
}
177+
}

src/util/irep_ids.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ IREP_ID_ONE(is_inline)
387387
IREP_ID_ONE(is_extern)
388388
IREP_ID_ONE(is_synchronized)
389389
IREP_ID_ONE(is_native_method)
390+
IREP_ID_ONE(is_varargs_method)
390391
IREP_ID_ONE(is_global)
391392
IREP_ID_ONE(is_thread_local)
392393
IREP_ID_ONE(is_parameter)

0 commit comments

Comments
 (0)