1; Checks if bitcasted call expression can be evaluated 2; Given call expresion: 3; %struct.Bar* bitcast (%struct.Foo* (%struct.Foo*)* @_ZL3fooP3Foo to %struct.Bar* (%struct.Bar*)*)(%struct.Bar* @gBar) 4; We evaluate call to function @_ZL3fooP3Foo casting both parameter and return value 5; Given call expression: 6; void bitcast (void (%struct.Foo*)* @_ZL3bazP3Foo to void (%struct.Bar*)*)(%struct.Bar* @gBar) 7; We evaluate call to function _ZL3bazP3Foo casting its parameter and check that evaluated value (nullptr) 8; is handled correctly 9 10; RUN: opt -globalopt -instcombine -S %s -o - | FileCheck %s 11 12; CHECK: @gBar = local_unnamed_addr global %struct.Bar { i32 2 } 13; CHECK-NEXT: @_s = local_unnamed_addr global %struct.S { i32 1 }, align 4 14; CHECK-NEXT: @llvm.global_ctors = appending global [0 x { i32, void ()*, i8* }] zeroinitializer 15 16; CHECK: define i32 @main() 17; CHECK-NEXT: ret i32 0 18 19target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 20target triple = "x86_64-apple-macosx10.12.0" 21 22%struct.Bar = type { i32 } 23%struct.S = type { i32 } 24%struct.Foo = type { i32 } 25 26@gBar = global %struct.Bar zeroinitializer, align 4 27@_s = global %struct.S zeroinitializer, align 4 28@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_main.cpp, i8* null }] 29 30define internal void @__cxx_global_var_init() section "__TEXT,__StaticInit,regular,pure_instructions" { 31 call void @_ZN1SC1Ev_alias(%struct.S* @_s) 32 ret void 33} 34 35@_ZN1SC1Ev_alias = linkonce_odr unnamed_addr alias void (%struct.S*), void (%struct.S*)* @_ZN1SC1Ev 36 37define linkonce_odr void @_ZN1SC1Ev(%struct.S*) unnamed_addr align 2 { 38 %2 = alloca %struct.S*, align 8 39 store %struct.S* %0, %struct.S** %2, align 8 40 %3 = load %struct.S*, %struct.S** %2, align 8 41 call void @_ZN1SC2Ev(%struct.S* %3) 42 ret void 43} 44 45define i32 @main() { 46 %1 = alloca i32, align 4 47 store i32 0, i32* %1, align 4 48 ret i32 0 49} 50 51define linkonce_odr void @_ZN1SC2Ev(%struct.S*) unnamed_addr align 2 { 52 %2 = alloca %struct.S*, align 8 53 store %struct.S* %0, %struct.S** %2, align 8 54 %3 = load %struct.S*, %struct.S** %2, align 8 55 %4 = getelementptr inbounds %struct.S, %struct.S* %3, i32 0, i32 0 56 %5 = call %struct.Bar* bitcast (%struct.Foo* (%struct.Foo*)* @_ZL3fooP3Foo to %struct.Bar* (%struct.Bar*)*)(%struct.Bar* @gBar) 57 %6 = getelementptr inbounds %struct.Bar, %struct.Bar* %5, i32 0, i32 0 58 %7 = load i32, i32* %6, align 4 59 store i32 %7, i32* %4, align 4 60 call void bitcast (void (%struct.Foo*)* @_ZL3bazP3Foo to void (%struct.Bar*)*)(%struct.Bar* @gBar) 61 ret void 62} 63 64define internal %struct.Foo* @_ZL3fooP3Foo(%struct.Foo*) { 65 %2 = alloca %struct.Foo*, align 8 66 store %struct.Foo* %0, %struct.Foo** %2, align 8 67 %3 = load %struct.Foo*, %struct.Foo** %2, align 8 68 %4 = getelementptr inbounds %struct.Foo, %struct.Foo* %3, i32 0, i32 0 69 store i32 1, i32* %4, align 4 70 %5 = load %struct.Foo*, %struct.Foo** %2, align 8 71 ret %struct.Foo* %5 72} 73 74define internal void @_ZL3bazP3Foo(%struct.Foo*) { 75 %2 = alloca %struct.Foo*, align 8 76 store %struct.Foo* %0, %struct.Foo** %2, align 8 77 %3 = load %struct.Foo*, %struct.Foo** %2, align 8 78 %4 = getelementptr inbounds %struct.Foo, %struct.Foo* %3, i32 0, i32 0 79 store i32 2, i32* %4, align 4 80 ret void 81} 82 83; Function Attrs: noinline ssp uwtable 84define internal void @_GLOBAL__sub_I_main.cpp() section "__TEXT,__StaticInit,regular,pure_instructions" { 85 call void @__cxx_global_var_init() 86 ret void 87} 88