Skip to content

Commit 7f8b2be

Browse files
author
Matthias Güdemann
authored
Merge pull request #2582 from jeannielynnmoulton/jeannie/parse-bridge-flag-for-thk123
Parse bridge flag [TG-4115]
2 parents 8966f09 + cb587a9 commit 7f8b2be

File tree

7 files changed

+71
-5
lines changed

7 files changed

+71
-5
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ void java_bytecode_convert_method_lazy(
371371
if(m.is_static)
372372
member_type.set(ID_is_static, true);
373373

374+
if(m.is_bridge)
375+
member_type.set(ID_is_bridge_method, m.is_bridge);
376+
374377
// do we need to add 'this' as a parameter?
375378
if(!m.is_static)
376379
{

jbmc/src/java_bytecode/java_bytecode_parse_tree.h

Lines changed: 6 additions & 5 deletions
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;
89+
bool is_native, is_abstract, is_synchronized, is_bridge;
9090
source_locationt source_location;
9191

9292
typedef std::vector<instructiont> instructionst;
@@ -164,10 +164,11 @@ struct java_bytecode_parse_treet
164164

165165
void output(std::ostream &out) const;
166166

167-
methodt():
168-
is_native(false),
169-
is_abstract(false),
170-
is_synchronized(false)
167+
methodt()
168+
: is_native(false),
169+
is_abstract(false),
170+
is_synchronized(false),
171+
is_bridge(false)
171172
{
172173
}
173174
};

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,7 @@ void java_bytecode_parsert::rmethod(classt &parsed_class)
17661766
method.is_private=(access_flags&ACC_PRIVATE)!=0;
17671767
method.is_synchronized=(access_flags&ACC_SYNCHRONIZED)!=0;
17681768
method.is_native=(access_flags&ACC_NATIVE)!=0;
1769+
method.is_bridge = (access_flags & ACC_BRIDGE) != 0;
17691770
method.name=pool_entry(name_index).s;
17701771
method.base_name=pool_entry(name_index).s;
17711772
method.descriptor=id2string(pool_entry(descriptor_index).s);
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class ClassWithBridgeMethod implements Comparable<ClassWithBridgeMethod> {
2+
public int compareTo(ClassWithBridgeMethod other) {
3+
return 0;
4+
}
5+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for converting constructors and static initializers
4+
5+
Author: Diffblue Limited.
6+
7+
\*******************************************************************/
8+
9+
#include <testing-utils/catch.hpp>
10+
11+
#include <util/symbol_table.h>
12+
13+
#include <java-testing-utils/load_java_class.h>
14+
#include <java-testing-utils/require_type.h>
15+
16+
SCENARIO(
17+
"java_bytecode_convert_bridge_method",
18+
"[core][java_bytecode][java_bytecode_convert_method]")
19+
{
20+
GIVEN("A class with a bridge method")
21+
{
22+
const symbol_tablet symbol_table = load_java_class(
23+
"ClassWithBridgeMethod", "./java_bytecode/java_bytecode_convert_method");
24+
25+
const std::string method_name = "java::ClassWithBridgeMethod.compareTo";
26+
27+
WHEN("When parsing the bridge method")
28+
{
29+
const symbolt function_symbol =
30+
symbol_table.lookup_ref(method_name + ":(Ljava/lang/Object;)I");
31+
32+
const code_typet &function_type =
33+
require_type::require_code(function_symbol.type);
34+
THEN("The method should be marked as a bridge method")
35+
{
36+
REQUIRE(function_type.get_bool(ID_is_bridge_method));
37+
}
38+
}
39+
WHEN("When parsing a non-bridge method")
40+
{
41+
THEN("THe method should not be marked as a bridge method")
42+
{
43+
const symbolt function_symbol =
44+
symbol_table.lookup_ref(method_name + ":(LClassWithBridgeMethod;)I");
45+
46+
const code_typet &function_type =
47+
require_type::require_code(function_symbol.type);
48+
THEN("The method should be marked as a bridge method")
49+
{
50+
REQUIRE_FALSE(function_type.get_bool(ID_is_bridge_method));
51+
}
52+
}
53+
}
54+
}
55+
}

src/util/irep_ids.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ IREP_ID_TWO(C_must_not_throw, #must_not_throw)
676676
IREP_ID_ONE(is_inner_class)
677677
IREP_ID_ONE(is_anonymous)
678678
IREP_ID_ONE(outer_class)
679+
IREP_ID_ONE(is_bridge_method)
679680

680681
// Projects depending on this code base that wish to extend the list of
681682
// available ids should provide a file local_irep_ids.h in their source tree and

0 commit comments

Comments
 (0)