This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug sanitizer/81598] New: -fsanitize=enum does not detect range violation
- From: "tim.ruehsen at gmx dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 28 Jul 2017 09:01:34 +0000
- Subject: [Bug sanitizer/81598] New: -fsanitize=enum does not detect range violation
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81598
Bug ID: 81598
Summary: -fsanitize=enum does not detect range violation
Product: gcc
Version: 7.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: sanitizer
Assignee: unassigned at gcc dot gnu.org
Reporter: tim.ruehsen at gmx dot de
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, marxin at gcc dot gnu.org
Target Milestone: ---
g++'s (nor gcc's) -fsanitize=enum doesn't detect enum range violation.
The documentation says that it does.
Having this little C/C++ code (enum_undef.cc):
#include <stdio.h>
typedef enum {
FLAG1 = (1 << 0),
FLAG2 = (1 << 1),
} flag_t;
int main(void)
{
int x = 5;
flag_t flags = (flag_t) x;
printf("flags = %X\n", flags);
return 0;
}
$ g++-7 -fsanitize=undefined -fsanitize=enum enum_undef.cc
$ $ ./a.out
flags = 5
In comparison, clang detects this kind of violation:
$ clang++-5.0 -fsanitize=undefined -fsanitize=enum enum_undef.cc
$ ./a.out
enum_undef.cc:13:25: runtime error: load of value 5, which is not a valid value
for type 'flag_t'
flags = 5
Adding -fno-sanitize-recover doesn't make a difference for gcc/g++.