diff --git a/src/codegen/tests/debug_tests/snapshots/rusty__codegen__tests__debug_tests__expression_debugging__external_impl_is_not_added_as_external_subroutine.snap b/src/codegen/tests/debug_tests/snapshots/rusty__codegen__tests__debug_tests__expression_debugging__external_impl_is_not_added_as_external_subroutine.snap index 35c7900159..97b8d3fd27 100644 --- a/src/codegen/tests/debug_tests/snapshots/rusty__codegen__tests__debug_tests__expression_debugging__external_impl_is_not_added_as_external_subroutine.snap +++ b/src/codegen/tests/debug_tests/snapshots/rusty__codegen__tests__debug_tests__expression_debugging__external_impl_is_not_added_as_external_subroutine.snap @@ -9,7 +9,7 @@ source_filename = "" %myFb = type {} @myPrg_instance = external global %myPrg, section "var-$RUSTY$myPrg_instance:r0", !dbg !0 -@__myFb__init = unnamed_addr constant %myFb zeroinitializer, section "var-$RUSTY$__myFb__init:r0", !dbg !5 +@__myFb__init = external global %myFb, section "var-$RUSTY$__myFb__init:r0", !dbg !5 declare i32 @myFunc() section "fn-$RUSTY$myFunc:i32" diff --git a/src/codegen/tests/initialization_test/global_initializers.rs b/src/codegen/tests/initialization_test/global_initializers.rs index d534b130b4..91ceb76644 100644 --- a/src/codegen/tests/initialization_test/global_initializers.rs +++ b/src/codegen/tests/initialization_test/global_initializers.rs @@ -153,3 +153,45 @@ fn global_constant_without_initializer_gets_declared_initializer() { //should initialize cmd1 and cmd2 with @__comamnds__init insta::assert_snapshot!(result); } + +#[test] +fn external_pous_get_external_initializers() { + let result = codegen( + " + {external} FUNCTION_BLOCK ext_fb END_FUNCTION_BLOCK + {external} PROGRAM ext_prog END_PROGRAM + ", + ); + + insta::assert_snapshot!(result, @r###" + ; ModuleID = '' + source_filename = "" + + %ext_fb = type {} + %ext_prog = type {} + + @__ext_fb__init = external global %ext_fb, section "var-$RUSTY$__ext_fb__init:r0" + @ext_prog_instance = external global %ext_prog, section "var-$RUSTY$ext_prog_instance:r0" + + declare void @ext_fb(%ext_fb*) section "fn-$RUSTY$ext_fb:v" + + declare void @ext_prog(%ext_prog*) section "fn-$RUSTY$ext_prog:v" + "###); +} + +#[test] +#[ignore = "external struct initializers are not declared external"] +fn external_aggregate_types_get_external_initializers() { + let result = codegen( + " + {external} + VAR_GLOBAL + a: ARRAY[0..10] OF DINT; + b: STRING; + c: STRUCT a: INT; END_STRUCT + END_VAR + ", + ); + + insta::assert_snapshot!(result, @r###""###); +} diff --git a/src/index/visitor.rs b/src/index/visitor.rs index 991474d555..e2e1716fb2 100644 --- a/src/index/visitor.rs +++ b/src/index/visitor.rs @@ -147,7 +147,8 @@ pub fn visit_pou(index: &mut Index, pou: &Pou) { &pou.name, pou.name_location.clone(), ) - .set_constant(true); + .set_constant(true) + .set_linkage(pou.linkage); index.register_global_initializer(&global_struct_name, variable); index.register_pou(PouIndexEntry::create_function_block_entry( &pou.name, @@ -165,7 +166,8 @@ pub fn visit_pou(index: &mut Index, pou: &Pou) { &pou.name, pou.name_location.clone(), ) - .set_constant(true); + .set_constant(true) + .set_linkage(pou.linkage); index.register_global_initializer(&global_struct_name, variable); index.register_pou(PouIndexEntry::create_class_entry( &pou.name,