-
Notifications
You must be signed in to change notification settings - Fork 274
Java frontend: record source locations of read static variables #5144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
smowton
merged 1 commit into
diffblue:develop
from
smowton:smowton/feature/java-record-getstatic-source-locations
Oct 5, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+375 Bytes
jbmc/unit/java_bytecode/java_bytecode_convert_method/ClassReadingStaticField.class
Binary file not shown.
11 changes: 11 additions & 0 deletions
11
jbmc/unit/java_bytecode/java_bytecode_convert_method/ClassReadingStaticField.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class ClassReadingStaticField { | ||
|
||
static int x; | ||
|
||
public static int test() { | ||
|
||
return x; | ||
|
||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -291,6 +291,45 @@ SCENARIO( | |
} | ||
} | ||
|
||
SCENARIO( | ||
"java_bytecode_convert_method_with_getstatic", | ||
"[core][java_bytecode][java_bytecode_convert_method]") | ||
{ | ||
GIVEN("A class that reads a static field.") | ||
{ | ||
const symbol_tablet symbol_table = load_java_class( | ||
"ClassReadingStaticField", | ||
"./java_bytecode/java_bytecode_convert_method"); | ||
|
||
WHEN("Converting the method that reads said field") | ||
{ | ||
const auto &method_symbol = | ||
symbol_table.lookup_ref("java::ClassReadingStaticField.test:()I"); | ||
|
||
THEN( | ||
"There should be a symbol expression attributed to bytecode index " | ||
"0 (the getstatic instruction)") | ||
{ | ||
bool found = false; | ||
method_symbol.value.visit_pre([&found](const exprt &subexpr) { | ||
if( | ||
const auto symbol_expr = | ||
expr_try_dynamic_cast<symbol_exprt>(subexpr)) | ||
{ | ||
if( | ||
symbol_expr->source_location().get_java_bytecode_index() == "0" && | ||
symbol_expr->get_identifier() == | ||
"java::ClassReadingStaticField.x") | ||
found = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛏️ multi line condition so please add braces around the body |
||
} | ||
}); | ||
|
||
REQUIRE(found); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// Allow access to private methods so that they can be unit tested | ||
class java_bytecode_convert_method_unit_testt | ||
{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ if the symbol isn't found, using lookup_ref makes the output on CI not very clear, better to use lookup and then REQUIRE(method_symbol != nullptr)