1; RUN: llvm-as < %s | llvm-dis > %t.orig
2; RUN: llvm-as < %s | llvm-c-test --echo --no-opaque-pointers > %t.echo
3; RUN: diff -w %t.orig %t.echo
4;
5; RUN: llvm-as -opaque-pointers < %s | llvm-dis > %t.orig_opaque
6; RUN: llvm-as -opaque-pointers < %s | llvm-c-test --echo > %t.echo_opaque
7; RUN: diff -w %t.orig_opaque %t.echo_opaque
8
9source_filename = "/test/Bindings/echo.ll"
10target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
11target triple = "x86_64-apple-macosx10.11.0"
12
13module asm "classical GAS"
14
15%S = type { i64, %S* }
16
17@var = global i32 42
18@ext = external global i32*
19@cst = constant %S { i64 1, %S* @cst }
20@tl = thread_local global { i64, %S* } { i64 1, %S* @cst }
21@arr = linkonce_odr global [5 x i8] [ i8 2, i8 3, i8 5, i8 7, i8 11 ]
22@str = private unnamed_addr constant [13 x i8] c"hello world\0A\00"
23@locStr = private local_unnamed_addr constant [13 x i8] c"hello world\0A\00"
24@hidden = hidden global i32 7
25@protected = protected global i32 23
26@section = global i32 27, section ".custom"
27@align = global i32 31, align 4
28@nullptr = global i32* null
29
30@const_gep = global i32* getelementptr (i32, i32* @var, i64 2)
31@const_inbounds_gep = global i32* getelementptr inbounds (i32, i32* @var, i64 1)
32
33@aliased1 = alias i32, i32* @var
34@aliased2 = internal alias i32, i32* @var
35@aliased3 = external alias i32, i32* @var
36@aliased4 = weak alias i32, i32* @var
37@aliased5 = weak_odr alias i32, i32* @var
38
39@ifunc = ifunc i32 (i32), i32 (i32)* ()* @ifunc_resolver
40
41define i32 (i32)* @ifunc_resolver() {
42entry:
43  ret i32 (i32)* null
44}
45
46define { i64, %S* } @unpackrepack(%S %s) {
47  %1 = extractvalue %S %s, 0
48  %2 = extractvalue %S %s, 1
49  %3 = insertvalue { i64, %S* } undef, %S* %2, 1
50  %4 = insertvalue { i64, %S* } %3, i64 %1, 0
51  ret { i64, %S* } %4
52}
53
54declare void @decl()
55
56; TODO: label and metadata types
57define void @types() {
58  %1 = alloca half, align 2
59  %2 = alloca float, align 4
60  %3 = alloca double, align 8
61  %4 = alloca x86_fp80, align 16
62  %5 = alloca fp128, align 16
63  %6 = alloca ppc_fp128, align 16
64  %7 = alloca i7, align 1
65  %8 = alloca void (i1)*, align 8
66  %9 = alloca [3 x i22], align 4
67  %10 = alloca i328 addrspace(5)*, align 8
68  %11 = alloca <5 x i23*>, align 64
69  %12 = alloca x86_mmx, align 8
70  ret void
71}
72
73define i32 @iops(i32 %a, i32 %b) {
74  %1 = add i32 %a, %b
75  %2 = mul i32 %a, %1
76  %3 = sub i32 %2, %1
77  %4 = udiv i32 %3, %b
78  %5 = sdiv i32 %2, %4
79  %6 = urem i32 %3, %5
80  %7 = srem i32 %2, %6
81  %8 = shl i32 %1, %b
82  %9 = lshr i32 %a, %7
83  %10 = ashr i32 %b, %8
84  %11 = and i32 %9, %10
85  %12 = or i32 %2, %11
86  %13 = xor i32 %12, %4
87  ret i32 %13
88}
89
90define i32 @call() {
91  %1 = call i32 @iops(i32 23, i32 19)
92  ret i32 %1
93}
94
95define i32 @cond(i32 %a, i32 %b) {
96  br label %br
97unreachable:
98  unreachable
99br:
100  %1 = icmp eq i32 %a, %b
101  br i1 %1, label %next0, label %unreachable
102next0:
103  %2 = icmp ne i32 %a, %b
104  br i1 %2, label %next1, label %unreachable
105next1:
106  %3 = icmp ugt i32 %a, %b
107  br i1 %3, label %next2, label %unreachable
108next2:
109  %4 = icmp uge i32 %a, %b
110  br i1 %4, label %next3, label %unreachable
111next3:
112  %5 = icmp ult i32 %a, %b
113  br i1 %5, label %next4, label %unreachable
114next4:
115  %6 = icmp ule i32 %a, %b
116  br i1 %6, label %next5, label %unreachable
117next5:
118  %7 = icmp sgt i32 %a, %b
119  br i1 %7, label %next6, label %unreachable
120next6:
121  %8 = icmp sge i32 %a, %b
122  br i1 %8, label %next7, label %unreachable
123next7:
124  %9 = icmp slt i32 %a, %b
125  br i1 %9, label %next8, label %unreachable
126next8:
127  %10 = icmp sle i32 %a, %b
128  br i1 %10, label %next9, label %unreachable
129next9:
130  ret i32 0
131}
132
133define i32 @loop(i32 %i) {
134  br label %cond
135cond:
136  %c = phi i32 [ %i, %0 ], [ %j, %do ]
137  %p = phi i32 [ %r, %do ], [ 789, %0 ]
138  %1 = icmp eq i32 %c, 0
139  br i1 %1, label %do, label %done
140do:
141  %2 = sub i32 %p, 23
142  %j = sub i32 %i, 1
143  %r = mul i32 %2, 3
144  br label %cond
145done:
146  ret i32 %p
147}
148
149define void @memops(i8* %ptr) {
150  %a = load i8, i8* %ptr
151  %b = load volatile i8, i8* %ptr
152  %c = load i8, i8* %ptr, align 8
153  %d = load atomic i8, i8* %ptr acquire, align 32
154  store i8 0, i8* %ptr
155  store volatile i8 0, i8* %ptr
156  store i8 0, i8* %ptr, align 8
157  store atomic i8 0, i8* %ptr release, align 32
158  %e = atomicrmw add i8* %ptr, i8 0 monotonic, align 1
159  %f = atomicrmw volatile xchg i8* %ptr, i8 0 acq_rel, align 8
160  %g = cmpxchg i8* %ptr, i8 1, i8 2 seq_cst acquire, align 1
161  %h = cmpxchg weak i8* %ptr, i8 1, i8 2 seq_cst acquire, align 8
162  %i = cmpxchg volatile i8* %ptr, i8 1, i8 2 monotonic monotonic, align 16
163  ret void
164}
165
166define i32 @vectorops(i32, i32) {
167  %a = insertelement <4 x i32> undef, i32 %0, i32 0
168  %b = insertelement <4 x i32> %a, i32 %1, i32 2
169  %c = shufflevector <4 x i32> %b, <4 x i32> undef, <4 x i32> zeroinitializer
170  %d = shufflevector <4 x i32> %c, <4 x i32> %b, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
171  %e = add <4 x i32> %d, %a
172  %f = mul <4 x i32> %e, %b
173  %g = xor <4 x i32> %f, %d
174  %h = or <4 x i32> %f, %e
175  %i = lshr <4 x i32> %h, <i32 2, i32 2, i32 2, i32 2>
176  %j = shl <4 x i32> %i, <i32 2, i32 3, i32 4, i32 5>
177  %k = shufflevector <4 x i32> %j, <4 x i32> %i, <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
178  %m = shufflevector <4 x i32> %k, <4 x i32> undef, <1 x i32> <i32 1>
179  %n = shufflevector <4 x i32> %j, <4 x i32> undef, <8 x i32> <i32 0, i32 0, i32 1, i32 2, i32 undef, i32 3, i32 undef, i32 undef>
180  %p = extractelement <8 x i32> %n, i32 5
181  ret i32 %p
182}
183
184define i32 @scalablevectorops(i32, <vscale x 4 x i32>) {
185  %a = insertelement <vscale x 4 x i32> undef, i32 %0, i32 0
186  %b = insertelement <vscale x 4 x i32> %a, i32 %0, i32 2
187  %c = shufflevector <vscale x 4 x i32> %b, <vscale x 4 x i32> undef, <vscale x 4 x i32> zeroinitializer
188  %e = add <vscale x 4 x i32> %a, %1
189  %f = mul <vscale x 4 x i32> %e, %b
190  %g = xor <vscale x 4 x i32> %f, %e
191  %h = or <vscale x 4 x i32> %g, %e
192  %i = lshr <vscale x 4 x i32> %h, undef
193  %j = extractelement <vscale x 4 x i32> %i, i32 3
194  ret i32 %j
195}
196
197declare void @personalityFn()
198
199define void @exn() personality void ()* @personalityFn {
200entry:
201  invoke void @decl()
202          to label %via.cleanup unwind label %exn.dispatch
203via.cleanup:
204  invoke void @decl()
205          to label %via.catchswitch unwind label %cleanup.inner
206cleanup.inner:
207  %cp.inner = cleanuppad within none []
208  cleanupret from %cp.inner unwind label %exn.dispatch
209via.catchswitch:
210  invoke void @decl()
211          to label %exit unwind label %dispatch.inner
212dispatch.inner:
213  %cs.inner = catchswitch within none [label %pad.inner] unwind label %exn.dispatch
214pad.inner:
215  %catch.inner = catchpad within %cs.inner [i32 0]
216  catchret from %catch.inner to label %exit
217exn.dispatch:
218  %cs = catchswitch within none [label %pad1, label %pad2] unwind label %cleanup
219pad1:
220  catchpad within %cs [i32 1]
221  unreachable
222pad2:
223  catchpad within %cs [i32 2]
224  unreachable
225cleanup:
226  %cp = cleanuppad within none []
227  cleanupret from %cp unwind to caller
228exit:
229  ret void
230}
231
232define void @with_debuginfo() !dbg !4 {
233  ret void, !dbg !7
234}
235
236declare i8* @llvm.stacksave()
237declare void @llvm.stackrestore(i8*)
238declare void @llvm.lifetime.start.p0i8(i64, i8*)
239declare void @llvm.lifetime.end.p0i8(i64, i8*)
240
241define void @test_intrinsics() {
242entry:
243  %sp = call i8* @llvm.stacksave()
244  %0 = alloca i8, align 1
245  call void @llvm.lifetime.start.p0i8(i64 1, i8* %0)
246  call void @llvm.lifetime.end.p0i8(i64 1, i8* %0)
247  call void @llvm.stackrestore(i8* %sp)
248  ret void
249}
250
251!llvm.dbg.cu = !{!0, !2}
252!llvm.module.flags = !{!3}
253
254!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
255!1 = !DIFile(filename: "echo.ll", directory: "/llvm/test/Bindings/llvm-c/echo.ll")
256!2 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
257!3 = !{i32 2, !"Debug Info Version", i32 3}
258!4 = distinct !DISubprogram(name: "with_debuginfo", linkageName: "_with_debuginfo", scope: null, file: !1, line: 42, type: !5, isLocal: false, isDefinition: true, scopeLine: 1519, flags: DIFlagPrototyped, isOptimized: true, unit: !0, templateParams: !6, retainedNodes: !6)
259!5 = !DISubroutineType(types: !6)
260!6 = !{}
261!7 = !DILocation(line: 42, scope: !8, inlinedAt: !11)
262!8 = distinct !DILexicalBlock(scope: !9, file: !1, line: 42, column: 12)
263!9 = distinct !DISubprogram(name: "fake_inlined_block", linkageName: "_fake_inlined_block", scope: null, file: !1, line: 82, type: !5, isLocal: false, isDefinition: true, scopeLine: 82, flags: DIFlagPrototyped, isOptimized: true, unit: !2, templateParams: !6, retainedNodes: !6)
264!10 = distinct !DILocation(line: 84, scope: !8, inlinedAt: !11)
265!11 = !DILocation(line: 42, scope: !4)
266