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)
10 ; RUN: opt -globalopt -instcombine -S %s -o - | FileCheck %s
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
16 ; CHECK: define i32 @main()
17 ; CHECK-NEXT: ret i32 0
19 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
20 target triple = "x86_64-apple-macosx10.12.0"
22 %struct.Bar = type { i32 }
23 %struct.S = type { i32 }
24 %struct.Foo = type { i32 }
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 }]
30 define internal void @__cxx_global_var_init() section "__TEXT,__StaticInit,regular,pure_instructions" {
31 call void @_ZN1SC1Ev_alias(%struct.S* @_s)
35 @_ZN1SC1Ev_alias = linkonce_odr unnamed_addr alias void (%struct.S*), void (%struct.S*)* @_ZN1SC1Ev
37 define 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)
46 %1 = alloca i32, align 4
47 store i32 0, i32* %1, align 4
51 define 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)
64 define 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
74 define 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
83 ; Function Attrs: noinline ssp uwtable
84 define internal void @_GLOBAL__sub_I_main.cpp() section "__TEXT,__StaticInit,regular,pure_instructions" {
85 call void @__cxx_global_var_init()