File: builtin-condition.ll

package info (click to toggle)
llvm-toolchain-5.0 1:5.0.1-2~bpo9+1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 553,688 kB
  • sloc: cpp: 2,878,786; ansic: 584,110; asm: 246,252; python: 124,751; objc: 106,925; sh: 21,542; lisp: 8,628; pascal: 5,885; ml: 5,544; perl: 5,312; makefile: 2,208; cs: 2,022; xml: 686; php: 212; csh: 117
file content (123 lines) | stat: -rw-r--r-- 3,837 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
; RUN: opt -codegenprepare -S  < %s | FileCheck %s

; Ensure we act sanely on overflow.
; CHECK-LABEL: define i32 @bar
define i32 @bar() {
entry:
  ; CHECK: ret i32 -1
  %az = alloca [2147483649 x i32], align 16
  %a = alloca i8*, align 8
  %arraydecay = getelementptr inbounds [2147483649 x i32], [2147483649 x i32]* %az, i32 0, i32 0
  %0 = bitcast i32* %arraydecay to i8*
  store i8* %0, i8** %a, align 8
  %1 = load i8*, i8** %a, align 8
  %2 = call i32 @llvm.objectsize.i32.p0i8(i8* %1, i1 false)
  ret i32 %2
}

; CHECK-LABEL: define i32 @baz
define i32 @baz(i32 %n) {
entry:
  ; CHECK: ret i32 -1
  %az = alloca [1 x i32], align 16
  %bz = alloca [4294967297 x i32], align 16
  %tobool = icmp ne i32 %n, 0
  %arraydecay = getelementptr inbounds [1 x i32], [1 x i32]* %az, i64 0, i64 0
  %arraydecay1 = getelementptr inbounds [4294967297 x i32], [4294967297 x i32]* %bz, i64 0, i64 0
  %cond = select i1 %tobool, i32* %arraydecay, i32* %arraydecay1
  %0 = bitcast i32* %cond to i8*
  %1 = call i32 @llvm.objectsize.i32.p0i8(i8* %0, i1 false)
  ret i32 %1
}

declare i32 @llvm.objectsize.i32.p0i8(i8*, i1)

; The following tests were generated by:
; #include<stdlib.h>
; #define STATIC_BUF_SIZE 10
; #define LARGER_BUF_SIZE 30
;
; size_t foo1(int flag) {
;   char *cptr;
;   char chararray[LARGER_BUF_SIZE];
;   char chararray2[STATIC_BUF_SIZE];
;   if(flag)
;     cptr = chararray2;
;    else
;     cptr = chararray;
;
;   return  __builtin_object_size(cptr, 2);
; }
;
; size_t foo2(int n) {
;   char Small[10];
;   char Large[20];
;   char *Ptr = n ? Small : Large + 19;
;   return __builtin_object_size(Ptr, 0);
; }
;
; void foo() {
;   size_t ret;
;   size_t ret1;
;   ret = foo1(0);
;   ret1 = foo2(0);
;   printf("\n%d %d\n", ret, ret1);
; }

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str = private unnamed_addr constant [8 x i8] c"\0A%d %d\0A\00", align 1

define i64 @foo1(i32 %flag) {
entry:
  %chararray = alloca [30 x i8], align 16
  %chararray2 = alloca [10 x i8], align 1
  %0 = getelementptr inbounds [30 x i8], [30 x i8]* %chararray, i64 0, i64 0
  call void @llvm.lifetime.start.p0i8(i64 30, i8* %0)
  %1 = getelementptr inbounds [10 x i8], [10 x i8]* %chararray2, i64 0, i64 0
  call void @llvm.lifetime.start.p0i8(i64 10, i8* %1)
  %tobool = icmp eq i32 %flag, 0
  %cptr.0 = select i1 %tobool, i8* %0, i8* %1
  %2 = call i64 @llvm.objectsize.i64.p0i8(i8* %cptr.0, i1 true)
  call void @llvm.lifetime.end.p0i8(i64 10, i8* %1)
  call void @llvm.lifetime.end.p0i8(i64 30, i8* %0)
  ret i64 %2
; CHECK-LABEL: foo1
; CHECK:  ret i64 10
}

declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)

declare i64 @llvm.objectsize.i64.p0i8(i8*, i1)

declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)

define i64 @foo2(i32 %n) {
entry:
  %Small = alloca [10 x i8], align 1
  %Large = alloca [20 x i8], align 16
  %0 = getelementptr inbounds [10 x i8], [10 x i8]* %Small, i64 0, i64 0
  call void @llvm.lifetime.start.p0i8(i64 10, i8* %0)
  %1 = getelementptr inbounds [20 x i8], [20 x i8]* %Large, i64 0, i64 0
  call void @llvm.lifetime.start.p0i8(i64 20, i8* %1)
  %tobool = icmp ne i32 %n, 0
  %add.ptr = getelementptr inbounds [20 x i8], [20 x i8]* %Large, i64 0, i64 19
  %cond = select i1 %tobool, i8* %0, i8* %add.ptr
  %2 = call i64 @llvm.objectsize.i64.p0i8(i8* %cond, i1 false)
  call void @llvm.lifetime.end.p0i8(i64 20, i8* %1)
  call void @llvm.lifetime.end.p0i8(i64 10, i8* %0)
  ret i64 %2
; CHECK-LABEL: foo2
; CHECK:  ret i64 10
}

define void @foo() {
entry:
  %call = tail call i64 @foo1(i32 0)
  %call1 = tail call i64 @foo2(i32 0)
  %call2 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %call, i64 %call1)
  ret void
}

declare i32 @printf(i8* nocapture readonly, ...)