[cfe-dev] How to prevent insertion of memcpy()

Dmitry Vyukov dvyukov at google.com
Tue May 29 23:56:24 PDT 2012


On Wed, May 30, 2012 at 8:30 AM, Chris Lattner <clattner at apple.com> wrote:

>
> On May 29, 2012, at 9:51 AM, Dmitry Vyukov wrote:
>
> Hi,
>
> I have the following program:
>
> // test.c
> #include <stdlib.h>
>  struct foo_t {
>   int x[1024];
> };
> __thread struct foo_t g_foo;
> void bar(struct foo_t* foo) {
>   g_foo = *foo;
> }
> int main() {
>   struct foo_t* f = (struct foo_t*)malloc(sizeof(struct foo_t));
>   bar(f);
>   return 0;
> }
>
> When I compile it with clang I see that it inserts memcpy() in function
> bar():
>
>
> Hi Dmitry,
>
> Short answer: you can't.  Freestanding implementations are required to
> provide memcpy.
>
>
Hi Chris,

I understand that a freestanding impl must provide memcpy(). But I think
it's somewhat orthogonal to actual insertion of the function calls. For
example, it's legal to compile with -O0 and with -O3, but I think a
conforming compiler that always compiles with -O3 w/o any means to override
that would not be that useful. So I thought maybe there is some flag that
control insertion of memcpy's, perhaps a hacky flag that turns off the
particular pass.

Meanwhile I will try Chandler's solution.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120530/755329e7/attachment.html>


More information about the cfe-dev mailing list