60 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s2 3int foo1 asm ("bar1");4int foo2 asm (L"bar2"); // expected-error {{cannot use wide string literal in 'asm'}}5int foo3 asm (u8"bar3"); // expected-error {{cannot use unicode string literal in 'asm'}}6int foo4 asm (u"bar4"); // expected-error {{cannot use unicode string literal in 'asm'}}7int foo5 asm (U"bar5"); // expected-error {{cannot use unicode string literal in 'asm'}}8int foo6 asm ("bar6"_x); // expected-error {{string literal with user-defined suffix cannot be used here}}9int foo6 asm ("" L"bar7"); // expected-error {{cannot use wide string literal in 'asm'}}10 11void f() {12 [[]] asm("");13 [[gnu::deprecated]] asm(""); // expected-warning {{'gnu::deprecated' attribute ignored}}14}15 16 17#if !__has_extension(gnu_asm_constexpr_strings)18#error Extension 'gnu_asm_constexpr_strings' should be available by default19#endif20 21struct string_view {22 int S;23 const char* D;24 constexpr string_view(const char* Str) : S(__builtin_strlen(Str)), D(Str) {}25 constexpr string_view(int Size, const char* Str) : S(Size), D(Str) {}26 constexpr int size() const {27 return S;28 }29 constexpr const char* data() const {30 return D;31 }32};33 34// Neither gcc nor clang support expressions in label35int foo1 asm ((string_view("test"))); // expected-error {{expected string literal in 'asm'}}36int func() asm ((string_view("test"))); // expected-error {{expected string literal in 'asm'}}37 38 39void f2() {40 asm(string_view("")); // expected-error {{expected string literal or parenthesized constant expression in 'asm'}}41 asm("" : string_view("")); // expected-error {{expected string literal or parenthesized constant expression in 'asm'}}42 asm("" : : string_view("")); // expected-error {{expected string literal or parenthesized constant expression in 'asm'}}43 asm("" : : : string_view("")); // expected-error {{expected ')'}}44 asm("" :: string_view("")); // expected-error {{expected string literal or parenthesized constant expression in 'asm'}}45 asm(::string_view("")); // expected-error {{expected string literal or parenthesized constant expression in 'asm'}}46 47 int i;48 49 asm((string_view("")));50 asm((::string_view("")));51 asm("" : (::string_view("+g")) (i));52 asm("" : (::string_view("+g"))); // expected-error {{expected '(' after 'asm operand'}}53 asm("" : (::string_view("+g")) (i) : (::string_view("g")) (0));54 asm("" : (::string_view("+g")) (i) : (::string_view("g"))); // expected-error {{expected '(' after 'asm operand'}}55 asm("" : (::string_view("+g")) (i) : (::string_view("g")) (0) : (string_view("memory")));56 57 58 asm((0)); // expected-error {{the expression in this asm operand must be a string literal or an object with 'data()' and 'size()' member functions}}59}60