1 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-linux-gnu -S -emit-llvm -o - %s | FileCheck %s
2 // UNSUPPORTED: ppc64be
3 
4 // CHECK-LABEL: define{{.*}} void @foo_no_mempcy() #0
foo_no_mempcy()5 extern "C" void foo_no_mempcy() __attribute__((no_builtin("memcpy"))) {}
6 
7 // CHECK-LABEL: define{{.*}} void @foo_no_mempcy_twice() #0
foo_no_mempcy_twice()8 extern "C" void foo_no_mempcy_twice() __attribute__((no_builtin("memcpy"))) __attribute__((no_builtin("memcpy"))) {}
9 
10 // CHECK-LABEL: define{{.*}} void @foo_no_builtins() #1
foo_no_builtins()11 extern "C" void foo_no_builtins() __attribute__((no_builtin)) {}
12 
13 // CHECK-LABEL: define{{.*}} void @foo_no_mempcy_memset() #2
foo_no_mempcy_memset()14 extern "C" void foo_no_mempcy_memset() __attribute__((no_builtin("memset", "memcpy"))) {}
15 
16 // CHECK-LABEL: define{{.*}} void @separate_attrs() #2
separate_attrs()17 extern "C" void separate_attrs() __attribute__((no_builtin("memset"))) __attribute__((no_builtin("memcpy"))) {}
18 
19 // CHECK-LABEL: define{{.*}} void @separate_attrs_ordering() #2
separate_attrs_ordering()20 extern "C" void separate_attrs_ordering() __attribute__((no_builtin("memcpy"))) __attribute__((no_builtin("memset"))) {}
21 
22 struct A {
fooA23   virtual int foo() const __attribute__((no_builtin("memcpy"))) { return 1; }
24   virtual ~A();
25 };
26 
27 struct B : public A {
fooB28   int foo() const override __attribute__((no_builtin("memmove"))) { return 2; }
29   virtual ~B();
30 };
31 
32 // CHECK-LABEL: define{{.*}} void @call_a_foo(%struct.A* noundef %a) #3
call_a_foo(A * a)33 extern "C" void call_a_foo(A *a) {
34   // CHECK: %call = call noundef i32 %2(%struct.A* {{[^,]*}} %0)
35   a->foo(); // virtual call is not annotated
36 }
37 
38 // CHECK-LABEL: define{{.*}} void @call_b_foo(%struct.B* noundef %b) #3
call_b_foo(B * b)39 extern "C" void call_b_foo(B *b) {
40   // CHECK: %call = call noundef i32 %2(%struct.B* {{[^,]*}} %0)
41   b->foo(); // virtual call is not annotated
42 }
43 
44 // CHECK-LABEL: define{{.*}} void @call_foo_no_mempcy() #3
call_foo_no_mempcy()45 extern "C" void call_foo_no_mempcy() {
46   // CHECK: call void @foo_no_mempcy() #7
47   foo_no_mempcy(); // call gets annotated with "no-builtin-memcpy"
48 }
49 
~A()50 A::~A() {} // Anchoring A so A::foo() gets generated
~B()51 B::~B() {} // Anchoring B so B::foo() gets generated
52 
53 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK1A3fooEv(%struct.A* noundef{{[^,]*}} %this) unnamed_addr #0 comdat align 2
54 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK1B3fooEv(%struct.B* noundef{{[^,]*}} %this) unnamed_addr #6 comdat align 2
55 
56 // CHECK:     attributes #0 = {{{.*}}"no-builtin-memcpy"{{.*}}}
57 // CHECK-NOT: attributes #0 = {{{.*}}"no-builtin-memmove"{{.*}}}
58 // CHECK-NOT: attributes #0 = {{{.*}}"no-builtin-memset"{{.*}}}
59 // CHECK:     attributes #1 = {{{.*}}"no-builtins"{{.*}}}
60 // CHECK:     attributes #2 = {{{.*}}"no-builtin-memcpy"{{.*}}"no-builtin-memset"{{.*}}}
61 // CHECK-NOT: attributes #2 = {{{.*}}"no-builtin-memmove"{{.*}}}
62 // CHECK:     attributes #6 = {{{.*}}"no-builtin-memmove"{{.*}}}
63 // CHECK-NOT: attributes #5 = {{{.*}}"no-builtin-memcpy"{{.*}}}
64 // CHECK-NOT: attributes #5 = {{{.*}}"no-builtin-memset"{{.*}}}
65 // CHECK:     attributes #7 = { "no-builtin-memcpy" }
66