Open Chaoshuai-Li opened 2 years ago
@Chaoshuai-Li thanks for the question. You're right that there is a difference in the IRs. WALA's IR is in SSA form and copy propagation is formed during SSA construction. So, copies of local variables and writing of constants to locals is not preserved in the IR. This is unfortunately not documented in a single place but is partially described in a couple of places:
https://github.com/wala/WALA/wiki/Slicer#warning-exclusion-of-copy-statements-from-slice https://github.com/wala/WALA/wiki/Mapping-to-source-code#mapping-value-numbers-back-to-local-names
In retrospect, it's not clear using SSA form was the right decision for a static analysis framework like WALA, but it would be a hard decision to undo now. In the WALA IR you will mostly find instructions involving statements like method calls, pointer dereferences, and control flow, but not copies of values of primitive type.
I hope that helps; let me know if you have further questions.
@Chaoshuai-Li thanks for the question. You're right that there is a difference in the IRs. WALA's IR is in SSA form and copy propagation is formed during SSA construction. So, copies of local variables and writing of constants to locals is not preserved in the IR. This is unfortunately not documented in a single place but is partially described in a couple of places:
https://github.com/wala/WALA/wiki/Slicer#warning-exclusion-of-copy-statements-from-slice https://github.com/wala/WALA/wiki/Mapping-to-source-code#mapping-value-numbers-back-to-local-names
In retrospect, it's not clear using SSA form was the right decision for a static analysis framework like WALA, but it would be a hard decision to undo now. In the WALA IR you will mostly find instructions involving statements like method calls, pointer dereferences, and control flow, but not copies of values of primitive type.
I hope that helps; let me know if you have further questions.
Thank you for your prompt and patient response, I am currently refactoring my software to accommodate the Java API update, so these local variables are really important to me as well. Perhaps this requires me to change my thinking about refactoring. But it is true that WALA has been a great help to me in my previous refactorings with the aim of optimizing programs.
@Chaoshuai-Li if you describe more what facts you are trying to compute about local variables, possibly I can help in figuring out if you can do what you need with WALA. Just let me know.
@msridhar I appreciate your taking such an interest in my problem, it is truly an honor.
As you know the recent Java18 introduced a lot of new uses for multi-branch statements (such as if...else... and switch), and I am trying to provide some automatic refactoring tools for this. In the process, we have found that some of the actual programs have unreasonable multi-branch statement judgment structures, and some even unintentionally increase the depth of judgment. I am trying to construct the control flow automaton for that multi-branch statement corresponding to the contents of the AST. Based on this automaton I will try to optimize the judgment structure of the multi-branch statement and even reduce its unnecessary circle complexity.
Although the idea is not prudent enough, I still hope that static analysis will help me to construct this well-established control flow automaton, and not just through AST traversal. The automaton will guide the refactoring tool to complete the automatic refactoring of the source program. My idea is still in the validation phase as well as I am trying to figure out how to map the control flow information with the AST content.
@Chaoshuai-Li if you only need to do intra-procedural dataflow analysis, I suggest taking a look at the Checker Dataflow library:
https://checkerframework.org/manual/checker-framework-dataflow-manual.pdf
It works on the ASTs computed by javac itself. So to use it, you could write an annotation processor that computes control-flow graphs for methods as they are being compiled and then writes out whatever information you need regarding the control flow.
@msridhar I received your suggestion and will read it now, I think it will be very helpful to me.
Dear Professor, do you have some mentoring projects to share? Although I am very interested in static program analysis, the lack of guides and partners has made it really slow to learn.
I'm already following you on GitHub and really hope to have the opportunity to consult you again.
Recently I was starting to study WALA and was intrigued by his pointer analysis. However, it has recently dawned on me that there is information in his IR that I cannot understand. Here is the source code for the IR I am trying to generate.
Using the Jimple IR as an example, the intermediate code can be represented as follows:
But in WALA IR and CFG, when I traverse Instructions I can't find any procedure for the local variables 'a' and 'b'. I don't understand if this has been removed by optimization or if there is something wrong with the way I have built it?
Very much looking forward to your response, although I'm not sure if this is an inexperienced question to ask, thanks.