[llvm-bugs] [Bug 28583] New: Clang warnings for optimizations in GCC string.h
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Jul 16 03:31:36 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=28583
Bug ID: 28583
Summary: Clang warnings for optimizations in GCC string.h
Product: clang
Version: 3.8
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: jibz-llvmbugs at stdip.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Created attachment 16751
--> https://llvm.org/bugs/attachment.cgi?id=16751&action=edit
Output of clang -E -frewrite-includes -O2 -c foo.c
Compiling foo.c:
#include <string.h>
int main() { (void) strspn("foo", "f"); }
on Linux with `clang -O2 -c foo.c' results in:
[jibsen at localhost build]$ clang -O2 -c foo.c
foo.c:2:498: warning: array index 2 is past the end of the array (which
contains 2 elements) [-Warray-bounds]
int main() { (void) __extension__ ({ char __a0, __a1, __a2;
(__builtin_constant_p ("f") && ((size_t)(const void *)(("f") + 1) -
(size_t)(const void *)("f") == 1) ? ((__builtin_constant_p ("foo") &&
((size_t)(const void *)(("foo") + 1) - (size_t)(const void *)("foo") == 1)) ?
__builtin_strspn ("foo", "f") : ((__a0 = ((const char *) ("f"))[0], __a0 ==
'\0') ? ((void) ("foo"), (size_t) 0) : ((__a1 = ((const char *) ("f"))[1], __a1
== '\0') ? __strspn_c1 ("foo", __a0) : ((__a2 = ((const char *) ("f"))[2], __a2
== '\0') ? __strspn_c2 ("foo", __a0, __a1) : (((const char *) ("f"))[3] == '\0'
? __strspn_c3 ("foo", __a0, __a1, __a2) : __builtin_strspn ("foo", "f")))))) :
__builtin_strspn ("foo", "f")); }); }
^ ~
foo.c:2:576: warning: array index 3 is past the end of the array (which
contains 2 elements) [-Warray-bounds]
int main() { (void) __extension__ ({ char __a0, __a1, __a2;
(__builtin_constant_p ("f") && ((size_t)(const void *)(("f") + 1) -
(size_t)(const void *)("f") == 1) ? ((__builtin_constant_p ("foo") &&
((size_t)(const void *)(("foo") + 1) - (size_t)(const void *)("foo") == 1)) ?
__builtin_strspn ("foo", "f") : ((__a0 = ((const char *) ("f"))[0], __a0 ==
'\0') ? ((void) ("foo"), (size_t) 0) : ((__a1 = ((const char *) ("f"))[1], __a1
== '\0') ? __strspn_c1 ("foo", __a0) : ((__a2 = ((const char *) ("f"))[2], __a2
== '\0') ? __strspn_c2 ("foo", __a0, __a1) : (((const char *) ("f"))[3] == '\0'
? __strspn_c3 ("foo", __a0, __a1, __a2) : __builtin_strspn ("foo", "f")))))) :
__builtin_strspn ("foo", "f")); }); }
^ ~
2 warnings generated.
I haven'd dug through the macros, but I assume Clang is not supposed to
generate warnings for standard functions, at least without any warning flags.
Attached is output of clang -E -frewrite-includes.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160716/df6227d0/attachment.html>
More information about the llvm-bugs
mailing list