xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/operator-new.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i686-pc-linux-gnu -emit-llvm -o %t-1.ll %s
2*f4a2713aSLionel Sambuc // RUN: FileCheck -check-prefix SANE --input-file=%t-1.ll %s
3*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i686-pc-linux-gnu -emit-llvm -fno-assume-sane-operator-new -o %t-2.ll %s
4*f4a2713aSLionel Sambuc // RUN: FileCheck -check-prefix SANENOT --input-file=%t-2.ll %s
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc class teste {
8*f4a2713aSLionel Sambuc   int A;
9*f4a2713aSLionel Sambuc public:
teste()10*f4a2713aSLionel Sambuc   teste() : A(2) {}
11*f4a2713aSLionel Sambuc };
12*f4a2713aSLionel Sambuc 
f1()13*f4a2713aSLionel Sambuc void f1() {
14*f4a2713aSLionel Sambuc   // SANE: declare noalias i8* @_Znwj(
15*f4a2713aSLionel Sambuc   // SANENOT: declare i8* @_Znwj(
16*f4a2713aSLionel Sambuc   new teste();
17*f4a2713aSLionel Sambuc }
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc 
20*f4a2713aSLionel Sambuc // rdar://5739832 - operator new should check for overflow in multiply.
f2(long N)21*f4a2713aSLionel Sambuc void *f2(long N) {
22*f4a2713aSLionel Sambuc   return new int[N];
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc // SANE:      [[UWO:%.*]] = call {{.*}} @llvm.umul.with.overflow
25*f4a2713aSLionel Sambuc // SANE-NEXT: [[OVER:%.*]] = extractvalue {{.*}} [[UWO]], 1
26*f4a2713aSLionel Sambuc // SANE-NEXT: [[SUM:%.*]] = extractvalue {{.*}} [[UWO]], 0
27*f4a2713aSLionel Sambuc // SANE-NEXT: [[RESULT:%.*]] = select i1 [[OVER]], i32 -1, i32 [[SUM]]
28*f4a2713aSLionel Sambuc // SANE-NEXT: call noalias i8* @_Znaj(i32 [[RESULT]])
29*f4a2713aSLionel Sambuc }
30