1 ; RUN: llvm-as < %s | llvm-dis > %t.orig
2 ; RUN: llvm-as < %s | llvm-c-test --echo > %t.echo
3 ; RUN: diff -w %t.orig %t.echo
5 source_filename = "/test/Bindings/echo.ll"
6 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-apple-macosx10.11.0"
9 module asm "classical GAS"
11 %S = type { i64, ptr }
14 @ext = external global ptr
15 @cst = constant %S { i64 1, ptr @cst }
16 @tl = thread_local global { i64, ptr } { i64 1, ptr @cst }
17 @arr = linkonce_odr global [5 x i8] [ i8 2, i8 3, i8 5, i8 7, i8 11 ]
18 @str = private unnamed_addr constant [13 x i8] c"hello world\0A\00"
19 @locStr = private local_unnamed_addr constant [13 x i8] c"hello world\0A\00"
20 @hidden = hidden global i32 7
21 @protected = protected global i32 23
22 @section = global i32 27, section ".custom"
23 @align = global i32 31, align 4
24 @nullptr = global ptr null
26 @const_gep = global ptr getelementptr (i32, ptr @var, i64 2)
27 @const_inbounds_gep = global ptr getelementptr inbounds (i32, ptr @var, i64 1)
28 @const_gep_nuw = global ptr getelementptr nuw (i32, ptr @var, i64 1)
29 @const_gep_nusw = global ptr getelementptr nusw (i32, ptr @var, i64 1)
30 @const_gep_nuw_inbounds = global ptr getelementptr nuw inbounds (i32, ptr @var, i64 1)
32 @aliased1 = alias i32, ptr @var
33 @aliased2 = internal alias i32, ptr @var
34 @aliased3 = external alias i32, ptr @var
35 @aliased4 = weak alias i32, ptr @var
36 @aliased5 = weak_odr alias i32, ptr @var
38 @ifunc = ifunc i32 (i32), ptr @ifunc_resolver
40 @ptrauth_addr_disc = global i32 0
41 @ptrauth_data = global i32 0
42 @ptrauth_ptr_01 = global ptr ptrauth (ptr @ptrauth_data, i32 77, i64 1001, ptr @ptrauth_addr_disc)
43 @ptrauth_ptr_02 = global ptr ptrauth (ptr @ptrauth_data, i32 11, i64 99, ptr null)
45 define ptr @ifunc_resolver() {
50 define { i64, ptr } @unpackrepack(%S %s) {
51 %1 = extractvalue %S %s, 0
52 %2 = extractvalue %S %s, 1
53 %3 = insertvalue { i64, ptr } undef, ptr %2, 1
54 %4 = insertvalue { i64, ptr } %3, i64 %1, 0
60 ; TODO: label and metadata types
61 define void @types() {
62 %1 = alloca half, align 2
63 %2 = alloca float, align 4
64 %3 = alloca double, align 8
65 %4 = alloca x86_fp80, align 16
66 %5 = alloca fp128, align 16
67 %6 = alloca ppc_fp128, align 16
68 %7 = alloca i7, align 1
69 %8 = alloca ptr, align 8
70 %9 = alloca [3 x i22], align 4
71 %10 = alloca ptr addrspace(5), align 8
72 %11 = alloca <5 x ptr>, align 64
73 %12 = alloca x86_mmx, align 8
77 ; Target extension types:
78 define target("target.ext.1") @target_ext_01(target("target.ext.1") %0) {
79 ret target("target.ext.1") %0
82 define target("target.ext.2", i8, i1) @target_ext_02(target("target.ext.2", i8, i1) %0) {
83 ret target("target.ext.2", i8, i1) %0
86 define target("target.ext.3", 7) @target_ext_03(target("target.ext.3", 7) %0) {
87 ret target("target.ext.3", 7) %0
90 define target("target.ext.4", i1, i32, 7) @target_ext_04(target("target.ext.4", i1, i32, 7) %0) {
91 ret target("target.ext.4", i1, i32, 7) %0
94 define i32 @iops(i32 %a, i32 %b) {
104 %10 = ashr i32 %b, %8
105 %11 = and i32 %9, %10
107 %13 = xor i32 %12, %4
108 %14 = add nuw i32 %13, %a
109 %15 = add nsw i32 %14, %b
110 %16 = add nuw nsw i32 %15, %a
111 %17 = shl nuw i32 %16, %a
112 %18 = shl nsw i32 %17, %b
113 %19 = shl nuw nsw i32 %18, %a
114 %20 = udiv exact i32 %19, %1
115 %21 = sdiv exact i32 %20, %2
116 %22 = lshr exact i32 %21, %4
117 %23 = ashr exact i32 %22, %14
118 %24 = zext i32 %23 to i64
119 %25 = zext nneg i32 %23 to i64
120 %26 = or disjoint i32 %23, %a
125 %1 = call i32 @iops(i32 23, i32 19)
129 define i32 @tailcall() {
130 %1 = tail call i32 @call()
134 define i32 @musttailcall() {
135 %1 = musttail call i32 @call()
139 define i32 @notailcall() {
140 %1 = notail call i32 @call()
144 define i32 @call_inline_asm(i32 %0) {
146 %2 = tail call i32 asm sideeffect inteldialect "mov $0, $1", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %0)
147 %3 = tail call i32 asm sideeffect inteldialect "lea $0, [$1+$2]", "=r,r,r,~{dirflag},~{fpsr},~{flags}"(i32 %0, i32 %2)
148 %4 = tail call i32 asm inteldialect "mov $0, $1", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %3)
149 %5 = tail call i32 asm inteldialect unwind "mov $0, $1", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %4)
150 %6 = tail call i32 asm alignstack inteldialect "mov $0, $1", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %5)
153 %7 = tail call i32 asm "mov $1, $0", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %6)
154 %8 = tail call i32 asm sideeffect "mov $1, $0", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %7)
155 %9 = tail call i32 asm alignstack "mov $1, $0", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %8)
156 %10 = tail call i32 asm alignstack unwind "mov $1, $0", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %9)
160 define i32 @cond(i32 %a, i32 %b) {
165 %1 = icmp eq i32 %a, %b
166 br i1 %1, label %next0, label %unreachable
168 %2 = icmp ne i32 %a, %b
169 br i1 %2, label %next1, label %unreachable
171 %3 = icmp ugt i32 %a, %b
172 br i1 %3, label %next2, label %unreachable
174 %4 = icmp uge i32 %a, %b
175 br i1 %4, label %next3, label %unreachable
177 %5 = icmp ult i32 %a, %b
178 br i1 %5, label %next4, label %unreachable
180 %6 = icmp ule i32 %a, %b
181 br i1 %6, label %next5, label %unreachable
183 %7 = icmp sgt i32 %a, %b
184 br i1 %7, label %next6, label %unreachable
186 %8 = icmp sge i32 %a, %b
187 br i1 %8, label %next7, label %unreachable
189 %9 = icmp slt i32 %a, %b
190 br i1 %9, label %next8, label %unreachable
192 %10 = icmp sle i32 %a, %b
193 br i1 %10, label %next9, label %unreachable
198 define i32 @loop(i32 %i) {
201 %c = phi i32 [ %i, %0 ], [ %j, %do ]
202 %p = phi i32 [ %r, %do ], [ 789, %0 ]
203 %1 = icmp eq i32 %c, 0
204 br i1 %1, label %do, label %done
214 define void @memops(ptr %ptr) {
215 %a = load i8, ptr %ptr
216 %b = load volatile i8, ptr %ptr
217 %c = load i8, ptr %ptr, align 8
218 %d = load atomic i8, ptr %ptr acquire, align 32
220 store volatile i8 0, ptr %ptr
221 store i8 0, ptr %ptr, align 8
222 store atomic i8 0, ptr %ptr release, align 32
223 %e = atomicrmw add ptr %ptr, i8 0 monotonic, align 1
224 %f = atomicrmw volatile xchg ptr %ptr, i8 0 acq_rel, align 8
225 %g = cmpxchg ptr %ptr, i8 1, i8 2 seq_cst acquire, align 1
226 %h = cmpxchg weak ptr %ptr, i8 1, i8 2 seq_cst acquire, align 8
227 %i = cmpxchg volatile ptr %ptr, i8 1, i8 2 monotonic monotonic, align 16
231 define i32 @vectorops(i32, i32) {
232 %a = insertelement <4 x i32> undef, i32 %0, i32 0
233 %b = insertelement <4 x i32> %a, i32 %1, i32 2
234 %c = shufflevector <4 x i32> %b, <4 x i32> undef, <4 x i32> zeroinitializer
235 %d = shufflevector <4 x i32> %c, <4 x i32> %b, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
236 %e = add <4 x i32> %d, %a
237 %f = mul <4 x i32> %e, %b
238 %g = xor <4 x i32> %f, %d
239 %h = or <4 x i32> %f, %e
240 %i = lshr <4 x i32> %h, <i32 2, i32 2, i32 2, i32 2>
241 %j = shl <4 x i32> %i, <i32 2, i32 3, i32 4, i32 5>
242 %k = shufflevector <4 x i32> %j, <4 x i32> %i, <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
243 %m = shufflevector <4 x i32> %k, <4 x i32> undef, <1 x i32> <i32 1>
244 %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>
245 %p = extractelement <8 x i32> %n, i32 5
249 define i32 @scalablevectorops(i32, <vscale x 4 x i32>) {
250 %a = insertelement <vscale x 4 x i32> undef, i32 %0, i32 0
251 %b = insertelement <vscale x 4 x i32> %a, i32 %0, i32 2
252 %c = shufflevector <vscale x 4 x i32> %b, <vscale x 4 x i32> undef, <vscale x 4 x i32> zeroinitializer
253 %e = add <vscale x 4 x i32> %a, %1
254 %f = mul <vscale x 4 x i32> %e, %b
255 %g = xor <vscale x 4 x i32> %f, %e
256 %h = or <vscale x 4 x i32> %g, %e
257 %i = lshr <vscale x 4 x i32> %h, undef
258 %j = extractelement <vscale x 4 x i32> %i, i32 3
262 declare void @personalityFn()
264 define void @exn() personality ptr @personalityFn {
267 to label %via.cleanup unwind label %exn.dispatch
270 to label %via.catchswitch unwind label %cleanup.inner
272 %cp.inner = cleanuppad within none []
273 cleanupret from %cp.inner unwind label %exn.dispatch
276 to label %exit unwind label %dispatch.inner
278 %cs.inner = catchswitch within none [label %pad.inner] unwind label %exn.dispatch
280 %catch.inner = catchpad within %cs.inner [i32 0]
281 catchret from %catch.inner to label %exit
283 %cs = catchswitch within none [label %pad1, label %pad2] unwind label %cleanup
285 catchpad within %cs [i32 1]
288 catchpad within %cs [i32 2]
291 %cp = cleanuppad within none []
292 cleanupret from %cp unwind to caller
297 define void @operandbundles() personality ptr @personalityFn {
298 call void @decl() [ "foo"(), "bar\00x"(i32 0, ptr null, token none) ]
299 invoke void @decl() [ "baz"(label %bar) ] to label %foo unwind label %bar
303 %1 = landingpad { ptr, i32 }
308 define void @with_debuginfo() !dbg !4 {
312 declare ptr @llvm.stacksave()
313 declare void @llvm.stackrestore(ptr)
314 declare void @llvm.lifetime.start.p0(i64, ptr)
315 declare void @llvm.lifetime.end.p0(i64, ptr)
317 define void @test_intrinsics() {
319 %sp = call ptr @llvm.stacksave()
320 %0 = alloca i8, align 1
321 call void @llvm.lifetime.start.p0(i64 1, ptr %0)
322 call void @llvm.lifetime.end.p0(i64 1, ptr %0)
323 call void @llvm.stackrestore(ptr %sp)
327 define void @test_fast_math_flags(i1 %c, float %a, float %b) {
329 %select.f.1 = select i1 %c, float %a, float %b
330 %select.f.2 = select nsz i1 %c, float %a, float %b
331 %select.f.3 = select fast i1 %c, float %a, float %b
332 %select.f.4 = select nnan arcp afn i1 %c, float %a, float %b
334 br i1 %c, label %choose_a, label %choose_b
343 %phi.f.1 = phi float [ %a, %choose_a ], [ %b, %choose_b ]
344 %phi.f.2 = phi nsz float [ %a, %choose_a ], [ %b, %choose_b ]
345 %phi.f.3 = phi fast float [ %a, %choose_a ], [ %b, %choose_b ]
346 %phi.f.4 = phi nnan arcp afn float [ %a, %choose_a ], [ %b, %choose_b ]
350 define float @test_fast_math_flags_call_inner(float %a) {
354 define void @test_fast_math_flags_call_outer(float %a) {
355 %a.1 = call float @test_fast_math_flags_call_inner(float %a)
356 %a.2 = call nsz float @test_fast_math_flags_call_inner(float %a)
357 %a.3 = call fast float @test_fast_math_flags_call_inner(float %a)
358 %a.4 = call nnan arcp afn float @test_fast_math_flags_call_inner(float %a)
362 define void @test_func_prefix_data_01() prefix i32 123 {
366 define void @test_func_prefix_data_02() prefix i64 2000 {
370 %func_prolog_struct = type <{ i8, i8, ptr }>
372 define void @test_func_prologue_data_01() prologue %func_prolog_struct <{ i8 235, i8 8, ptr zeroinitializer}> {
377 define void @test_call_br_01(i32 %input) {
379 callbr void asm "nop", "r,!i"(i32 %input) to label %bb_01 [label %bb_02]
387 define void @test_call_br_02(i32 %input0, i32 %input1) {
389 ; Multiple indirect destinations, operand bundles, and arguments
390 callbr void asm "nop", "r,r,!i,!i"(i32 %input0, i32 %input1)
391 ["op0"(i32 %input1), "op1"(label %bb_02)]
392 to label %bb_01 [label %bb_03, label %bb_02]
402 define ptr @test_gep_no_wrap_flags(ptr %0) {
403 %gep.1 = getelementptr i8, ptr %0, i32 4
404 %gep.inbounds = getelementptr inbounds i8, ptr %0, i32 4
405 %gep.nuw = getelementptr nuw i8, ptr %0, i32 4
406 %gep.nuw.inbounds = getelementptr inbounds nuw i8, ptr %0, i32 4
407 %gep.nusw = getelementptr nusw i8, ptr %0, i32 4
411 !llvm.dbg.cu = !{!0, !2}
412 !llvm.module.flags = !{!3}
414 !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
415 !1 = !DIFile(filename: "echo.ll", directory: "/llvm/test/Bindings/llvm-c/echo.ll")
416 !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
417 !3 = !{i32 2, !"Debug Info Version", i32 3}
418 !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)
419 !5 = !DISubroutineType(types: !6)
421 !7 = !DILocation(line: 42, scope: !8, inlinedAt: !11)
422 !8 = distinct !DILexicalBlock(scope: !9, file: !1, line: 42, column: 12)
423 !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)
424 !10 = distinct !DILocation(line: 84, scope: !8, inlinedAt: !11)
425 !11 = !DILocation(line: 42, scope: !4)