| 1 |
// REQUIRES: x86-registered-target |
| 2 |
// RUN: %clang_cc1 -triple x86_64 %s -S -o /dev/null -Werror -verify |
| 3 |
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s |
| 4 |
|
| 5 |
struct string_view { |
| 6 |
int S; |
| 7 |
const char* D; |
| 8 |
constexpr string_view() : S(0), D(0){} |
| 9 |
constexpr string_view(const char* Str) : S(__builtin_strlen(Str)), D(Str) {} |
| 10 |
constexpr string_view(int Size, const char* Str) : S(Size), D(Str) {} |
| 11 |
constexpr int size() const { |
| 12 |
return S; |
| 13 |
} |
| 14 |
constexpr const char* data() const { |
| 15 |
return D; |
| 16 |
} |
| 17 |
}; |
| 18 |
|
| 19 |
namespace GH143242 { |
| 20 |
constexpr string_view code2 = R"(nop; nop; nop; nop)"; |
| 21 |
asm((code2)); |
| 22 |
// CHECK: module asm "nop; nop; nop; nop" |
| 23 |
} |
| 24 |
|
| 25 |
int func() {return 0;}; |
| 26 |
|
| 27 |
void f() { |
| 28 |
|
| 29 |
asm((string_view("")) ::(string_view("r"))(func())); |
| 30 |
// CHECK: %[[CALL:.*]] = call noundef i32 @_Z4funcv |
| 31 |
// CHECK: call void asm sideeffect "", "r,~{dirflag},~{fpsr},~{flags}" |
| 32 |
asm("" :::(string_view("memory"))); |
| 33 |
// CHECK: call void asm sideeffect "", "~{memory},~{dirflag},~{fpsr},~{flags}" |
| 34 |
} |
| 35 |
|
| 36 |
void foo(unsigned long long addr, unsigned long long a0) { |
| 37 |
register unsigned long long result asm("rax"); |
| 38 |
register unsigned long long b0 asm("rdi"); |
| 39 |
|
| 40 |
b0 = a0; |
| 41 |
|
| 42 |
asm((string_view("call *%1")) : (string_view("=r")) (result) |
| 43 |
: (string_view("r"))(addr), (string_view("r")) (b0) : (string_view("memory"))); |
| 44 |
|
| 45 |
// CHECK:{{.*}} call i64 asm "call *$1", "={rax},r,{rdi},~{memory},~{dirflag},~{fpsr},~{flags}" |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
void test_srcloc() { |
| 50 |
asm((string_view( // expected-error {{invalid instruction mnemonic 'nonsense'}} \ |
| 51 |
// expected-error {{invalid instruction mnemonic 'foobar'}} \ |
| 52 |
// expected-note@1 {{instantiated into assembly here}} \ |
| 53 |
// expected-note@2 {{instantiated into assembly here}} |
| 54 |
R"o(nonsense |
| 55 |
foobar)o") |
| 56 |
|
| 57 |
) ::(string_view("r"))(func())); |
| 58 |
} |