<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW " title="NEW --- - array-bounds warning generated on correct usage of strspn/strcspn" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24025&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=4cQG98mSvVaykCqqUtByyjRK6oqv_A_ftHh4naz-P1g&s=enL8WmgqQTllxP6h1YxLCkWi78xe4xq5NXoblecz9qM&e=">24025</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>array-bounds warning generated on correct usage of strspn/strcspn
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.5
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>charles.unix.pro@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>