Skip to content

Commit 61cc308

Browse files
authored
fix: declare external pou initializers as external (#1290)
1 parent 15eb67e commit 61cc308

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

src/codegen/tests/debug_tests/snapshots/rusty__codegen__tests__debug_tests__expression_debugging__external_impl_is_not_added_as_external_subroutine.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ source_filename = "<internal>"
99
%myFb = type {}
1010

1111
@myPrg_instance = external global %myPrg, section "var-$RUSTY$myPrg_instance:r0", !dbg !0
12-
@__myFb__init = unnamed_addr constant %myFb zeroinitializer, section "var-$RUSTY$__myFb__init:r0", !dbg !5
12+
@__myFb__init = external global %myFb, section "var-$RUSTY$__myFb__init:r0", !dbg !5
1313

1414
declare i32 @myFunc() section "fn-$RUSTY$myFunc:i32"
1515

src/codegen/tests/initialization_test/global_initializers.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,45 @@ fn global_constant_without_initializer_gets_declared_initializer() {
153153
//should initialize cmd1 and cmd2 with @__comamnds__init
154154
insta::assert_snapshot!(result);
155155
}
156+
157+
#[test]
158+
fn external_pous_get_external_initializers() {
159+
let result = codegen(
160+
"
161+
{external} FUNCTION_BLOCK ext_fb END_FUNCTION_BLOCK
162+
{external} PROGRAM ext_prog END_PROGRAM
163+
",
164+
);
165+
166+
insta::assert_snapshot!(result, @r###"
167+
; ModuleID = '<internal>'
168+
source_filename = "<internal>"
169+
170+
%ext_fb = type {}
171+
%ext_prog = type {}
172+
173+
@__ext_fb__init = external global %ext_fb, section "var-$RUSTY$__ext_fb__init:r0"
174+
@ext_prog_instance = external global %ext_prog, section "var-$RUSTY$ext_prog_instance:r0"
175+
176+
declare void @ext_fb(%ext_fb*) section "fn-$RUSTY$ext_fb:v"
177+
178+
declare void @ext_prog(%ext_prog*) section "fn-$RUSTY$ext_prog:v"
179+
"###);
180+
}
181+
182+
#[test]
183+
#[ignore = "external struct initializers are not declared external"]
184+
fn external_aggregate_types_get_external_initializers() {
185+
let result = codegen(
186+
"
187+
{external}
188+
VAR_GLOBAL
189+
a: ARRAY[0..10] OF DINT;
190+
b: STRING;
191+
c: STRUCT a: INT; END_STRUCT
192+
END_VAR
193+
",
194+
);
195+
196+
insta::assert_snapshot!(result, @r###""###);
197+
}

src/index/visitor.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ pub fn visit_pou(index: &mut Index, pou: &Pou) {
147147
&pou.name,
148148
pou.name_location.clone(),
149149
)
150-
.set_constant(true);
150+
.set_constant(true)
151+
.set_linkage(pou.linkage);
151152
index.register_global_initializer(&global_struct_name, variable);
152153
index.register_pou(PouIndexEntry::create_function_block_entry(
153154
&pou.name,
@@ -165,7 +166,8 @@ pub fn visit_pou(index: &mut Index, pou: &Pou) {
165166
&pou.name,
166167
pou.name_location.clone(),
167168
)
168-
.set_constant(true);
169+
.set_constant(true)
170+
.set_linkage(pou.linkage);
169171
index.register_global_initializer(&global_struct_name, variable);
170172
index.register_pou(PouIndexEntry::create_class_entry(
171173
&pou.name,

0 commit comments

Comments
 (0)