<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - inlines with names matching __builtin_* have entire function body removed when calling builtin"
   href="https://bugs.llvm.org/show_bug.cgi?id=50322">50322</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>inlines with names matching __builtin_* have entire function body removed when calling builtin
          </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>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </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>keescook@chromium.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre><a href="https://godbolt.org/z/fs9q55daM">https://godbolt.org/z/fs9q55daM</a>


typedef unsigned long size_t;
void fortify_panic(void) __attribute__((noreturn)); 

#ifndef USE_BUILTIN
extern void *memcpy_implementation(void *p, const void *q, size_t size);
#define __underlying_memcpy memcpy_implementation
#else
#define __underlying_memcpy __builtin_memcpy
#endif

// inlines with names matching a __builtin_* have their entire
// contents ignored when the matching __builtin is called anywhere
// in the function, regardless to conditionals or outcomes.
// If this isn't named "memcpy" or it doesn't ultimately call
// "__builtin_memcpy" it will work correctly.
inline void *memcpy(void *p, const void *q, size_t size)
{
        size_t p_size = __builtin_object_size(p, 0);

        if (p_size < size)
                fortify_panic();
        if (size > 4)
            __underlying_memcpy(p, q, size);
        return 0;
}

static char buf[8];

void *maybe_overflow(char *src, size_t size)
{
    return memcpy(buf, src, size);
}

void *always_overflow(char *src)
{
    return memcpy(buf, src, 16);
}


With -DUSE_BUILTIN all of the memcpy logic vanishes.</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>