1 ; Checks if bitcasted call expression can be evaluated
2 ; Given call expresion:
3 ; ptr @_ZL3fooP3Foo(ptr @gBar)
4 ; We evaluate call to function @_ZL3fooP3Foo casting both parameter and return value
5 ; Given call expression:
6 ; void @_ZL3bazP3Foo(ptr @gBar)
7 ; We evaluate call to function _ZL3bazP3Foo casting its parameter and check that evaluated value (nullptr)
10 ; RUN: opt -passes=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, ptr, ptr }] 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, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_main.cpp, ptr null }]
30 define internal void @__cxx_global_var_init() section "__TEXT,__StaticInit,regular,pure_instructions" {
31 call void @_ZN1SC1Ev_alias(ptr @_s)
35 @_ZN1SC1Ev_alias = linkonce_odr unnamed_addr alias void (ptr), ptr @_ZN1SC1Ev
37 define linkonce_odr void @_ZN1SC1Ev(ptr) unnamed_addr align 2 {
38 %2 = alloca ptr, align 8
39 store ptr %0, ptr %2, align 8
40 %3 = load ptr, ptr %2, align 8
41 call void @_ZN1SC2Ev(ptr %3)
46 %1 = alloca i32, align 4
47 store i32 0, ptr %1, align 4
51 define linkonce_odr void @_ZN1SC2Ev(ptr) unnamed_addr align 2 {
52 %2 = alloca ptr, align 8
53 store ptr %0, ptr %2, align 8
54 %3 = load ptr, ptr %2, align 8
55 %4 = call ptr @_ZL3fooP3Foo(ptr @gBar)
56 %5 = load i32, ptr %4, align 4
57 store i32 %5, ptr %3, align 4
58 call void @_ZL3bazP3Foo(ptr @gBar)
62 define internal ptr @_ZL3fooP3Foo(ptr) {
63 %2 = alloca ptr, align 8
64 store ptr %0, ptr %2, align 8
65 %3 = load ptr, ptr %2, align 8
66 store i32 1, ptr %3, align 4
67 %4 = load ptr, ptr %2, align 8
71 define internal void @_ZL3bazP3Foo(ptr) {
72 %2 = alloca ptr, align 8
73 store ptr %0, ptr %2, align 8
74 %3 = load ptr, ptr %2, align 8
75 store i32 2, ptr %3, align 4
79 ; Function Attrs: noinline ssp uwtable
80 define internal void @_GLOBAL__sub_I_main.cpp() section "__TEXT,__StaticInit,regular,pure_instructions" {
81 call void @__cxx_global_var_init()