This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug sanitizer/71611] New: UBSan shows type '<unknown>' for enums based on long
- From: "ch3root at openwall dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 21 Jun 2016 19:02:50 +0000
- Subject: [Bug sanitizer/71611] New: UBSan shows type '<unknown>' for enums based on long
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71611
Bug ID: 71611
Summary: UBSan shows type '<unknown>' for enums based on long
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: sanitizer
Assignee: unassigned at gcc dot gnu.org
Reporter: ch3root at openwall dot com
CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
jakub at gcc dot gnu.org, kcc at gcc dot gnu.org
Target Milestone: ---
Source code:
----------------------------------------------------------------------
#include <limits.h>
int main()
{
enum { c = LONG_MIN } x = c;
x = -x;
return x;
}
----------------------------------------------------------------------
Results:
----------------------------------------------------------------------
$ gcc -std=c11 -pedantic -Wall -Wextra -O3 -fsanitize=undefined test.c &&
./a.out
test.c:6:5: runtime error: negation of -9223372036854775808 cannot be
represented in type '<unknown>'; cast to an unsigned type to negate this value
to itself
----------------------------------------------------------------------
gcc version: gcc (GCC) 7.0.0 20160616 (experimental)
For comparison:
----------------------------------------------------------------------
$ clang -std=c11 -Weverything -O3 -fsanitize=undefined test.c && ./a.out
test.c:5:10: warning: ISO C restricts enumerator values to range of 'int'
(-9223372036854775808 is too small) [-Wpedantic]
enum { c = LONG_MIN } x = c;
^ ~~~~~~~~
test.c:7:10: warning: implicit conversion loses integer precision: 'enum
(anonymous enum at test.c:5:3)' to 'int' [-Wshorten-64-to-32]
return x;
~~~~~~ ^
2 warnings generated.
test.c:6:7: runtime error: negation of -9223372036854775808 cannot be
represented in type 'long'; cast to an unsigned type to negate this value to
itself
----------------------------------------------------------------------
clang version: clang version 3.9.0 (trunk 271312)