What steps will reproduce the problem?
1. Compile attached file: javac -g -cp
${APARAPI_HOME}/com.amd.aparapi/dist/aparapi.jar Nested.java
2. Execute: java -cp .:${APARAPI_HOME}/com.amd.aparapi/dist/aparapi.jar Nested
This will produce an error message during clBuildProgram of the generated
OpenCL kernel indicating that i is not declared. The generated kernel will be
something like:
int k = 2;
if (k<3){
int i = 2;
} else {
int i = 4;
}
k = i;
because APARAPI misidentifies the scope of i due to its initialization in a
nested scope. This is primarily caused by the implementation of
AssignToLocalVariable.isDeclaration() causing the generation of a variable
declaration only at the point where it is initialized and not earlier as
needed, as well as misidentifying a point in a program's control flow as
earlier purely based on bytecode index.
As far as I can tell, this should be independent of platform.
The hack I put in place to fix this gathers the APARAPI-identified declarations
in a block, as well as the assignments and searches for variables which are
declared in one branch of a condition and assigned in another (indicating
misidentification of the declaration). I do believe a more robust solution will
be required to handle more general cases where this might occur by calculating
scope for a local (for instance, I believe Issue 84 is related to this problem).
I've attached a diff to show the changes made to BlockWriter.java
Original issue reported on code.google.com by jmaxg3@gmail.com on 11 Jan 2013 at 3:38
Original issue reported on code.google.com by
jmaxg3@gmail.com
on 11 Jan 2013 at 3:38Attachments: