<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 --- - strlen (s) == 0 not folded when return type is casted to unsigned"
   href="https://llvm.org/bugs/show_bug.cgi?id=28833">28833</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>strlen (s) == 0 not folded when return type is casted to unsigned
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.6
          </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>Transformation Utilities
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>prathamesh.kulkarni@linaro.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hi,
For the following test-case, strlen (s) == 0 is not folded to *s == 0.
_Bool f2(const char *s)
{
  unsigned len = __builtin_strlen (s);
  return len == 0;
}

Assembly with clang -O2 -S:
  .text
        .file   "test-2.c"
        .globl  f2
        .align  16, 0x90
        .type   f2,@function
f2:                                     # @f2
        .cfi_startproc
# BB#0:
        pushq   %rax
.Ltmp0:
        .cfi_def_cfa_offset 16
        callq   strlen
        testl   %eax, %eax
        sete    %al
        popq    %rdx
        retq
.Ltmp1:
        .size   f2, .Ltmp1-f2
        .cfi_endproc


        .ident  "Ubuntu clang version 3.6.2-1 (tags/RELEASE_362/final) (based
on LLVM 3.6.2)"
        .section        ".note.GNU-stack","",@progbits

However if type of len is changed from unsigned to unsigned long,
then the transform takes place.
Is there a reason why the transform is disabled if the return
value (unsigned long) is stored in a smaller type (unsigned) ?

Thanks,
Prathamesh</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>