1; RUN: opt -codegenprepare -S < %s | FileCheck %s 2 3; #include<stdlib.h> 4; #define STATIC_BUF_SIZE 10 5; #define LARGER_BUF_SIZE 30 6; 7; size_t foo1(int flag) { 8; char *cptr; 9; char chararray[LARGER_BUF_SIZE]; 10; char chararray2[STATIC_BUF_SIZE]; 11; if(flag) 12; cptr = chararray2; 13; else 14; cptr = chararray; 15; 16; return __builtin_object_size(cptr, 2); 17; } 18; 19; size_t foo2(int n) { 20; char Small[10]; 21; char Large[20]; 22; char *Ptr = n ? Small : Large + 19; 23; return __builtin_object_size(Ptr, 0); 24; } 25; 26; void foo() { 27; size_t ret; 28; size_t ret1; 29; ret = foo1(0); 30; ret1 = foo2(0); 31; printf("\n%d %d\n", ret, ret1); 32; } 33 34target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 35target triple = "x86_64-unknown-linux-gnu" 36 37@.str = private unnamed_addr constant [8 x i8] c"\0A%d %d\0A\00", align 1 38 39define i64 @foo1(i32 %flag) { 40entry: 41 %chararray = alloca [30 x i8], align 16 42 %chararray2 = alloca [10 x i8], align 1 43 %0 = getelementptr inbounds [30 x i8], [30 x i8]* %chararray, i64 0, i64 0 44 call void @llvm.lifetime.start(i64 30, i8* %0) 45 %1 = getelementptr inbounds [10 x i8], [10 x i8]* %chararray2, i64 0, i64 0 46 call void @llvm.lifetime.start(i64 10, i8* %1) 47 %tobool = icmp eq i32 %flag, 0 48 %cptr.0 = select i1 %tobool, i8* %0, i8* %1 49 %2 = call i64 @llvm.objectsize.i64.p0i8(i8* %cptr.0, i1 true) 50 call void @llvm.lifetime.end(i64 10, i8* %1) 51 call void @llvm.lifetime.end(i64 30, i8* %0) 52 ret i64 %2 53; CHECK-LABEL: foo1 54; CHECK: ret i64 10 55} 56 57declare void @llvm.lifetime.start(i64, i8* nocapture) 58 59declare i64 @llvm.objectsize.i64.p0i8(i8*, i1) 60 61declare void @llvm.lifetime.end(i64, i8* nocapture) 62 63define i64 @foo2(i32 %n) { 64entry: 65 %Small = alloca [10 x i8], align 1 66 %Large = alloca [20 x i8], align 16 67 %0 = getelementptr inbounds [10 x i8], [10 x i8]* %Small, i64 0, i64 0 68 call void @llvm.lifetime.start(i64 10, i8* %0) 69 %1 = getelementptr inbounds [20 x i8], [20 x i8]* %Large, i64 0, i64 0 70 call void @llvm.lifetime.start(i64 20, i8* %1) 71 %tobool = icmp ne i32 %n, 0 72 %add.ptr = getelementptr inbounds [20 x i8], [20 x i8]* %Large, i64 0, i64 19 73 %cond = select i1 %tobool, i8* %0, i8* %add.ptr 74 %2 = call i64 @llvm.objectsize.i64.p0i8(i8* %cond, i1 false) 75 call void @llvm.lifetime.end(i64 20, i8* %1) 76 call void @llvm.lifetime.end(i64 10, i8* %0) 77 ret i64 %2 78; CHECK-LABEL: foo2 79; CHECK: ret i64 10 80} 81 82define void @foo() { 83entry: 84 %call = tail call i64 @foo1(i32 0) 85 %call1 = tail call i64 @foo2(i32 0) 86 %call2 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %call, i64 %call1) 87 ret void 88} 89 90declare i32 @printf(i8* nocapture readonly, ...)