2012-08-18 05:44:55 +08:00
// RUN: %clang_cc1 %s -Wno-private-extern -triple i386-pc-linux-gnu -verify -fsyntax-only
2007-11-24 03:43:50 +08:00
2014-06-06 00:45:22 +08:00
2009-03-11 08:06:36 +08:00
void f ( ) {
2007-11-24 03:43:50 +08:00
int i ;
asm ( " foo \n " : : " a " ( i + 2 ) ) ;
asm ( " foo \n " : : " a " ( f ( ) ) ) ; // expected-error {{invalid type 'void' in asm input}}
2011-07-08 07:11:01 +08:00
2007-11-24 03:43:50 +08:00
asm ( " foo \n " : " =a " ( f ( ) ) ) ; // expected-error {{invalid lvalue in asm output}}
asm ( " foo \n " : " =a " ( i + 2 ) ) ; // expected-error {{invalid lvalue in asm output}}
2009-01-18 09:56:57 +08:00
asm ( " foo \n " : [ symbolic_name ] " =a " ( i ) : " [symbolic_name] " ( i ) ) ;
asm ( " foo \n " : " =a " ( i ) : " [ " ( i ) ) ; // expected-error {{invalid input constraint '[' in asm}}
asm ( " foo \n " : " =a " ( i ) : " [foo " ( i ) ) ; // expected-error {{invalid input constraint '[foo' in asm}}
asm ( " foo \n " : " =a " ( i ) : " [symbolic_name] " ( i ) ) ; // expected-error {{invalid input constraint '[symbolic_name]' in asm}}
2013-12-16 11:20:06 +08:00
asm ( " foo \n " : : " " ( i ) ) ; // expected-error {{invalid input constraint '' in asm}}
asm ( " foo \n " : " =a " ( i ) : " " ( i ) ) ; // expected-error {{invalid input constraint '' in asm}}
2007-11-24 03:43:50 +08:00
}
2007-11-25 08:25:21 +08:00
2009-03-11 08:06:36 +08:00
void clobbers ( ) {
2007-11-25 08:25:21 +08:00
asm ( " nop " : : : " ax " , " #ax " , " %ax " ) ;
asm ( " nop " : : : " eax " , " rax " , " ah " , " al " ) ;
asm ( " nop " : : : " 0 " , " %0 " , " #0 " ) ;
asm ( " nop " : : : " foo " ) ; // expected-error {{unknown register name 'foo' in asm}}
asm ( " nop " : : : " 52 " ) ;
2016-02-03 19:32:08 +08:00
asm ( " nop " : : : " 204 " ) ; // expected-error {{unknown register name '204' in asm}}
2007-11-25 08:25:21 +08:00
asm ( " nop " : : : " -1 " ) ; // expected-error {{unknown register name '-1' in asm}}
asm ( " nop " : : : " +1 " ) ; // expected-error {{unknown register name '+1' in asm}}
2016-12-26 20:23:42 +08:00
register void * clobber_conflict asm ( " %rcx " ) ;
register void * no_clobber_conflict asm ( " %rax " ) ;
int a , b , c ;
asm ( " nop " : " =r " ( no_clobber_conflict ) : " r " ( clobber_conflict ) : " %rcx " ) ; // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
asm ( " nop " : " =r " ( clobber_conflict ) : " r " ( no_clobber_conflict ) : " %rcx " ) ; // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
asm ( " nop " : " =r " ( clobber_conflict ) : " r " ( clobber_conflict ) : " %rcx " ) ; // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
asm ( " nop " : " =c " ( a ) : " r " ( no_clobber_conflict ) : " %rcx " ) ; // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
asm ( " nop " : " =r " ( no_clobber_conflict ) : " c " ( c ) : " %rcx " ) ; // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
asm ( " nop " : " =r " ( clobber_conflict ) : " c " ( c ) : " %rcx " ) ; // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
asm ( " nop " : " =a " ( a ) : " b " ( b ) : " %rcx " , " %rbx " ) ; // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
2007-11-25 08:25:21 +08:00
}
2008-07-23 14:46:56 +08:00
// rdar://6094010
void test3 ( ) {
int x ;
asm ( L " foo " : " =r " ( x ) ) ; // expected-error {{wide string}}
asm ( " foo " : L " =r " ( x ) ) ; // expected-error {{wide string}}
}
2009-01-21 04:49:22 +08:00
// <rdar://problem/6156893>
void test4 ( const volatile void * addr )
{
2010-09-05 08:04:01 +08:00
asm ( " nop " : : " r " ( * addr ) ) ; // expected-error {{invalid type 'const volatile void' in asm input for constraint 'r'}}
2009-01-21 04:49:22 +08:00
asm ( " nop " : : " m " ( * addr ) ) ;
asm ( " nop " : : " r " ( test4 ( addr ) ) ) ; // expected-error {{invalid type 'void' in asm input for constraint 'r'}}
asm ( " nop " : : " m " ( test4 ( addr ) ) ) ; // expected-error {{invalid lvalue in asm input for constraint 'm'}}
2009-01-21 14:27:20 +08:00
asm ( " nop " : : " m " ( f ( ) ) ) ; // expected-error {{invalid lvalue in asm input for constraint 'm'}}
}
// <rdar://problem/6512595>
2009-03-11 07:51:40 +08:00
void test5 ( ) {
2011-07-08 07:11:01 +08:00
asm ( " nop " : : " X " ( 8 ) ) ;
2009-01-21 04:49:22 +08:00
}
2009-01-25 02:03:09 +08:00
// PR3385
2009-03-11 07:51:40 +08:00
void test6 ( long i ) {
2009-01-25 02:03:09 +08:00
asm ( " nop " : : " er " ( i ) ) ;
2009-01-28 04:38:24 +08:00
}
2009-03-11 07:51:40 +08:00
2009-03-11 08:23:13 +08:00
void asm_string_tests ( int i ) {
2011-07-08 07:11:01 +08:00
asm ( " %! " ) ; // simple asm string, %! is not an error.
2009-03-11 07:51:40 +08:00
asm ( " %! " : ) ; // expected-error {{invalid % escape in inline assembly string}}
2009-03-11 08:06:36 +08:00
asm ( " xyz % " : ) ; // expected-error {{invalid % escape in inline assembly string}}
asm ( " %[somename] " : : [ somename ] " i " ( 4 ) ) ; // ok
asm ( " %[somename] " : : " i " ( 4 ) ) ; // expected-error {{unknown symbolic operand name in inline assembly string}}
asm ( " %[somename " : : " i " ( 4 ) ) ; // expected-error {{unterminated symbolic operand name in inline assembly string}}
asm ( " %[] " : : " i " ( 4 ) ) ; // expected-error {{empty symbolic operand name in inline assembly string}}
2011-07-08 07:11:01 +08:00
2009-03-11 08:23:13 +08:00
// PR3258
asm ( " %9 " : : " i " ( 4 ) ) ; // expected-error {{invalid operand number in inline asm string}}
asm ( " %1 " : " +r " ( i ) ) ; // ok, referring to input.
2009-03-11 07:51:40 +08:00
}
2009-04-27 02:22:24 +08:00
// PR4077
int test7 ( unsigned long long b ) {
int a ;
2009-05-03 15:04:21 +08:00
asm volatile ( " foo %0 %1 " : " =a " ( a ) : " 0 " ( b ) ) ; // expected-error {{input with type 'unsigned long long' matching output with type 'int'}}
2009-04-27 02:22:24 +08:00
return a ;
}
2010-01-26 06:27:48 +08:00
// <rdar://problem/7574870>
asm volatile ( " " ) ; // expected-warning {{meaningless 'volatile' on asm outside function}}
2010-11-03 10:22:29 +08:00
// PR3904
2010-11-03 10:54:51 +08:00
void test8 ( int i ) {
2010-11-03 10:22:29 +08:00
// A number in an input constraint can't point to a read-write constraint.
2010-11-03 10:54:51 +08:00
asm ( " " : " +r " ( i ) , " =r " ( i ) : " 0 " ( i ) ) ; // expected-error{{invalid input constraint '0' in asm}}
}
// PR3905
void test9 ( int i ) {
asm ( " " : [ foo ] " =r " ( i ) , " =r " ( i ) : " 1[foo] " ( i ) ) ; // expected-error{{invalid input constraint '1[foo]' in asm}}
asm ( " " : [ foo ] " =r " ( i ) , " =r " ( i ) : " [foo]1 " ( i ) ) ; // expected-error{{invalid input constraint '[foo]1' in asm}}
2010-11-03 10:22:29 +08:00
}
2011-01-02 05:47:03 +08:00
void test10 ( void ) {
2011-01-11 23:16:52 +08:00
static int g asm ( " g_asm " ) = 0 ;
extern int gg asm ( " gg_asm " ) ;
__private_extern__ int ggg asm ( " ggg_asm " ) ;
int a asm ( " a_asm " ) ; // expected-warning{{ignored asm label 'a_asm' on automatic variable}}
auto int aa asm ( " aa_asm " ) ; // expected-warning{{ignored asm label 'aa_asm' on automatic variable}}
register int r asm ( " cx " ) ;
register int rr asm ( " rr_asm " ) ; // expected-error{{unknown register name 'rr_asm' in asm}}
2014-08-17 21:19:48 +08:00
register int rrr asm ( " % " ) ; // expected-error{{unknown register name '%' in asm}}
2011-01-02 05:47:03 +08:00
}
2011-05-11 07:39:47 +08:00
// This is just an assert because of the boolean conversion.
// Feel free to change the assembly to something sensible if it causes a problem.
// rdar://problem/9414925
void test11 ( void ) {
_Bool b ;
asm volatile ( " movb %%gs:%P2,%b0 " : " =q " ( b ) : " 0 " ( 0 ) , " i " ( 5L ) ) ;
}
2011-06-29 02:20:53 +08:00
void test12 ( void ) {
register int cc __asm ( " cc " ) ; // expected-error{{unknown register name 'cc' in asm}}
}
2011-07-01 04:17:41 +08:00
// PR10223
void test13 ( void ) {
void * esp ;
__asm__ volatile ( " mov %%esp, %o " : " =r " ( esp ) : : ) ; // expected-error {{invalid % escape in inline assembly string}}
}
2013-03-26 05:09:49 +08:00
// <rdar://problem/12700799>
2013-03-28 07:26:09 +08:00
struct S ; // expected-note 2 {{forward declaration of 'struct S'}}
2013-03-26 05:09:49 +08:00
void test14 ( struct S * s ) {
__asm ( " " : : " a " ( * s ) ) ; // expected-error {{dereference of pointer to incomplete type 'struct S'}}
__asm ( " " : " =a " ( * s ) : ) ; // expected-error {{dereference of pointer to incomplete type 'struct S'}}
}
2013-04-18 21:23:23 +08:00
// PR15759.
double test15 ( ) {
double ret = 0 ;
__asm ( " 0.0 " : " = " ( ret ) ) ; // expected-error {{invalid output constraint '=' in asm}}
__asm ( " 0.0 " : " =& " ( ret ) ) ; // expected-error {{invalid output constraint '=&' in asm}}
__asm ( " 0.0 " : " +? " ( ret ) ) ; // expected-error {{invalid output constraint '+?' in asm}}
__asm ( " 0.0 " : " +! " ( ret ) ) ; // expected-error {{invalid output constraint '+!' in asm}}
__asm ( " 0.0 " : " +# " ( ret ) ) ; // expected-error {{invalid output constraint '+#' in asm}}
__asm ( " 0.0 " : " +* " ( ret ) ) ; // expected-error {{invalid output constraint '+*' in asm}}
__asm ( " 0.0 " : " =% " ( ret ) ) ; // expected-error {{invalid output constraint '=%' in asm}}
__asm ( " 0.0 " : " =,= " ( ret ) ) ; // expected-error {{invalid output constraint '=,=' in asm}}
__asm ( " 0.0 " : " =,g " ( ret ) ) ; // no-error
__asm ( " 0.0 " : " =g " ( ret ) ) ; // no-error
return ret ;
}
2014-06-06 00:45:22 +08:00
// PR19837
struct foo {
int a ;
} ;
2015-11-18 08:15:28 +08:00
register struct foo bar asm ( " esp " ) ; // expected-error {{bad type for named register variable}}
register float baz asm ( " esp " ) ; // expected-error {{bad type for named register variable}}
register int r0 asm ( " edi " ) ; // expected-error {{register 'edi' unsuitable for global register variables on this target}}
register long long r1 asm ( " esp " ) ; // expected-error {{size of register 'esp' does not match variable size}}
register int r2 asm ( " esp " ) ;
2014-07-19 07:30:30 +08:00
double f_output_constraint ( void ) {
double result ;
__asm ( " foo1 " : " =f " ( result ) ) ; // expected-error {{invalid output constraint '=f' in asm}}
return result ;
}
2014-12-29 12:09:59 +08:00
void fn1 ( ) {
int l ;
__asm__ ( " "
: [ l ] " =r " ( l )
: " [l],m " ( l ) ) ; // expected-error {{asm constraint has an unexpected number of alternatives: 1 vs 2}}
}
2015-01-10 18:43:19 +08:00
void fn2 ( ) {
int l ;
__asm__ ( " "
: " +&m " ( l ) ) ; // expected-error {{invalid output constraint '+&m' in asm}}
}
2015-01-11 16:52:38 +08:00
void fn3 ( ) {
int l ;
__asm__ ( " "
: " +#r " ( l ) ) ; // expected-error {{invalid output constraint '+#r' in asm}}
}
2015-01-11 17:39:03 +08:00
void fn4 ( ) {
int l ;
__asm__ ( " "
: " =r " ( l )
2015-01-14 13:11:09 +08:00
: " m# " ( l ) ) ;
2015-01-11 17:39:03 +08:00
}
2015-01-11 17:57:13 +08:00
void fn5 ( ) {
int l ;
__asm__ ( " "
: [ g ] " +r " ( l )
: " [g] " ( l ) ) ; // expected-error {{invalid input constraint '[g]' in asm}}
}
2015-01-11 18:22:41 +08:00
void fn6 ( ) {
int a ;
__asm__ ( " "
: " =rm " ( a ) , " =rm " ( a )
: " 11m " ( a ) ) // expected-error {{invalid input constraint '11m' in asm}}
}
2015-06-05 21:40:59 +08:00
// PR14269
typedef struct test16_foo {
unsigned int field1 : 1 ;
unsigned int field2 : 2 ;
unsigned int field3 : 3 ;
} test16_foo ;
2015-08-03 18:38:10 +08:00
typedef __attribute__ ( ( vector_size ( 16 ) ) ) int test16_bar ;
2015-11-18 08:15:28 +08:00
register int test16_baz asm ( " esp " ) ;
2015-08-03 18:38:10 +08:00
2015-06-05 21:40:59 +08:00
void test16 ( )
{
2015-08-03 18:38:10 +08:00
test16_foo a ;
test16_bar b ;
__asm__ ( " movl $5, %0 "
: " =rm " ( a . field2 ) ) ; // expected-error {{reference to a bit-field in asm input with a memory constraint '=rm'}}
__asm__ ( " movl $5, %0 "
:
: " m " ( a . field3 ) ) ; // expected-error {{reference to a bit-field in asm output with a memory constraint 'm'}}
__asm__ ( " movl $5, %0 "
: " =rm " ( b [ 2 ] ) ) ; // expected-error {{reference to a vector element in asm input with a memory constraint '=rm'}}
__asm__ ( " movl $5, %0 "
:
: " m " ( b [ 3 ] ) ) ; // expected-error {{reference to a vector element in asm output with a memory constraint 'm'}}
2015-06-05 21:40:59 +08:00
__asm__ ( " movl $5, %0 "
2015-08-03 18:38:10 +08:00
: " =rm " ( test16_baz ) ) ; // expected-error {{reference to a global register variable in asm input with a memory constraint '=rm'}}
2015-06-05 21:40:59 +08:00
__asm__ ( " movl $5, %0 "
:
2015-08-03 18:38:10 +08:00
: " m " ( test16_baz ) ) ; // expected-error {{reference to a global register variable in asm output with a memory constraint 'm'}}
2015-06-05 21:40:59 +08:00
}
2015-09-21 22:41:00 +08:00
int test17 ( int t0 )
{
int r0 , r1 ;
__asm ( " addl %2, %2 \n \t "
" movl $123, %0 "
: " =a " ( r0 ) ,
" =&r " ( r1 )
: " 1 " ( t0 ) , // expected-note {{constraint '1' is already present here}}
" 1 " ( t0 ) ) ; // expected-error {{more than one input constraint matches the same output '1'}}
return r0 + r1 ;
}