"Fossies" - the Fresh Open Source Software Archive

Member "cfe-9.0.0.src/test/CodeGenCXX/new-array-init.cpp" (6 May 2019, 5874 Bytes) of package /linux/misc/cfe-9.0.0.src.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "new-array-init.cpp": 8.0.1_vs_9.0.0.

    1 // RUN: %clang_cc1 -std=c++11 -triple i386-unknown-unknown %s -emit-llvm -o - | FileCheck %s
    2 // RUN: %clang_cc1 -std=c++11 -triple i386-unknown-unknown %s -emit-llvm -fsanitize=signed-integer-overflow -o - | FileCheck --check-prefix=SIO %s
    3 
    4 // CHECK: @[[ABC4:.*]] = {{.*}} constant [4 x i8] c"abc\00"
    5 // CHECK: @[[ABC15:.*]] = {{.*}} constant [15 x i8] c"abc\00\00\00\00
    6 
    7 // CHECK-LABEL: define void @_Z2fni
    8 void fn(int n) {
    9   // CHECK: icmp ult i{{32|64}} %{{[^ ]+}}, 3
   10   // CHECK: store i32 1
   11   // CHECK: store i32 2
   12   // CHECK: store i32 3
   13   // CHECK: sub {{.*}}, 12
   14   // CHECK: call void @llvm.memset
   15   new int[n] { 1, 2, 3 };
   16 }
   17 
   18 // CHECK-LABEL: define void @_Z11const_exactv
   19 void const_exact() {
   20   // CHECK-NOT: icmp ult i{{32|64}} %{{[^ ]+}}, 3
   21   // CHECK-NOT: icmp eq i32*
   22   new int[3] { 1, 2, 3 };
   23 }
   24 
   25 // CHECK-LABEL: define void @_Z16const_sufficientv
   26 void const_sufficient() {
   27   // CHECK-NOT: icmp ult i{{32|64}} %{{[^ ]+}}, 3
   28   new int[4] { 1, 2, 3 };
   29   // CHECK: ret void
   30 }
   31 
   32 // CHECK-LABEL: define void @_Z22check_array_value_initv
   33 void check_array_value_init() {
   34   struct S;
   35   new (int S::*[3][4][5]) ();
   36 
   37   // CHECK: call i8* @_Zna{{.}}(i{{32 240|64 480}})
   38   // CHECK: getelementptr inbounds i{{32|64}}, i{{32|64}}* {{.*}}, i{{32|64}} 60
   39 
   40   // CHECK: phi
   41   // CHECK: store i{{32|64}} -1,
   42   // CHECK: getelementptr inbounds i{{32|64}}, i{{32|64}}* {{.*}}, i{{32|64}} 1
   43   // CHECK: icmp eq
   44   // CHECK: br i1
   45 }
   46 
   47 // CHECK-LABEL: define void @_Z15string_nonconsti
   48 void string_nonconst(int n) {
   49   // CHECK: icmp slt i{{32|64}} %{{[^ ]+}}, 4
   50   // FIXME: Conditionally throw an exception rather than passing -1 to alloc function
   51   // CHECK: select
   52   // CHECK: %[[PTR:.*]] = call i8* @_Zna{{.}}(i{{32|64}}
   53   // CHECK: call void @llvm.memcpy{{.*}}(i8* align {{[0-9]+}} %[[PTR]], i8* align {{[0-9]+}} getelementptr inbounds ([4 x i8], [4 x i8]* @[[ABC4]], i32 0, i32 0), i32 4,
   54   // CHECK: %[[REST:.*]] = getelementptr inbounds i8, i8* %[[PTR]], i32 4
   55   // CHECK: %[[RESTSIZE:.*]] = sub {{.*}}, 4
   56   // CHECK: call void @llvm.memset{{.*}}(i8* align {{[0-9]+}} %[[REST]], i8 0, i{{32|64}} %[[RESTSIZE]],
   57   new char[n] { "abc" };
   58 }
   59 
   60 // CHECK-LABEL: define void @_Z12string_exactv
   61 void string_exact() {
   62   // CHECK-NOT: icmp
   63   // CHECK: %[[PTR:.*]] = call i8* @_Zna{{.}}(i{{32|64}} 4)
   64   // CHECK: call void @llvm.memcpy{{.*}}(i8* align {{[0-9]+}} %[[PTR]], i8* align {{[0-9]+}} getelementptr inbounds ([4 x i8], [4 x i8]* @[[ABC4]], i32 0, i32 0), i32 4,
   65   // CHECK-NOT: memset
   66   new char[4] { "abc" };
   67 }
   68 
   69 // CHECK-LABEL: define void @_Z17string_sufficientv
   70 void string_sufficient() {
   71   // CHECK-NOT: icmp
   72   // CHECK: %[[PTR:.*]] = call i8* @_Zna{{.}}(i{{32|64}} 15)
   73   // FIXME: For very large arrays, it would be preferable to emit a small copy and a memset.
   74   // CHECK: call void @llvm.memcpy{{.*}}(i8* align {{[0-9]+}} %[[PTR]], i8* align {{[0-9]+}} getelementptr inbounds ([15 x i8], [15 x i8]* @[[ABC15]], i32 0, i32 0), i32 15,
   75   // CHECK-NOT: memset
   76   new char[15] { "abc" };
   77 }
   78 
   79 // CHECK-LABEL: define void @_Z10aggr_exactv
   80 void aggr_exact() {
   81   // CHECK-NOT: icmp
   82   // CHECK: %[[MEM:.*]] = call i8* @_Zna{{.}}(i{{32|64}} 16)
   83   // CHECK: %[[PTR0:.*]] = bitcast i8* %[[MEM]] to %[[AGGR:.*]]*
   84   // CHECK: %[[FIELD:.*]] = getelementptr inbounds %[[AGGR]], %[[AGGR]]* %[[PTR0]], i32 0, i32 0{{$}}
   85   // CHECK: store i32 1, i32* %[[FIELD]]
   86   // CHECK: %[[FIELD:.*]] = getelementptr inbounds %[[AGGR]], %[[AGGR]]* %[[PTR0]], i32 0, i32 1{{$}}
   87   // CHECK: store i32 2, i32* %[[FIELD]]
   88   // CHECK: %[[PTR1:.*]] = getelementptr inbounds %[[AGGR]], %[[AGGR]]* %[[PTR0]], i32 1{{$}}
   89   // CHECK: %[[FIELD:.*]] = getelementptr inbounds %[[AGGR]], %[[AGGR]]* %[[PTR1]], i32 0, i32 0{{$}}
   90   // CHECK: store i32 3, i32* %[[FIELD]]
   91   // CHECK: %[[FIELD:.*]] = getelementptr inbounds %[[AGGR]], %[[AGGR]]* %[[PTR1]], i32 0, i32 1{{$}}
   92   // CHECK: store i32 0, i32* %[[FIELD]]
   93   // CHECK-NOT: store
   94   // CHECK-NOT: memset
   95   struct Aggr { int a, b; };
   96   new Aggr[2] { 1, 2, 3 };
   97 }
   98 
   99 // CHECK-LABEL: define void @_Z15aggr_sufficienti
  100 void aggr_sufficient(int n) {
  101   // CHECK: icmp ult i32 %{{.*}}, 2
  102   // CHECK: %[[MEM:.*]] = call i8* @_Zna{{.}}(
  103   // CHECK: %[[PTR0:.*]] = bitcast i8* %[[MEM]] to %[[AGGR:.*]]*
  104   // CHECK: %[[FIELD:.*]] = getelementptr inbounds %[[AGGR]], %[[AGGR]]* %[[PTR0]], i32 0, i32 0{{$}}
  105   // CHECK: store i32 1, i32* %[[FIELD]]
  106   // CHECK: %[[FIELD:.*]] = getelementptr inbounds %[[AGGR]], %[[AGGR]]* %[[PTR0]], i32 0, i32 1{{$}}
  107   // CHECK: store i32 2, i32* %[[FIELD]]
  108   // CHECK: %[[PTR1:.*]] = getelementptr inbounds %[[AGGR]], %[[AGGR]]* %[[PTR0]], i32 1{{$}}
  109   // CHECK: %[[FIELD:.*]] = getelementptr inbounds %[[AGGR]], %[[AGGR]]* %[[PTR1]], i32 0, i32 0{{$}}
  110   // CHECK: store i32 3, i32* %[[FIELD]]
  111   // CHECK: %[[FIELD:.*]] = getelementptr inbounds %[[AGGR]], %[[AGGR]]* %[[PTR1]], i32 0, i32 1{{$}}
  112   // CHECK: store i32 0, i32* %[[FIELD]]
  113   // CHECK: %[[PTR2:.*]] = getelementptr inbounds %[[AGGR]], %[[AGGR]]* %[[PTR1]], i32 1{{$}}
  114   // CHECK: %[[REMAIN:.*]] = sub i32 {{.*}}, 16
  115   // CHECK: %[[MEM:.*]] = bitcast %[[AGGR]]* %[[PTR2]] to i8*
  116   // CHECK: call void @llvm.memset{{.*}}(i8* align {{[0-9]+}} %[[MEM]], i8 0, i32 %[[REMAIN]],
  117   struct Aggr { int a, b; };
  118   new Aggr[n] { 1, 2, 3 };
  119 }
  120 
  121 // SIO-LABEL: define void @_Z14constexpr_testv
  122 void constexpr_test() {
  123   // SIO: call i8* @_Zna{{.}}(i32 4)
  124   new int[0+1]{0};
  125 }
  126 
  127 // CHECK-LABEL: define void @_Z13unknown_boundv
  128 void unknown_bound() {
  129   struct Aggr { int x, y, z; };
  130   new Aggr[]{1, 2, 3, 4};
  131   // CHECK: call {{.*}}_Znaj(i32 24)
  132   // CHECK: store i32 1
  133   // CHECK: store i32 2
  134   // CHECK: store i32 3
  135   // CHECK: store i32 4
  136   // CHECK: store i32 0
  137   // CHECK: store i32 0
  138   // CHECK-NOT: store
  139   // CHECK: }
  140 }
  141 
  142 // CHECK-LABEL: define void @_Z20unknown_bound_stringv
  143 void unknown_bound_string() {
  144   new char[]{"hello"};
  145   // CHECK: call {{.*}}_Znaj(i32 6)
  146   // CHECK: memcpy{{.*}} i32 6,
  147 }