Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

unsupported inline asm: input with type 'long' matching output with type 'int' #14426

Open Quuxplusone opened 11 years ago

Quuxplusone commented 11 years ago
Bugzilla Link PR14408
Status NEW
Importance P enhancement
Reported by Zhenbo Xu (zhenbo1987@gmail.com)
Reported on 2012-11-22 01:42:59 -0800
Last modified on 2015-08-18 20:53:36 -0700
Version trunk
Hardware PC Linux
CC anton@korobeynikov.info, jtony@ca.ibm.com, llvm-bugs@lists.llvm.org, pawel@32bitmicro.com, rafael@espindo.la
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
clang generate error instead of warning in the following testcase.

TestCase:
static inline __attribute__((no_instrument_function)) int ffs(int x)
{
   int r;
   long tmp = -1;
   asm("bsfl %1,%0"
       : "=r" (r)
       : "rm" (x), "0" (tmp));
   return r + 1;
}
Quuxplusone commented 11 years ago

The error is correct per se. The code is buggy and needs to be fixed.

Quuxplusone commented 11 years ago
The code is from linux kernel 3.5.4. gcc don't generate this error.
(In reply to comment #1)
> The error is correct per se. The code is buggy and needs to be fixed.
Quuxplusone commented 9 years ago
The test case here is indeed buggy. Because it is not good to cast long to int.
However, I met a similar problem. Clang cannot cast int to long, which I think
can be improved. The test case is as follows:

void VALGRIND_PRINTF(const char *format, ...)
{
   unsigned long _qzz_res = ({
        unsigned long long  int _zzq_result;
         __asm__ volatile("lgr 3,%1"
                        : "=d" (_zzq_result)
                        : "0" (0)
                        );
         _zzq_result; });
}

error: unsupported inline asm: input with type 'int' matching output with type
'volatile unsigned long long'
                        : "0" (0)
                               ^

In this case, if we can cast 0 to unsigned long long  int, there will be no
error.