Constraint violation bug
With this code and -check c enabled:
int main() {
a = [[1.0f,2.0f,3.0f],[2.0f,1.0f,2.0f],[3.0f,2.0f,1.0f]];
b = foo( 3, a, [0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f]);
return _toi_S_(b[[0]]);
}
float[m] foo(int n, float[n,n] a, float[m] ap)
{
k = 0;
for (j=0; _lt_SxS_(j,n); j = _add_SxS_(j,1))
{
for (i=j; _lt_SxS_(i,n); i = _add_SxS_(i,1))
{
ap = _modarray_AxVxS_(ap, [k],a[[i,j]]);
k = _add_SxS_(k,1);
}
}
return ap;
}
float[*] sel( int[.] idx, float[*] array)
{
new_shape = _drop_SxV_( _sel_VxA_( [0], _shape_A_(idx)),
_shape_A_(array));
res = with {
( . <= iv <= . ) {
new_idx = _cat_VxV_( idx, iv);
} : _sel_VxA_(new_idx, array);
} : genarray( new_shape, 0.0f);
return( res);
}
We get this error message:
*** SAC runtime warning
*** In ./test/trttpBug.sac, line 62, column 15
*** Scalar constraint `SACp_emal_8200__uprf_2410 (0) < SACp_emal_8195__uprf_2397 (0)' violated
*** SAC runtime warning
*** In ./test/trttpBug.sac, line 62, column 15
*** Scalar constraint `SACp_emal_8198__uprf_2415 (0) < SACp_emal_8193__uprf_2404 (0)' violated
*** SAC runtime error
*** In ./test/trttpBug.sac, line 62, column 15
*** Primitive function _sel_VxA_ guard failed
Removing the 'n' parameter like so:
int main() {
a = [[1.0f,2.0f,3.0f],[2.0f,1.0f,2.0f],[3.0f,2.0f,1.0f]];
b = foo( a, [0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f]);
return _toi_S_(b[[0]]);
}
float[m] foo(float[n,n] a, float[m] ap)
{
k = 0;
for (j=0; _lt_SxS_(j,n); j = _add_SxS_(j,1))
{
for (i=j; _lt_SxS_(i,n); i = _add_SxS_(i,1))
{
ap = _modarray_AxVxS_(ap, [k],a[[i,j]]);
k = _add_SxS_(k,1);
}
}
return ap;
}
float[*] sel( int[.] idx, float[*] array)
{
new_shape = _drop_SxV_( _sel_VxA_( [0], _shape_A_(idx)),
_shape_A_(array));
res = with {
( . <= iv <= . ) {
new_idx = _cat_VxV_( idx, iv);
} : _sel_VxA_(new_idx, array);
} : genarray( new_shape, 0.0f);
return( res);
}
Gives a different error, namely:
*** SAC runtime warning
*** In ./test/trttpBug.sac, line 7, column 1
*** Type pattern error in definition of foo: the found value of `m' in `m' of return value is not equal to the defined value of `m'
*** SAC runtime error
*** In ./test/trttpBug.sac, line 7, column 1
*** One or more type pattern post-conditions of foo failed
Expectation: the code should work as it does without -check c. Version: sac2c 1.3.3-MijasCosta-1208-g8c73d build-type: RELEASE built-by: "rubenhensen" at 2024-04-26T18:47:46