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

clava.opt.NormalizeToSubset crashes when using global variables #107

Open
lm-sousa opened this issue Oct 19, 2022 · 0 comments
Open

clava.opt.NormalizeToSubset crashes when using global variables #107

lm-sousa opened this issue Oct 19, 2022 · 0 comments
Labels

Comments

@lm-sousa
Copy link
Member

lm-sousa commented Oct 19, 2022

The following C code

int global_i = 0;
void print_matrix_result(double *A, const int N, const int K) {
	double acc = 0.0;
	while (global_i) {
		for (int j = 0; j < K; ++j) {
			//acc += A[i][j];
			acc += A[K*global_i + j];
		}
		global_i = 0;
	}
	printf("Result acc: %f\n", acc);
}

When combined with the JS script:

"use strict";

laraImport("clava.opt.NormalizeToSubset");
laraImport("clava.code.Inliner");

laraImport("weaver.WeaverJps");
laraImport("weaver.TraversalType");
laraImport("weaver.Query");

// Normalize all code
NormalizeToSubset(Query.root());

Crashes and throws the following error. Execution is halted without any code output:

!Problems while running Clava:

 During LARA Interpreter execution 
  
   when closing the weaver
    Cannot cast pt.up.fe.specs.clava.ast.stmt.ExprStmt to pt.up.fe.specs.clava.ast.decl.Decl
   Cannot cast pt.up.fe.specs.clava.ast.stmt.ExprStmt to pt.up.fe.specs.clava.ast.decl.Decl

The problem appears to be due to poor handling of the global variable global_i. If its declaration is moved to inside the function, making it a local variable, the error no longer manifests itself.

@lm-sousa lm-sousa added the bug label Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant