brintos

brintos / llvm-project-archived public Read only

0
0
Text · 13.0 KiB · 39f6f49 Raw
376 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; Test a pile of objectsize bounds checking.3; RUN: opt < %s -passes=instcombine -S | FileCheck %s4; We need target data to get the sizes of the arrays and structures.5target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"6 7@a = private global [60 x i8] zeroinitializer, align 1 ; <ptr>8@.str = private constant [8 x i8] c"abcdefg\00"   ; <ptr>9define i32 @foo() nounwind {10; CHECK-LABEL: @foo(11; CHECK-NEXT:    ret i32 6012;13  %1 = call i32 @llvm.objectsize.i32.p0(ptr @a, i1 false, i1 false, i1 false)14  ret i32 %115}16 17define ptr @bar(ptr %retval) nounwind {18; CHECK-LABEL: @bar(19; CHECK-NEXT:  entry:20; CHECK-NEXT:    br i1 true, label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]21; CHECK:       cond.true:22; CHECK-NEXT:    [[TMP1:%.*]] = load ptr, ptr [[RETVAL:%.*]], align 423; CHECK-NEXT:    ret ptr [[TMP1]]24; CHECK:       cond.false:25; CHECK-NEXT:    ret ptr poison26;27entry:28  %0 = call i32 @llvm.objectsize.i32.p0(ptr @a, i1 false, i1 false, i1 false)29  %cmp = icmp ne i32 %0, -130  br i1 %cmp, label %cond.true, label %cond.false31 32cond.true:33  %1 = load ptr, ptr %retval34  ret ptr %135 36cond.false:37  %2 = load ptr, ptr %retval38  ret ptr %239}40 41define i32 @f() nounwind {42; CHECK-LABEL: @f(43; CHECK-NEXT:    ret i32 044;45  %1 = call i32 @llvm.objectsize.i32.p0(ptr getelementptr ([60 x i8], ptr @a, i32 1, i32 0), i1 false, i1 false, i1 false)46  ret i32 %147}48 49@window = external global [0 x i8]50 51define i1 @baz() nounwind {52; CHECK-LABEL: @baz(53; CHECK-NEXT:    [[TMP1:%.*]] = tail call i32 @llvm.objectsize.i32.p0(ptr @window, i1 false, i1 false, i1 false)54; CHECK-NEXT:    [[TMP2:%.*]] = icmp eq i32 [[TMP1]], -155; CHECK-NEXT:    ret i1 [[TMP2]]56;57  %1 = tail call i32 @llvm.objectsize.i32.p0(ptr @window, i1 false, i1 false, i1 false)58  %2 = icmp eq i32 %1, -159  ret i1 %260}61 62define void @test1(ptr %q, i32 %x) nounwind noinline {63; CHECK-LABEL: @test1(64; CHECK-NEXT:  entry:65; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @llvm.objectsize.i32.p0(ptr getelementptr inbounds nuw (i8, ptr @window, i32 10), i1 false, i1 false, i1 false)66; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq i32 [[TMP0]], -167; CHECK-NEXT:    br i1 [[TMP1]], label %"47", label %"46"68; CHECK:       "46":69; CHECK-NEXT:    unreachable70; CHECK:       "47":71; CHECK-NEXT:    unreachable72;73entry:74  %0 = call i32 @llvm.objectsize.i32.p0(ptr getelementptr inbounds ([0 x i8], ptr @window, i32 0, i32 10), i1 false, i1 false, i1 false) ; <i64> [#uses=1]75  %1 = icmp eq i32 %0, -1                         ; <i1> [#uses=1]76  br i1 %1, label %"47", label %"46"77 78"46":                                             ; preds = %entry79  unreachable80 81"47":                                             ; preds = %entry82  unreachable83}84 85@.str5 = private constant [9 x i32] [i32 97, i32 98, i32 99, i32 100, i32 0, i3286  101, i32 102, i32 103, i32 0], align 487define i32 @test2() nounwind {88; CHECK-LABEL: @test2(89; CHECK-NEXT:    ret i32 3490;91  %1 = call i32 @llvm.objectsize.i32.p0(ptr getelementptr (i8, ptr @.str5, i32 2), i1 false, i1 false, i1 false)92  ret i32 %193}94 95; rdar://767494696@array = internal global [480 x float] zeroinitializer ; <ptr> [#uses=1]97 98declare ptr @__memcpy_chk(ptr, ptr, i32, i32) nounwind99 100declare i32 @llvm.objectsize.i32.p0(ptr, i1, i1, i1) nounwind readonly101 102declare i32 @llvm.objectsize.i32.p1(ptr addrspace(1), i1, i1, i1) nounwind readonly103 104declare ptr @__inline_memcpy_chk(ptr, ptr, i32) nounwind inlinehint105 106define void @test3(i1 %c1, ptr %ptr1, ptr %ptr2, ptr %ptr3) nounwind {107; CHECK-LABEL: @test3(108; CHECK-NEXT:  entry:109; CHECK-NEXT:    br i1 [[C1:%.*]], label [[BB11:%.*]], label [[BB12:%.*]]110; CHECK:       bb11:111; CHECK-NEXT:    unreachable112; CHECK:       bb12:113; CHECK-NEXT:    [[TMP0:%.*]] = call ptr @__inline_memcpy_chk(ptr nonnull getelementptr inbounds nuw (i8, ptr @array, i32 4), ptr [[PTR3:%.*]], i32 512) #[[ATTR3:[0-9]+]]114; CHECK-NEXT:    unreachable115;116entry:117  br i1 %c1, label %bb11, label %bb12118 119bb11:120  %0 = getelementptr inbounds float, ptr getelementptr inbounds ([480 x float], ptr @array, i32 0, i32 128), i32 -127 ; <ptr> [#uses=1]121  %1 = call i32 @llvm.objectsize.i32.p0(ptr %0, i1 false, i1 false, i1 false) ; <i32> [#uses=1]122  %2 = call ptr @__memcpy_chk(ptr %ptr1, ptr %ptr2, i32 512, i32 %1) nounwind ; <ptr> [#uses=0]123  unreachable124 125bb12:126  %3 = getelementptr inbounds float, ptr getelementptr inbounds ([480 x float], ptr @array, i32 0, i32 128), i32 -127 ; <ptr> [#uses=1]127  %4 = call ptr @__inline_memcpy_chk(ptr %3, ptr %ptr3, i32 512) nounwind inlinehint ; <ptr> [#uses=0]128  unreachable129}130 131; rdar://7718857132 133%struct.data = type { [100 x i32], [100 x i32], [1024 x i8] }134 135define i32 @test4(ptr %esc) nounwind ssp {136; CHECK-LABEL: @test4(137; CHECK-NEXT:  entry:138; CHECK-NEXT:    [[TMP0:%.*]] = alloca [[STRUCT_DATA:%.*]], align 8139; CHECK-NEXT:    call void @llvm.memset.p0.i32(ptr noundef nonnull align 8 dereferenceable(1824) [[TMP0]], i8 0, i32 1824, i1 false) #[[ATTR0:[0-9]+]]140; CHECK-NEXT:    store ptr [[TMP0]], ptr [[ESC:%.*]], align 4141; CHECK-NEXT:    ret i32 0142;143entry:144  %0 = alloca %struct.data, align 8145  %1 = call i32 @llvm.objectsize.i32.p0(ptr %0, i1 false, i1 false, i1 false) nounwind146  %2 = call ptr @__memset_chk(ptr %0, i32 0, i32 1824, i32 %1) nounwind147  store ptr %0, ptr %esc148  ret i32 0149}150 151; rdar://7782496152@s = external global ptr153 154define ptr @test5(i32 %n) nounwind ssp {155; CHECK-LABEL: @test5(156; CHECK-NEXT:  entry:157; CHECK-NEXT:    [[TMP0:%.*]] = tail call noalias dereferenceable_or_null(20) ptr @malloc(i32 20) #[[ATTR0]]158; CHECK-NEXT:    [[TMP1:%.*]] = load ptr, ptr @s, align 8159; CHECK-NEXT:    tail call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(10) [[TMP0]], ptr noundef nonnull align 1 dereferenceable(10) [[TMP1]], i32 10, i1 false) #[[ATTR0]]160; CHECK-NEXT:    ret ptr [[TMP0]]161;162entry:163  %0 = tail call noalias ptr @malloc(i32 20) nounwind164  %1 = tail call i32 @llvm.objectsize.i32.p0(ptr %0, i1 false, i1 false, i1 false)165  %2 = load ptr, ptr @s, align 8166  %3 = tail call ptr @__memcpy_chk(ptr %0, ptr %2, i32 10, i32 %1) nounwind167  ret ptr %0168}169 170define void @test6(i32 %n) nounwind ssp {171; CHECK-LABEL: @test6(172; CHECK-NEXT:  entry:173; CHECK-NEXT:    [[TMP0:%.*]] = tail call noalias dereferenceable_or_null(20) ptr @malloc(i32 20) #[[ATTR0]]174; CHECK-NEXT:    [[TMP1:%.*]] = load ptr, ptr @s, align 8175; CHECK-NEXT:    [[TMP2:%.*]] = tail call ptr @__memcpy_chk(ptr [[TMP0]], ptr [[TMP1]], i32 30, i32 20) #[[ATTR0]]176; CHECK-NEXT:    ret void177;178entry:179  %0 = tail call noalias ptr @malloc(i32 20) nounwind180  %1 = tail call i32 @llvm.objectsize.i32.p0(ptr %0, i1 false, i1 false, i1 false)181  %2 = load ptr, ptr @s, align 8182  %3 = tail call ptr @__memcpy_chk(ptr %0, ptr %2, i32 30, i32 %1) nounwind183  ret void184}185 186declare ptr @__memset_chk(ptr, i32, i32, i32) nounwind187 188declare noalias ptr @malloc(i32) nounwind allockind("alloc,uninitialized") allocsize(0)189 190define i32 @test7(ptr %esc) {191; CHECK-LABEL: @test7(192; CHECK-NEXT:    [[ALLOC:%.*]] = call noalias dereferenceable_or_null(48) ptr @malloc(i32 48) #[[ATTR0]]193; CHECK-NEXT:    store ptr [[ALLOC]], ptr [[ESC:%.*]], align 4194; CHECK-NEXT:    ret i32 32195;196  %alloc = call noalias ptr @malloc(i32 48) nounwind197  store ptr %alloc, ptr %esc198  %gep = getelementptr inbounds i8, ptr %alloc, i32 16199  %objsize = call i32 @llvm.objectsize.i32.p0(ptr %gep, i1 false, i1 false, i1 false) nounwind readonly200  ret i32 %objsize201}202 203declare noalias ptr @calloc(i32, i32) nounwind allockind("alloc,zeroed") allocsize(0,1)204 205define i32 @test8(ptr %esc) {206; CHECK-LABEL: @test8(207; CHECK-NEXT:    [[ALLOC:%.*]] = call noalias dereferenceable_or_null(35) ptr @calloc(i32 5, i32 7) #[[ATTR0]]208; CHECK-NEXT:    store ptr [[ALLOC]], ptr [[ESC:%.*]], align 4209; CHECK-NEXT:    ret i32 30210;211  %alloc = call noalias ptr @calloc(i32 5, i32 7) nounwind212  store ptr %alloc, ptr %esc213  %gep = getelementptr inbounds i8, ptr %alloc, i32 5214  %objsize = call i32 @llvm.objectsize.i32.p0(ptr %gep, i1 false, i1 false, i1 false) nounwind readonly215  ret i32 %objsize216}217 218declare noalias ptr @strdup(ptr nocapture) nounwind219declare noalias ptr @strndup(ptr nocapture, i32) nounwind220 221define i32 @test9(ptr %esc) {222; CHECK-LABEL: @test9(223; CHECK-NEXT:    [[CALL:%.*]] = tail call dereferenceable_or_null(8) ptr @strdup(ptr nonnull @.str) #[[ATTR0]]224; CHECK-NEXT:    store ptr [[CALL]], ptr [[ESC:%.*]], align 8225; CHECK-NEXT:    ret i32 8226;227  %call = tail call ptr @strdup(ptr @.str) nounwind228  store ptr %call, ptr %esc, align 8229  %1 = tail call i32 @llvm.objectsize.i32.p0(ptr %call, i1 true, i1 false, i1 false)230  ret i32 %1231}232 233define i32 @test10(ptr %esc) {234; CHECK-LABEL: @test10(235; CHECK-NEXT:    [[CALL:%.*]] = tail call dereferenceable_or_null(4) ptr @strndup(ptr nonnull dereferenceable(8) @.str, i32 3) #[[ATTR0]]236; CHECK-NEXT:    store ptr [[CALL]], ptr [[ESC:%.*]], align 8237; CHECK-NEXT:    ret i32 4238;239  %call = tail call ptr @strndup(ptr @.str, i32 3) nounwind240  store ptr %call, ptr %esc, align 8241  %1 = tail call i32 @llvm.objectsize.i32.p0(ptr %call, i1 true, i1 false, i1 false)242  ret i32 %1243}244 245define i32 @test11(ptr %esc) {246; CHECK-LABEL: @test11(247; CHECK-NEXT:    [[STRDUP:%.*]] = tail call dereferenceable_or_null(8) ptr @strdup(ptr nonnull @.str)248; CHECK-NEXT:    store ptr [[STRDUP]], ptr [[ESC:%.*]], align 8249; CHECK-NEXT:    ret i32 8250;251  %call = tail call ptr @strndup(ptr @.str, i32 7) nounwind252  store ptr %call, ptr %esc, align 8253  %1 = tail call i32 @llvm.objectsize.i32.p0(ptr %call, i1 true, i1 false, i1 false)254  ret i32 %1255}256 257define i32 @test12(ptr %esc) {258; CHECK-LABEL: @test12(259; CHECK-NEXT:    [[STRDUP:%.*]] = tail call dereferenceable_or_null(8) ptr @strdup(ptr nonnull @.str)260; CHECK-NEXT:    store ptr [[STRDUP]], ptr [[ESC:%.*]], align 8261; CHECK-NEXT:    ret i32 8262;263  %call = tail call ptr @strndup(ptr @.str, i32 8) nounwind264  store ptr %call, ptr %esc, align 8265  %1 = tail call i32 @llvm.objectsize.i32.p0(ptr %call, i1 true, i1 false, i1 false)266  ret i32 %1267}268 269define i32 @test13(ptr %esc) {270; CHECK-LABEL: @test13(271; CHECK-NEXT:    [[STRDUP:%.*]] = tail call dereferenceable_or_null(8) ptr @strdup(ptr nonnull @.str)272; CHECK-NEXT:    store ptr [[STRDUP]], ptr [[ESC:%.*]], align 8273; CHECK-NEXT:    ret i32 8274;275  %call = tail call ptr @strndup(ptr @.str, i32 57) nounwind276  store ptr %call, ptr %esc, align 8277  %1 = tail call i32 @llvm.objectsize.i32.p0(ptr %call, i1 true, i1 false, i1 false)278  ret i32 %1279}280 281@globalalias = internal alias [60 x i8], ptr @a282 283define i32 @test18() {284; CHECK-LABEL: @test18(285; CHECK-NEXT:    ret i32 60286;287  %1 = call i32 @llvm.objectsize.i32.p0(ptr @globalalias, i1 false, i1 false, i1 false)288  ret i32 %1289}290 291@globalalias2 = weak alias [60 x i8], ptr @a292 293define i32 @test19() {294; CHECK-LABEL: @test19(295; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @llvm.objectsize.i32.p0(ptr @globalalias2, i1 false, i1 false, i1 false)296; CHECK-NEXT:    ret i32 [[TMP1]]297;298  %1 = call i32 @llvm.objectsize.i32.p0(ptr @globalalias2, i1 false, i1 false, i1 false)299  ret i32 %1300}301 302define i32 @test20() {303; CHECK-LABEL: @test20(304; CHECK-NEXT:    ret i32 0305;306  %1 = call i32 @llvm.objectsize.i32.p0(ptr null, i1 false, i1 false, i1 false)307  ret i32 %1308}309 310define i32 @test21() {311; CHECK-LABEL: @test21(312; CHECK-NEXT:    ret i32 0313;314  %1 = call i32 @llvm.objectsize.i32.p0(ptr null, i1 true, i1 false, i1 false)315  ret i32 %1316}317 318define i32 @test22() {319; CHECK-LABEL: @test22(320; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @llvm.objectsize.i32.p0(ptr null, i1 false, i1 true, i1 false)321; CHECK-NEXT:    ret i32 [[TMP1]]322;323  %1 = call i32 @llvm.objectsize.i32.p0(ptr null, i1 false, i1 true, i1 false)324  ret i32 %1325}326 327define i32 @test23() {328; CHECK-LABEL: @test23(329; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @llvm.objectsize.i32.p0(ptr null, i1 true, i1 true, i1 false)330; CHECK-NEXT:    ret i32 [[TMP1]]331;332  %1 = call i32 @llvm.objectsize.i32.p0(ptr null, i1 true, i1 true, i1 false)333  ret i32 %1334}335 336; 1 is an arbitrary non-zero address space.337define i32 @test24() {338; CHECK-LABEL: @test24(339; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @llvm.objectsize.i32.p1(ptr addrspace(1) null, i1 false, i1 false, i1 false)340; CHECK-NEXT:    ret i32 [[TMP1]]341;342  %1 = call i32 @llvm.objectsize.i32.p1(ptr addrspace(1) null, i1 false,343  i1 false, i1 false)344  ret i32 %1345}346 347define i32 @test25() {348; CHECK-LABEL: @test25(349; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @llvm.objectsize.i32.p1(ptr addrspace(1) null, i1 true, i1 false, i1 false)350; CHECK-NEXT:    ret i32 [[TMP1]]351;352  %1 = call i32 @llvm.objectsize.i32.p1(ptr addrspace(1) null, i1 true,353  i1 false, i1 false)354  ret i32 %1355}356 357define i32 @test26() {358; CHECK-LABEL: @test26(359; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @llvm.objectsize.i32.p1(ptr addrspace(1) null, i1 false, i1 true, i1 false)360; CHECK-NEXT:    ret i32 [[TMP1]]361;362  %1 = call i32 @llvm.objectsize.i32.p1(ptr addrspace(1) null, i1 false,363  i1 true, i1 false)364  ret i32 %1365}366 367define i32 @test27() {368; CHECK-LABEL: @test27(369; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @llvm.objectsize.i32.p1(ptr addrspace(1) null, i1 true, i1 true, i1 false)370; CHECK-NEXT:    ret i32 [[TMP1]]371;372  %1 = call i32 @llvm.objectsize.i32.p1(ptr addrspace(1) null, i1 true,373  i1 true, i1 false)374  ret i32 %1375}376