Home | History | Annotate | Download | only in CodeGenCXX
      1 // RUN: %clang_cc1 %s -triple=armv7-apple-darwin -emit-llvm -o - | FileCheck %s
      2 // RUN: %clang_cc1 %s -triple=armv7-apple-darwin -emit-llvm -o - | FileCheck -check-prefix=CHECK-LATE %s
      3 
      4 // The 'a' variants ask for the v-table first.
      5 // The 'b' variants ask for the v-table second.
      6 // The 'c' variants ask for the v-table third.
      7 // We do a separate CHECK-LATE pass because the RTTI definition gets
      8 // changed after the fact, which causes reordering of the globals.
      9 
     10 // These are not separated into namespaces because the way that Sema
     11 // currently reports namespaces to IR-generation (i.e., en masse for
     12 // the entire namespace at once) subverts the ordering that we're
     13 // trying to test.
     14 
     15 namespace std { class type_info; }
     16 extern void use(const std::type_info &rtti);
     17 
     18 /*** Test0a ******************************************************************/
     19 
     20 struct Test0a {
     21   Test0a();
     22   virtual inline void foo();
     23   virtual void bar();
     24 };
     25 
     26 // V-table should be defined externally.
     27 Test0a::Test0a() { use(typeid(Test0a)); }
     28 // CHECK: @_ZTV6Test0a = external unnamed_addr constant
     29 // CHECK: @_ZTI6Test0a = external constant
     30 
     31 // This is not a key function.
     32 void Test0a::foo() {}
     33 
     34 /*** Test0b ******************************************************************/
     35 
     36 struct Test0b {
     37   Test0b();
     38   virtual inline void foo();
     39   virtual void bar();
     40 };
     41 
     42 // This is not a key function.
     43 void Test0b::foo() {}
     44 
     45 // V-table should be defined externally.
     46 Test0b::Test0b() { use(typeid(Test0b)); }
     47 // CHECK: @_ZTV6Test0b = external unnamed_addr constant
     48 // CHECK: @_ZTI6Test0b = external constant
     49 
     50 /*** Test1a ******************************************************************/
     51 
     52 struct Test1a {
     53   Test1a();
     54   virtual void foo();
     55   virtual void bar();
     56 };
     57 
     58 // V-table needs to be defined weakly.
     59 Test1a::Test1a() { use(typeid(Test1a)); }
     60 // CHECK:      @_ZTV6Test1a = linkonce_odr unnamed_addr constant
     61 // CHECK-LATE: @_ZTS6Test1a = linkonce_odr constant
     62 // CHECK-LATE: @_ZTI6Test1a = linkonce_odr constant
     63 
     64 // This defines the key function.
     65 inline void Test1a::foo() {}
     66 
     67 /*** Test1b ******************************************************************/
     68 
     69 struct Test1b {
     70   Test1b();
     71   virtual void foo();
     72   virtual void bar();
     73 };
     74 
     75 // This defines the key function.
     76 inline void Test1b::foo() {}
     77 
     78 // V-table should be defined weakly..
     79 Test1b::Test1b() { use(typeid(Test1b)); }
     80 // CHECK: @_ZTV6Test1b = linkonce_odr unnamed_addr constant
     81 // CHECK: @_ZTS6Test1b = linkonce_odr constant
     82 // CHECK: @_ZTI6Test1b = linkonce_odr constant
     83 
     84 /*** Test2a ******************************************************************/
     85 
     86 struct Test2a {
     87   Test2a();
     88   virtual void foo();
     89   virtual void bar();
     90 };
     91 
     92 // V-table should be defined with weak linkage.
     93 Test2a::Test2a() { use(typeid(Test2a)); }
     94 // CHECK:      @_ZTV6Test2a = linkonce_odr unnamed_addr constant
     95 // CHECK-LATE: @_ZTS6Test2a = linkonce_odr constant
     96 // CHECK-LATE: @_ZTI6Test2a = linkonce_odr constant
     97 
     98 void Test2a::bar() {}
     99 inline void Test2a::foo() {}
    100 
    101 /*** Test2b ******************************************************************/
    102 
    103 struct Test2b {
    104   Test2b();
    105   virtual void foo();
    106   virtual void bar();
    107 };
    108 
    109 void Test2b::bar() {}
    110 
    111 // V-table should be defined with weak linkage.
    112 Test2b::Test2b() { use(typeid(Test2b)); }
    113 // CHECK:      @_ZTV6Test2b = linkonce_odr unnamed_addr constant
    114 // CHECK-LATE: @_ZTS6Test2b = linkonce_odr constant
    115 // CHECK-LATE: @_ZTI6Test2b = linkonce_odr constant
    116 
    117 inline void Test2b::foo() {}
    118 
    119 /*** Test2c ******************************************************************/
    120 
    121 struct Test2c {
    122   Test2c();
    123   virtual void foo();
    124   virtual void bar();
    125 };
    126 
    127 void Test2c::bar() {}
    128 inline void Test2c::foo() {}
    129 
    130 // V-table should be defined with weak linkage.
    131 Test2c::Test2c() { use(typeid(Test2c)); }
    132 // CHECK: @_ZTV6Test2c = linkonce_odr unnamed_addr constant
    133 // CHECK: @_ZTS6Test2c = linkonce_odr constant
    134 // CHECK: @_ZTI6Test2c = linkonce_odr constant
    135 
    136 /*** Test3a ******************************************************************/
    137 
    138 struct Test3a {
    139   Test3a();
    140   virtual void foo();
    141   virtual void bar();
    142 };
    143 
    144 // V-table should be defined with weak linkage.
    145 Test3a::Test3a() { use(typeid(Test3a)); }
    146 // CHECK:      @_ZTV6Test3a = linkonce_odr unnamed_addr constant
    147 // CHECK-LATE: @_ZTS6Test3a = linkonce_odr constant
    148 // CHECK-LATE: @_ZTI6Test3a = linkonce_odr constant
    149 
    150 // This defines the key function.
    151 inline void Test3a::bar() {}
    152 inline void Test3a::foo() {}
    153 
    154 /*** Test3b ******************************************************************/
    155 
    156 struct Test3b {
    157   Test3b();
    158   virtual void foo();
    159   virtual void bar();
    160 };
    161 
    162 inline void Test3b::bar() {}
    163 
    164 // V-table should be defined with weak linkage.
    165 Test3b::Test3b() { use(typeid(Test3b)); }
    166 // CHECK:      @_ZTV6Test3b = linkonce_odr unnamed_addr constant
    167 // CHECK-LATE: @_ZTS6Test3b = linkonce_odr constant
    168 // CHECK-LATE: @_ZTI6Test3b = linkonce_odr constant
    169 
    170 // This defines the key function.
    171 inline void Test3b::foo() {}
    172 
    173 /*** Test3c ******************************************************************/
    174 
    175 struct Test3c {
    176   Test3c();
    177   virtual void foo();
    178   virtual void bar();
    179 };
    180 
    181 // This defines the key function.
    182 inline void Test3c::bar() {}
    183 inline void Test3c::foo() {}
    184 
    185 // V-table should be defined with weak linkage.
    186 Test3c::Test3c() { use(typeid(Test3c)); }
    187 // CHECK: @_ZTV6Test3c = linkonce_odr unnamed_addr constant
    188 // CHECK: @_ZTS6Test3c = linkonce_odr constant
    189 // CHECK: @_ZTI6Test3c = linkonce_odr constant
    190