Skip to content

Commit

Permalink
add test for array cookies of dynamically sized arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderlinne committed May 10, 2021
1 parent 08254d8 commit 22d8b4f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/pass/new_delete/17_array_cookie_dynamic_size.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// clang-format off
// RUN: %cpp-to-llvm %s | %apply-typeart -S 2>&1 | FileCheck %s
// clang-format on

struct S1 {
int x;
~S1(){};
};

// CHECK: call i8* @_Znam(i64 [[ALLOC:%[0-9]+]])
// CHECK: call void @__typeart_alloc(i8* [[MEM:%[0-9]+]], i32 {{2[0-9]+}}, i64 [[COUNT:%[0-9]+]])
// CHECK: [[COOKIE:%[0-9]+]] = bitcast i8* [[MEM]] to i64*
// CHECK: store i64 [[COUNT]], i64* [[COOKIE]], align 8
// CHECK: [[ARR:%[0-9]+]] = getelementptr inbounds i8, i8* [[MEM]], i64 8
// CHECK: bitcast i8* [[ARR]] to %struct.S1*
int main() {
volatile int elment_count = 2;
S1* ss = new S1[elment_count];
return 0;
}

// CHECK: TypeArtPass [Heap]
// CHECK-NEXT: Malloc{{[ ]*}}:{{[ ]*}}1
// CHECK-NEXT: Free
// CHECK-NEXT: Alloca{{[ ]*}}:{{[ ]*}}0

0 comments on commit 22d8b4f

Please sign in to comment.