@@ -406,3 +406,123 @@ fn dbg_declare_has_valid_metadata_references_for_methods() {
406
406
!16 = !DILocation(line: 4, column: 8, scope: !14)
407
407
"### ) ;
408
408
}
409
+
410
+ #[ test]
411
+ fn action_with_var_temp ( ) {
412
+ let codegen = codegen (
413
+ r"
414
+ FUNCTION main : DINT
415
+ PLC_PRG();
416
+ PLC_PRG.act();
417
+ END_FUNCTION
418
+
419
+ PROGRAM PLC_PRG
420
+ VAR_TEMP
421
+ x : DINT;
422
+ END_VAR
423
+
424
+ x := 0;
425
+ END_PROGRAM
426
+
427
+ ACTIONS
428
+ ACTION act
429
+ x := x + 1;
430
+ END_ACTION
431
+ END_ACTIONS
432
+ " ,
433
+ ) ;
434
+
435
+ assert_snapshot ! ( codegen, @r#"
436
+ ; ModuleID = '<internal>'
437
+ source_filename = "<internal>"
438
+
439
+ %PLC_PRG = type {}
440
+
441
+ @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @__init___Test, i8* null }]
442
+ @PLC_PRG_instance = global %PLC_PRG zeroinitializer, !dbg !0
443
+
444
+ define i32 @main() !dbg !9 {
445
+ entry:
446
+ %main = alloca i32, align 4, !dbg !12
447
+ call void @llvm.dbg.declare(metadata i32* %main, metadata !13, metadata !DIExpression()), !dbg !15
448
+ store i32 0, i32* %main, align 4, !dbg !12
449
+ call void @PLC_PRG(%PLC_PRG* @PLC_PRG_instance), !dbg !12
450
+ call void @PLC_PRG.act(%PLC_PRG* @PLC_PRG_instance), !dbg !16
451
+ %main_ret = load i32, i32* %main, align 4, !dbg !16
452
+ ret i32 %main_ret, !dbg !16
453
+ }
454
+
455
+ define void @PLC_PRG(%PLC_PRG* %0) !dbg !17 {
456
+ entry:
457
+ call void @llvm.dbg.declare(metadata %PLC_PRG* %0, metadata !20, metadata !DIExpression()), !dbg !21
458
+ %x = alloca i32, align 4, !dbg !21
459
+ call void @llvm.dbg.declare(metadata i32* %x, metadata !22, metadata !DIExpression()), !dbg !23
460
+ store i32 0, i32* %x, align 4, !dbg !21
461
+ store i32 0, i32* %x, align 4, !dbg !21
462
+ ret void, !dbg !21
463
+ }
464
+
465
+ define void @PLC_PRG.act(%PLC_PRG* %0) !dbg !24 {
466
+ entry:
467
+ call void @llvm.dbg.declare(metadata %PLC_PRG* %0, metadata !25, metadata !DIExpression()), !dbg !26
468
+ %x = alloca i32, align 4, !dbg !26
469
+ call void @llvm.dbg.declare(metadata i32* %x, metadata !27, metadata !DIExpression()), !dbg !28
470
+ store i32 0, i32* %x, align 4, !dbg !26
471
+ %load_x = load i32, i32* %x, align 4, !dbg !26
472
+ %tmpVar = add i32 %load_x, 1, !dbg !26
473
+ store i32 %tmpVar, i32* %x, align 4, !dbg !26
474
+ ret void, !dbg !26
475
+ }
476
+
477
+ ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
478
+ declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
479
+
480
+ define void @__init_plc_prg(%PLC_PRG* %0) {
481
+ entry:
482
+ %self = alloca %PLC_PRG*, align 8
483
+ store %PLC_PRG* %0, %PLC_PRG** %self, align 8
484
+ ret void
485
+ }
486
+
487
+ define void @__init___Test() {
488
+ entry:
489
+ call void @__init_plc_prg(%PLC_PRG* @PLC_PRG_instance)
490
+ ret void
491
+ }
492
+
493
+ attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
494
+
495
+ !llvm.module.flags = !{!5, !6}
496
+ !llvm.dbg.cu = !{!7}
497
+
498
+ !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
499
+ !1 = distinct !DIGlobalVariable(name: "PLC_PRG", scope: !2, file: !2, line: 7, type: !3, isLocal: false, isDefinition: true)
500
+ !2 = !DIFile(filename: "<internal>", directory: "")
501
+ !3 = !DICompositeType(tag: DW_TAG_structure_type, name: "PLC_PRG", scope: !2, file: !2, line: 7, align: 64, flags: DIFlagPublic, elements: !4, identifier: "PLC_PRG")
502
+ !4 = !{}
503
+ !5 = !{i32 2, !"Dwarf Version", i32 5}
504
+ !6 = !{i32 2, !"Debug Info Version", i32 3}
505
+ !7 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "RuSTy Structured text Compiler", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !8, splitDebugInlining: false)
506
+ !8 = !{!0}
507
+ !9 = distinct !DISubprogram(name: "main", linkageName: "main", scope: !2, file: !2, line: 2, type: !10, scopeLine: 3, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !7, retainedNodes: !4)
508
+ !10 = !DISubroutineType(flags: DIFlagPublic, types: !11)
509
+ !11 = !{null}
510
+ !12 = !DILocation(line: 3, column: 12, scope: !9)
511
+ !13 = !DILocalVariable(name: "main", scope: !9, file: !2, line: 2, type: !14, align: 32)
512
+ !14 = !DIBasicType(name: "DINT", size: 32, encoding: DW_ATE_signed, flags: DIFlagPublic)
513
+ !15 = !DILocation(line: 2, column: 17, scope: !9)
514
+ !16 = !DILocation(line: 4, column: 12, scope: !9)
515
+ !17 = distinct !DISubprogram(name: "PLC_PRG", linkageName: "PLC_PRG", scope: !2, file: !2, line: 7, type: !18, scopeLine: 12, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !7, retainedNodes: !4)
516
+ !18 = !DISubroutineType(flags: DIFlagPublic, types: !19)
517
+ !19 = !{null, !3}
518
+ !20 = !DILocalVariable(name: "PLC_PRG", scope: !17, file: !2, line: 12, type: !3)
519
+ !21 = !DILocation(line: 12, column: 12, scope: !17)
520
+ !22 = !DILocalVariable(name: "x", scope: !17, file: !2, line: 9, type: !14, align: 32)
521
+ !23 = !DILocation(line: 9, column: 12, scope: !17)
522
+ !24 = distinct !DISubprogram(name: "PLC_PRG.act", linkageName: "PLC_PRG.act", scope: !2, file: !2, line: 16, type: !18, scopeLine: 17, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !7, retainedNodes: !4)
523
+ !25 = !DILocalVariable(name: "PLC_PRG", scope: !24, file: !2, line: 17, type: !3)
524
+ !26 = !DILocation(line: 17, column: 16, scope: !24)
525
+ !27 = !DILocalVariable(name: "x", scope: !24, file: !2, line: 9, type: !14, align: 32)
526
+ !28 = !DILocation(line: 9, column: 12, scope: !24)
527
+ "# ) ;
528
+ }
0 commit comments