[LLVMbugs] [Bug 24025] New: array-bounds warning generated on correct usage of strspn/strcspn

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jul 3 07:49:54 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24025

            Bug ID: 24025
           Summary: array-bounds warning generated on correct usage of
                    strspn/strcspn
           Product: clang
           Version: 3.5
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: charles.unix.pro at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Calls to strcpn or strcspn with -O3 generate code which is flagged an array
bounds violation.

#include <string.h>
size_t foo (char * buf)
  {
    return strspn (buf, ":");
  }

$ clang -O3 -c test.c -v
clang version 3.5.0 (tags/RELEASE_350/final)
Target: x86_64-redhat-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/5.1.1
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
 "/usr/bin/clang" -cc1 -triple x86_64-redhat-linux-gnu -E -disable-free
-disable-llvm-verifier -main-file-name test.c -mrelocation-model static
-fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables
-fuse-init-array -target-cpu x86-64 -target-linker-version 2.25
-momit-leaf-frame-pointer -v -dwarf-column-info -resource-dir
/usr/bin/../lib/clang/3.5.0 -internal-isystem /usr/local/include
-internal-isystem /usr/bin/../lib/clang/3.5.0/include -internal-externc-isystem
/usr/include -internal-externc-isystem
/usr/lib/gcc/x86_64-redhat-linux/5.0.0/include -O3 -fdebug-compilation-dir
/home/cac -ferror-limit 19 -fmessage-length 0 -mstackrealign -fobjc-runtime=gcc
-fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp
-o - -x c test.c
clang -cc1 version 3.5.0 based upon LLVM 3.5.0 default target
x86_64-redhat-linux-gnu
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/5.0.0/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/bin/../lib/clang/3.5.0/include
 /usr/include
End of search list.
clang version 3.5.0 (tags/RELEASE_350/final)
Target: x86_64-redhat-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/5.1.1
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
 "/usr/bin/clang" -cc1 -triple x86_64-redhat-linux-gnu -emit-obj -disable-free
-disable-llvm-verifier -main-file-name test.stdout.sve-vm-1.2052.UbQOax.i
-mrelocation-model static -fmath-errno -masm-verbose -mconstructor-aliases
-munwind-tables -fuse-init-array -target-cpu x86-64 -target-linker-version 2.25
-momit-leaf-frame-pointer -v -dwarf-column-info -coverage-file /home/cac/test.o
-resource-dir /usr/bin/../lib/clang/3.5.0 -O3 -fdebug-compilation-dir /home/cac
-ferror-limit 19 -fmessage-length 0 -mstackrealign -fobjc-runtime=gcc
-fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp
-o test.o -x cpp-output
/home/cac/.ccache/tmp/test.stdout.sve-vm-1.2052.UbQOax.i
clang -cc1 version 3.5.0 based upon LLVM 3.5.0 default target
x86_64-redhat-linux-gnu
#include "..." search starts here:
End of search list.
test.c:4:477: warning: array index 2 is past the end of the array (which
contains 2 elements) [-Warray-bounds]
    return __extension__ ({ char __a0, __a1, __a2; (__builtin_constant_p (":")
&& ((size_t)(const void *)((":") + 1) - (size_t)(const void *)(":") == 1) ?
((__builtin_constant_p (buf) && ((size_t)(const void *)((buf) + 1) -
(size_t)(const void *)(buf) == 1)) ? __builtin_strspn (buf, ":") : ((__a0 =
((const char *) (":"))[0], __a0 == '\0') ? ((void) (buf), (size_t) 0) : ((__a1
= ((const char *) (":"))[1], __a1 == '\0') ? __strspn_c1 (buf, __a0) : ((__a2 =
((const char *) (":"))[2], __a2 == '\0') ? __strspn_c2 (buf, __a0, __a1) :
(((const char *) (":"))[3] == '\0' ? __strspn_c3 (buf, __a0, __a1, __a2) :
__builtin_strspn (buf, ":")))))) : __builtin_strspn (buf, ":")); });
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                            ^  
  ~
test.c:4:553: warning: array index 3 is past the end of the array (which
contains 2 elements) [-Warray-bounds]
    return __extension__ ({ char __a0, __a1, __a2; (__builtin_constant_p (":")
&& ((size_t)(const void *)((":") + 1) - (size_t)(const void *)(":") == 1) ?
((__builtin_constant_p (buf) && ((size_t)(const void *)((buf) + 1) -
(size_t)(const void *)(buf) == 1)) ? __builtin_strspn (buf, ":") : ((__a0 =
((const char *) (":"))[0], __a0 == '\0') ? ((void) (buf), (size_t) 0) : ((__a1
= ((const char *) (":"))[1], __a1 == '\0') ? __strspn_c1 (buf, __a0) : ((__a2 =
((const char *) (":"))[2], __a2 == '\0') ? __strspn_c2 (buf, __a0, __a1) :
(((const char *) (":"))[3] == '\0' ? __strspn_c3 (buf, __a0, __a1, __a2) :
__builtin_strspn (buf, ":")))))) : __builtin_strspn (buf, ":")); });
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                        ^     ~
2 warnings generated.

-- 
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/20150703/effaebd3/attachment.html>


More information about the llvm-bugs mailing list