[Beignet] [PATCH] Fix compiler error
Jan Beich
jbeich at vfemail.net
Thu Jul 20 03:50:35 UTC 2017
yyc1992 at gmail.com writes:
> From: Yichao Yu <yyc1992 at gmail.com>
>
> There's no overload for `std::abs` or `abs` that takes `unsigned int` as input so this causes
> an ambiguity when both `std::abs` and `abs` are available in the namespace.
> Explicitly cast the `unsigned int` to `int` to resolve the ambiguity.
[...]
> unsigned int s0 = src0.value.ud;
> if (src0.absolute)
> - s0 = abs(s0);
> + s0 = abs((int)s0);
Can you add `assert(s0 <= INT_MAX)` before abs() call? Otherwise, a value
between INT_MAX and UINT_MAX may overflow `int` (or `long` with -m32).
$ cat >a.cc
#include <climits>
#include <iostream>
int main()
{
unsigned int s0 = UINT_MAX;
s0 = std::abs((int)s0);
std::cout << s0 << std::endl;
return 0;
}
$ c++ a.cc
$ ./a.out
1
More information about the Beignet
mailing list