-
Notifications
You must be signed in to change notification settings - Fork 9
Description
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.