@@ -148,18 +148,10 @@ fn init_functions_generated_for_programs() {
148
148
ret void
149
149
}
150
150
151
- define void @__user_init_PLC_PRG(%PLC_PRG* %0) {
152
- entry:
153
- %self = alloca %PLC_PRG*, align 8
154
- store %PLC_PRG* %0, %PLC_PRG** %self, align 8
155
- ret void
156
- }
157
-
158
151
define void @__init___Test() {
159
152
entry:
160
153
call void @__init_plc_prg(%PLC_PRG* @PLC_PRG_instance)
161
154
call void @__user_init_PLC_PRG(%PLC_PRG* @PLC_PRG_instance)
162
- call void @__user_init_PLC_PRG(%PLC_PRG* @PLC_PRG_instance)
163
155
ret void
164
156
}
165
157
"# ) ;
@@ -567,7 +559,6 @@ fn nested_initializer_pous() {
567
559
}
568
560
569
561
#[ test]
570
- #[ ignore = "initializing references in same POU not yet supported" ]
571
562
fn local_address ( ) {
572
563
let res = generate_to_string (
573
564
"Test" ,
@@ -588,8 +579,7 @@ fn local_address() {
588
579
}
589
580
590
581
#[ test]
591
- #[ ignore = "initializing references in same POU not yet supported" ]
592
- fn tmpo ( ) {
582
+ fn user_init_called_for_variables_on_stack ( ) {
593
583
let result = generate_to_string (
594
584
"Test" ,
595
585
vec ! [ SourceCode :: from(
@@ -599,17 +589,83 @@ fn tmpo() {
599
589
i : INT;
600
590
pi: REF_TO INT;
601
591
END_VAR
592
+ METHOD FB_INIT
593
+ pi := ADR(i);
594
+ END_METHOD
602
595
END_FUNCTION_BLOCK
603
596
604
- ACTION foo.init
605
- pi := REF(i);
606
- END_ACTION
597
+ FUNCTION main
598
+ VAR
599
+ fb: foo;
600
+ END_VAR
601
+ fb();
602
+ END_FUNCTION
607
603
"# ,
608
604
) ] ,
609
605
)
610
606
. unwrap ( ) ;
611
607
612
- insta:: assert_snapshot!( result, @r###""### ) ;
608
+ insta:: assert_snapshot!( result, @r#"
609
+ ; ModuleID = '<internal>'
610
+ source_filename = "<internal>"
611
+
612
+ %foo = type { i16, i16* }
613
+
614
+ @__foo__init = constant %foo zeroinitializer
615
+ @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @__init___Test, i8* null }]
616
+
617
+ define void @foo(%foo* %0) {
618
+ entry:
619
+ %i = getelementptr inbounds %foo, %foo* %0, i32 0, i32 0
620
+ %pi = getelementptr inbounds %foo, %foo* %0, i32 0, i32 1
621
+ ret void
622
+ }
623
+
624
+ define void @foo__FB_INIT(%foo* %0) {
625
+ entry:
626
+ %i = getelementptr inbounds %foo, %foo* %0, i32 0, i32 0
627
+ %pi = getelementptr inbounds %foo, %foo* %0, i32 0, i32 1
628
+ store i16* %i, i16** %pi, align 8
629
+ ret void
630
+ }
631
+
632
+ define void @main() {
633
+ entry:
634
+ %fb = alloca %foo, align 8
635
+ %0 = bitcast %foo* %fb to i8*
636
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %0, i8* align 1 bitcast (%foo* @__foo__init to i8*), i64 ptrtoint (%foo* getelementptr (%foo, %foo* null, i32 1) to i64), i1 false)
637
+ call void @__init_foo(%foo* %fb)
638
+ call void @__user_init_foo(%foo* %fb)
639
+ call void @foo(%foo* %fb)
640
+ ret void
641
+ }
642
+
643
+ ; Function Attrs: argmemonly nofree nounwind willreturn
644
+ declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg) #0
645
+
646
+ define void @__init_foo(%foo* %0) {
647
+ entry:
648
+ %self = alloca %foo*, align 8
649
+ store %foo* %0, %foo** %self, align 8
650
+ ret void
651
+ }
652
+
653
+ define void @__user_init_foo(%foo* %0) {
654
+ entry:
655
+ %self = alloca %foo*, align 8
656
+ store %foo* %0, %foo** %self, align 8
657
+ %deref = load %foo*, %foo** %self, align 8
658
+ call void @foo__FB_INIT(%foo* %deref)
659
+ ret void
660
+ }
661
+
662
+ define void @__init___Test() {
663
+ entry:
664
+ ret void
665
+ }
666
+
667
+ attributes #0 = { argmemonly nofree nounwind willreturn }
668
+ "# ) ;
613
669
}
614
670
615
671
#[ test]
0 commit comments