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

            Bug ID: 42996
           Summary: Inline assembly incompatibility with gcc for array
                    parameters
           Product: clang
           Version: 8.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangb...@nondot.org
          Reporter: j...@alien8.de
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@metafoo.co.uk

Consider the following memcpy example that is adapted from the GCC
documentation [1]:

#include <stddef.h>

void* memcpy(void* dst, const void* src, size_t n)
{
    void *orig_dst = dst;

    asm ("rep movsb"
         : "+S" (src), "+D" (dst), "+c" (n),
           "=m" (*(char (*)[]) dst)
         : "m" (*(const char (*)[]) src));

    return orig_dst;
}

Array types is used to denote array parameters of unknown length. This works
fine on GCC, but results in the following error on clang:

string.c:10:17: error: dereference of pointer to incomplete type 'const char
[]'
         : "m" (*(const char (*)[]) src));

The fix seems to be to cast to `(char (*)[n])` instead and this also works on
GCC. It's just unfortunate that the example from the gcc documentation is
broken on clang.

[1] See repne scasb here: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html

-- 
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