File: builtin-object-size-ptr.ll

package info (click to toggle)
llvm-toolchain-6.0 1:6.0-1~bpo9+1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 594,652 kB
  • sloc: cpp: 3,044,500; ansic: 595,051; asm: 271,890; python: 128,923; objc: 106,554; sh: 21,854; lisp: 10,191; pascal: 6,094; ml: 5,544; perl: 5,265; makefile: 2,214; cs: 2,027; xml: 686; php: 212; csh: 117
file content (34 lines) | stat: -rw-r--r-- 999 bytes parent folder | download | duplicates (11)
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
; RUN: opt -instcombine -S < %s | FileCheck %s

; int foo() {
; struct V { char buf1[10];
;            int b;
;            char buf2[10];
;           } var;
;
;           char *p = &var.buf1[1];
;           return __builtin_object_size (p, 0);
; }

%struct.V = type { [10 x i8], i32, [10 x i8] }

define i32 @foo() #0 {
entry:
  %var = alloca %struct.V, align 4
  %0 = bitcast %struct.V* %var to i8*
  call void @llvm.lifetime.start.p0i8(i64 28, i8* %0) #3
  %buf1 = getelementptr inbounds %struct.V, %struct.V* %var, i32 0, i32 0
  %arrayidx = getelementptr inbounds [10 x i8], [10 x i8]* %buf1, i64 0, i64 1
  %1 = call i64 @llvm.objectsize.i64.p0i8(i8* %arrayidx, i1 false)
  %conv = trunc i64 %1 to i32
  call void @llvm.lifetime.end.p0i8(i64 28, i8* %0) #3
  ret i32 %conv
; CHECK: ret i32 27
; CHECK-NOT: ret i32 -1
}

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

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

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