Home | History | Annotate | Download | only in CodeGenCXX
      1 // RUN: not %clang_cc1 -triple i686-pc-linux-gnu %s -o - -emit-llvm -verify | FileCheck %s
      2 
      3 typedef __typeof(sizeof(int)) size_t;
      4 
      5 namespace test1 {
      6   struct A { void operator delete(void*,size_t); int x; };
      7 
      8   // CHECK: define void @_ZN5test11aEPNS_1AE(
      9   void a(A *x) {
     10     // CHECK:      load
     11     // CHECK-NEXT: icmp eq {{.*}}, null
     12     // CHECK-NEXT: br i1
     13     // CHECK:      call void @_ZN5test11AdlEPvj(i8* %{{.*}}, i32 4)
     14     delete x;
     15   }
     16 }
     17 
     18 // Check that we make cookies for the two-arg delete even when using
     19 // the global allocator and deallocator.
     20 namespace test2 {
     21   struct A {
     22     int x;
     23     void *operator new[](size_t);
     24     void operator delete[](void *, size_t);
     25   };
     26 
     27   // CHECK: define [[A:%.*]]* @_ZN5test24testEv()
     28   A *test() {
     29     // CHECK:      [[NEW:%.*]] = call noalias i8* @_Znaj(i32 44)
     30     // CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[NEW]] to i32*
     31     // CHECK-NEXT: store i32 10, i32* [[T0]]
     32     // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[NEW]], i64 4
     33     // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[A]]*
     34     // CHECK-NEXT: ret [[A]]* [[T2]]
     35     return ::new A[10];
     36   }
     37 
     38   // CHECK: define void @_ZN5test24testEPNS_1AE(
     39   void test(A *p) {
     40     // CHECK:      [[P:%.*]] = alloca [[A]]*, align 4
     41     // CHECK-NEXT: store [[A]]* {{%.*}}, [[A]]** [[P]], align 4
     42     // CHECK-NEXT: [[T0:%.*]] = load [[A]]** [[P]], align 4
     43     // CHECK-NEXT: [[T1:%.*]] = icmp eq [[A]]* [[T0]], null
     44     // CHECK-NEXT: br i1 [[T1]],
     45     // CHECK:      [[T2:%.*]] = bitcast [[A]]* [[T0]] to i8*
     46     // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 -4
     47     // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i32*
     48     // CHECK-NEXT: [[T5:%.*]] = load i32* [[T4]]
     49     // CHECK-NEXT: call void @_ZdaPv(i8* [[T3]])
     50     // CHECK-NEXT: br label
     51     ::delete[] p;
     52   }
     53 }
     54 
     55 // rdar://problem/8913519
     56 namespace test3 {
     57   struct A {
     58     int x;
     59     void operator delete[](void *, size_t);
     60   };
     61   struct B : A {};
     62 
     63   // CHECK: define void @_ZN5test34testEv()
     64   void test() {
     65     // CHECK:      call noalias i8* @_Znaj(i32 24)
     66     // CHECK-NEXT: bitcast
     67     // CHECK-NEXT: store i32 5
     68     (void) new B[5];
     69   }
     70 }
     71