Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Singlepath: wrong execution when returning from loop #20

Open
Emoun opened this issue Feb 21, 2019 · 0 comments
Open

Singlepath: wrong execution when returning from loop #20

Emoun opened this issue Feb 21, 2019 · 0 comments

Comments

@Emoun
Copy link
Member

Emoun commented Feb 21, 2019

If we compile a program using single-path, and that program includes a conditional return inside a loop, the resulting executable will produce the wrong result.
Take this program (main.c):

#include <stdio.h>

volatile int _7 = 7;

int init_func(int x){
  #pragma loopbound min 0 max 5
  while(x > 0){
    if(x == _7){
      return x;
    }
    x--;
  }
  x += 10;
  return x;
}

int main(){
  int x;
  scanf("%d", &x);
  printf("%d\n", init_func(x));
}

The program should print 10 if given an input integer below 7 and 7 otherwise. (the highest input integer allowed is 13). But, if compiled with the command patmos-clang main.c -mpatmos-singlepath and run on pasim with the command echo 6 | pasim a.out, the result is 0 (should be 10).
For all other inputs the result is correct. For some reason, when x starts out at 6, the x += 10; is skipped.

This error is similar to #19, so they might be caused by the same bug.

We might also note, that if the above program did not have the loop bound pragma, it would compile and execute correctly. However, this is because, without a loop bound, the loop is not generated as single-path code.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant