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: unassignedclangb...@nondot.org
          Reporter: keesc...@chromium.org
                CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org,
                    neeil...@live.com, richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to