<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 --- - clang -mkernel/-ffreestanding/-fno-builtin evaluates "__has_builtin(__builtin___memcpy_chk)" as true"
   href="https://llvm.org/bugs/show_bug.cgi?id=23093">23093</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang -mkernel/-ffreestanding/-fno-builtin evaluates  "__has_builtin(__builtin___memcpy_chk)" as true
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </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>ahmed.bougacha@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>__has_builtin currently disregards -mkernel/-ffreestanding/-fno-builtin for the
various __builtin_s.  I tried with __builtin_memcpy_chk and __builtin_expect,
and they're always marked as available.  

For the latter that's perfectly fine (as it is for most __builtin_s), but is it
also for the _chk functions?  We provide them as builtins, but they really are
functions, so perhaps an exception is acceptable.

One alternative would be to tell users to check for freestanding/kernel, but
that's a bit contrived when there's the more descriptive __has_builtin.



 $ cat builtin.c                                                               
                                                                               
                                                                               
                                                                               
     #if __has_builtin(__builtin___memcpy_chk)
#warning "__memcpy_chk is available"
#else
#warning "__memcpy_chk is not available"
#endif

 $ clang ./builtin.c -fsyntax-only -fno-builtin                                
                                                                               
                                                                               
                                                                              
./builtin.c:2:2: warning: "__memcpy_chk is available" [-W#warnings]
#warning "__memcpy_chk is available"
 ^
1 warning 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>