[llvm-bugs] [Bug 50322] New: inlines with names matching __builtin_* have entire function body removed when calling builtin

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 12 11:44:32 PDT 2021


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

            Bug ID: 50322
           Summary: inlines with names matching __builtin_* have entire
                    function body removed when calling builtin
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: keescook at chromium.org
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

https://godbolt.org/z/fs9q55daM


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.

-- 
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/20210512/46819d87/attachment.html>


More information about the llvm-bugs mailing list