Skip to content
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

Incorrect shape propagation when resizing arrays in loops with breaks #11

Open
nassifm opened this issue Dec 30, 2016 · 0 comments
Open

Comments

@nassifm
Copy link

nassifm commented Dec 30, 2016

When an array is resized in a loop that contains a control flow statement, such as a break statement, the shape of the array is sometimes incorrect.

For example, I have the following MATLAB function:

function y = test
	t1 = 1;
	t2 = 20;
	t3 = 10;
	for i = t1:t2
		y(i) = t1;
		if i > t3
			break;
		end
	end
end

The array y is resized inside the loop, which iterates from 1 to 20, but breaks after 10, so it really iterates from 1 to 11.
And this is what I get when I print the callgraph:

% args: {}
function  [y] = test()
  t1 = 1;                             % t1=(t1,double,1.0,[1, 1],<1, 1>,REAL)
  t2 = 20;                            % t2=(t2,double,20.0,[1, 1],<20, 20>,REAL)
  t3 = 10;                            % t3=(t3,double,10.0,[1, 1],<10, 10>,REAL)
  for i = (t1 : t2);
    y(i) = t1;                          % y=(t1,double,[1, 20],REAL)
    [mc_t0] = gt(i, t3);                % mc_t0=(logical,[1, 1],REAL)
    if mc_t0
      break;
    else
    end
  end
end
% results: [(t1,double,[1, 20],REAL)]

The size of y is marked as [1,20], which is incorrect. It should ideally be [1,11], but [1,?] is probably more realistic.

(Here's the Java code I used)

public static void main(String... args) {
	GenericFile gf = GenericFile.create(new File("dev/test.m"));
	FileEnvironment fe = new FileEnvironment(gf);
	Callgraph<BasicMatrixValue> cg = new Callgraph<BasicMatrixValue>(fe,
			new Args<>(Collections.emptyList()),
			new BasicMatrixValueFactory());
	System.out.println(cg.prettyPrint());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant