FD_ZERO unsupported inline asm on 64 bit

Hello,

I get this error when compiling this code with llvm-gcc:
error: unsupported inline asm: input constraint with a matching output constraint of incompatible type!

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

int
main(void)
{
  fd_set rfds;
  FD_ZERO(&rfds); //this is the error line
  return 0;
}

I used llvm-2.6 compiled from source and the latest llvm-gcc binaries for Linux x86_64.
This code worked just fine with older versions of llvm-gcc on 32 bit Linux.

FD_ZERO is defined in /usr/include/bits/select.h like this:

# if __WORDSIZE == 64
# define __FD_ZERO_STOS "stosq"
# define __FD_SET_BTS "btsq"
# define __FD_CLR_BTR "btrq"
# define __FD_ISSET_BT "btq"
# else
# define __FD_ZERO_STOS "stosl"
# define __FD_SET_BTS "btsl"
# define __FD_CLR_BTR "btrl"
# define __FD_ISSET_BT "btl"
# endif

# define __FD_ZERO(fdsp) \
  do { \
    int __d0, __d1; \
    __asm__ __volatile__ ("cld; rep; " __FD_ZERO_STOS \
                          : "=c" (__d0), "=D" (__d1) \
                          : "a" (0), "0" (sizeof (fd_set) \
                                          / sizeof (__fd_mask)), \
                            "1" (&__FDS_BITS (fdsp)[0]) \
                          : "memory"); \
  } while (0)

Thanks,
Cristi

Hi Cristian, this is (part of) bug 3373, see
   http://llvm.org/bugs/show_bug.cgi?id=3373

  FD_ZERO(&rfds); //this is the error line

...

# define __FD_ZERO(fdsp) \
  do { \
    int __d0, __d1; \
    __asm__ __volatile__ ("cld; rep; " __FD_ZERO_STOS \
                          : "=c" (__d0), "=D" (__d1) \
                          : "a" (0), "0" (sizeof (fd_set) \
                                          / sizeof (__fd_mask)), \
                            "1" (&__FDS_BITS (fdsp)[0]) \
                          : "memory"); \
  } while (0)

That said, this is an odd way to implement FD_ZERO. The crazy asm is equivalent
to a simple memset...

Ciao,

Duncan.

PS: The underlying problem here is probably that __d0 and __d1 are declared as
int, which is only 32 bits in size, while the asm is expecting 64 bits.

Thanks Duncan,

It seems the bug has been reopened. After reading the comments related to the bug report, it was not clear if this is fixed in llvm-gcc, or just in clang.

Thanks,
Cristi

Hi Cristi,

It seems the bug has been reopened. After reading the comments related to the bug report, it was not clear if this is fixed in llvm-gcc, or just in clang.

it has been fixed in clang but not in llvm-gcc.

Ciao,

Duncan.

it has been fixed in clang but not in llvm-gcc.

I believe I fixed it in llvm-gcc via fixincludes :slight_smile: Not the best way, but...

Anton Korobeynikov wrote:

it has been fixed in clang but not in llvm-gcc.

I believe I fixed it in llvm-gcc via fixincludes :slight_smile: Not the best way, but...

For example, it doesn't help dragonegg unless the fixincludes patch goes
upstream.

Ciao,

Duncan.