File: asm.cpp

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,235,796 kB
  • sloc: cpp: 7,617,614; ansic: 1,433,901; asm: 1,058,726; python: 252,096; f90: 94,671; objc: 70,753; lisp: 42,813; pascal: 18,401; sh: 10,032; ml: 5,111; perl: 4,720; awk: 3,523; makefile: 3,401; javascript: 2,272; xml: 892; fortran: 770
file content (59 lines) | stat: -rw-r--r-- 2,744 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s

int foo1 asm ("bar1");
int foo2 asm (L"bar2"); // expected-error {{cannot use wide string literal in 'asm'}}
int foo3 asm (u8"bar3"); // expected-error {{cannot use unicode string literal in 'asm'}}
int foo4 asm (u"bar4"); // expected-error {{cannot use unicode string literal in 'asm'}}
int foo5 asm (U"bar5"); // expected-error {{cannot use unicode string literal in 'asm'}}
int foo6 asm ("bar6"_x); // expected-error {{string literal with user-defined suffix cannot be used here}}
int foo6 asm ("" L"bar7"); // expected-error {{cannot use wide string literal in 'asm'}}

void f() {
  [[]] asm("");
  [[gnu::deprecated]] asm(""); // expected-warning {{'gnu::deprecated' attribute ignored}}
}


#if !__has_extension(gnu_asm_constexpr_strings)
#error Extension 'gnu_asm_constexpr_strings' should be available by default
#endif

struct string_view {
  int S;
  const char* D;
  constexpr string_view(const char* Str) : S(__builtin_strlen(Str)), D(Str) {}
  constexpr string_view(int Size, const char* Str) : S(Size), D(Str) {}
  constexpr int size() const {
      return S;
  }
  constexpr const char* data() const {
      return D;
  }
};

// Neither gcc nor clang support expressions in label
int foo1 asm ((string_view("test"))); // expected-error {{expected string literal in 'asm'}}
int func() asm ((string_view("test"))); // expected-error {{expected string literal in 'asm'}}


void f2() {
  asm(string_view("")); // expected-error {{expected string literal or parenthesized constant expression in 'asm'}}
  asm("" : string_view("")); // expected-error {{expected string literal or parenthesized constant expression in 'asm'}}
  asm("" : : string_view("")); // expected-error {{expected string literal or parenthesized constant expression in 'asm'}}
  asm("" : : : string_view("")); // expected-error {{expected ')'}}
  asm("" :: string_view("")); // expected-error {{expected string literal or parenthesized constant expression in 'asm'}}
  asm(::string_view("")); // expected-error {{expected string literal or parenthesized constant expression in 'asm'}}

  int i;

  asm((string_view("")));
  asm((::string_view("")));
  asm("" : (::string_view("+g")) (i));
  asm("" : (::string_view("+g"))); // expected-error {{expected '(' after 'asm operand'}}
  asm("" : (::string_view("+g")) (i) : (::string_view("g")) (0));
  asm("" : (::string_view("+g")) (i) : (::string_view("g"))); // expected-error {{expected '(' after 'asm operand'}}
  asm("" : (::string_view("+g")) (i) : (::string_view("g")) (0) : (string_view("memory")));


  asm((0)); // expected-error {{the expression in this asm operand must be a string literal or an object with 'data()' and 'size()' member functions}}
}