Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion compiler/plc_ast/src/pre_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,14 @@ fn add_nested_datatypes(
types: &mut Vec<UserTypeDeclaration>,
location: &SourceLocation,
) {
let new_type_name = format!("{container_name}_"); // TODO: Naming convention (see plc_util/src/convention.rs)
// TODO: Naming convention (see plc_util/src/convention.rs)
let new_type_name = format!("{container_name}_");
// FIXME: When processing pointer-to-pointer types (e.g., alias variables pointing to existing pointers),
// the inner type is already a DataTypeDeclaration::Reference, so replace_data_type_with_reference_to
// returns None and nested type processing is skipped. This results in incomplete names like "__global_alias_var_"
// (with trailing underscore but no suffix) when the inner pointer type should be processed.
// We need to distinguish between pointer references (which should be processed) and other references
// (which should return None) to properly handle nested pointer structures.
if let Some(DataTypeDeclaration::Definition { mut data_type, location: inner_location, scope }) =
datatype.replace_data_type_with_reference_to(new_type_name.clone(), location)
{
Expand Down
17 changes: 9 additions & 8 deletions compiler/plc_driver/src/tests/multi_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn forward_declared_constant_is_also_marked_constant() {

declare !dbg !24 void @__user_init_foo(%foo*)

declare !dbg !29 void @mainProg(%mainProg*)
declare !dbg !30 void @mainProg(%mainProg*)

; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
Expand Down Expand Up @@ -238,13 +238,14 @@ fn forward_declared_constant_is_also_marked_constant() {
!25 = !DIFile(filename: "__initializers", directory: "")
!26 = !DISubroutineType(flags: DIFlagPublic, types: !27)
!27 = !{null, !28}
!28 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "__auto_pointer_to_foo", baseType: !10, size: 64, align: 64, dwarfAddressSpace: 1)
!29 = distinct !DISubprogram(name: "mainProg", linkageName: "mainProg", scope: !11, file: !11, line: 6, type: !30, scopeLine: 10, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !8)
!30 = !DISubroutineType(flags: DIFlagPublic, types: !31)
!31 = !{null, !32, !14}
!32 = !DICompositeType(tag: DW_TAG_structure_type, name: "mainProg", scope: !11, file: !11, line: 6, size: 16, align: 64, flags: DIFlagPublic, elements: !33, identifier: "mainProg")
!33 = !{!34}
!34 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !11, file: !11, line: 8, baseType: !14, size: 16, align: 16, flags: DIFlagPublic)
!28 = !DIDerivedType(tag: DW_TAG_typedef, name: "__AUTO_DEREF____auto_pointer_to_foo", scope: !3, file: !3, baseType: !29, align: 64)
!29 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "__auto_pointer_to_foo", baseType: !10, size: 64, align: 64, dwarfAddressSpace: 1)
!30 = distinct !DISubprogram(name: "mainProg", linkageName: "mainProg", scope: !11, file: !11, line: 6, type: !31, scopeLine: 10, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !8)
!31 = !DISubroutineType(flags: DIFlagPublic, types: !32)
!32 = !{null, !33, !14}
!33 = !DICompositeType(tag: DW_TAG_structure_type, name: "mainProg", scope: !11, file: !11, line: 6, size: 16, align: 64, flags: DIFlagPublic, elements: !34, identifier: "mainProg")
!34 = !{!35}
!35 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !11, file: !11, line: 8, baseType: !14, size: 16, align: 16, flags: DIFlagPublic)

; ModuleID = 'external_file2.st'
source_filename = "external_file2.st"
Expand Down
23 changes: 22 additions & 1 deletion src/codegen/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,28 @@ impl<'ink> DebugBuilder<'ink> {
align_bits,
inkwell::AddressSpace::from(ADDRESS_SPACE_GLOBAL),
);
self.register_concrete_type(name, DebugType::Derived(pointer_type));

// Handle auto-dereferencing pointers by creating a typedef if needed. This ensures
// that the DWARF information accurately reflects the intended usage (deref semantics) of the pointer type.
let ty = if let DataTypeInformation::Pointer { auto_deref: Some(_), .. } =
index.get_type(name).map(|it| it.get_type_information())?
{
let file = self.compile_unit.get_file();
let typedef_name = format!("__AUTO_DEREF__{name}");
self.debug_info.create_typedef(
pointer_type.as_type(),
&typedef_name,
file,
0, // Line 0 for built-in types
file.as_debug_info_scope(),
align_bits,
)
} else {
pointer_type
};

self.register_concrete_type(name, DebugType::Derived(ty));

Ok(())
}

Expand Down
Loading