From 26f3fe37f43ca473db366384712bc11b3eb61665 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Mon, 24 Jun 2024 16:00:47 +0200 Subject: [PATCH] Fix of built in aliases for headers. --- src/compiler/compiler_internal.h | 2 +- src/compiler/headers.c | 14 +++++++ src/compiler/sema_decls.c | 2 - src/compiler/types.c | 2 +- test/test_suite/visibility/export_property.c3 | 41 ------------------- .../test_suite/visibility/export_property.c3t | 39 ++++++++++++++++++ 6 files changed, 55 insertions(+), 45 deletions(-) delete mode 100644 test/test_suite/visibility/export_property.c3 create mode 100644 test/test_suite/visibility/export_property.c3t diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index baa689022..e71321293 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -3042,7 +3042,7 @@ static inline Type *type_flatten_no_export(Type *type) switch (type->type_kind) { case TYPE_TYPEDEF: - if (type->decl->is_export) return type; + if (!type->decl || type->decl->is_export) return type; type = type->canonical; break; case TYPE_DISTINCT: diff --git a/src/compiler/headers.c b/src/compiler/headers.c index f27e8f4f0..567917cb5 100644 --- a/src/compiler/headers.c +++ b/src/compiler/headers.c @@ -137,6 +137,15 @@ static void header_print_type(FILE *file, Type *type) header_print_type(file, type->decl->distinct->type); return; case TYPE_TYPEDEF: + if (!type->decl) + { + if (type == type_usz) { PRINTF("size_t"); return; } + if (type == type_isz) { PRINTF("ptrdiff_t"); return; } + if (type == type_iptr) { PRINTF("intptr_t"); return; } + if (type == type_uptr) { PRINTF("uintptr_t"); return; } + header_print_type(file, type->canonical); + return; + } if (type->decl->is_export) { PRINTF("%s", decl_get_extname(type->decl)); @@ -453,6 +462,11 @@ RETRY: } case TYPE_TYPEDEF: { + if (!type->decl) + { + type = type->canonical; + goto RETRY; + } assert(type->decl->is_export); if (htable_get(table, type)) return; htable_set(table, type, type); diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index 2ab6b33b2..531e8df38 100644 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -953,10 +953,8 @@ static void sema_recursively_import(Type *type) { if (!type) return; Decl *decl = type_no_export(type); - printf("Recursively import %s %p.\n", type->name, decl); if (!decl) return; decl->is_export = true; - printf("Recursively import %s.\n", type->name); if (decl->resolve_status != RESOLVE_DONE) return; decl->extname = NULL; assert(!decl->has_extname); diff --git a/src/compiler/types.c b/src/compiler/types.c index ed47c0932..23693affc 100644 --- a/src/compiler/types.c +++ b/src/compiler/types.c @@ -418,7 +418,7 @@ Decl *type_no_export(Type *type) case TYPE_DISTINCT: case TYPE_BITSTRUCT: case TYPE_TYPEDEF: - if (type->decl->is_export) return NULL; + if (!type->decl || type->decl->is_export) return NULL; return type->decl; case TYPE_SLICE: case TYPE_ARRAY: diff --git a/test/test_suite/visibility/export_property.c3 b/test/test_suite/visibility/export_property.c3 deleted file mode 100644 index 80d9f7d60..000000000 --- a/test/test_suite/visibility/export_property.c3 +++ /dev/null @@ -1,41 +0,0 @@ -fn Abcd test(Test a) @export -{ - return Abcd.ABC; -} - -fn void test2(Abc a) @export // #error: must also be an exported type -{ -} - -fault Abcd @export -{ - ABC, - EFG -} -enum Abc -{ - ABC, - DEF -} -struct Test @export -{ - struct - { - int a; - int b; - } - bitstruct : int - { - int fa : 1..6; - } - int[*] x; - -} - -struct Test2 @export -{ - struct - { - Abc d; // #error: must also be an exported type - } -} \ No newline at end of file diff --git a/test/test_suite/visibility/export_property.c3t b/test/test_suite/visibility/export_property.c3t new file mode 100644 index 000000000..567b8079a --- /dev/null +++ b/test/test_suite/visibility/export_property.c3t @@ -0,0 +1,39 @@ +// #target: macos-aarch64 +module test; +fn void test(Test a) @export +{ +} + +enum Abc +{ + ABC, + DEF +} +struct Test +{ + struct + { + int a; + int b; + } + bitstruct : int + { + int fa : 1..6; + } + Abc y; + int[*] x; +} + +/* #expect: test.ll + +%.introspect = type { i8, i64, ptr, i64, i64, i64, [0 x i64] } +%"char[]" = type { ptr, i64 } +%Test = type { %.anon, i32, i32, [0 x i32] } +%.anon = type { i32, i32 } + +@"$ct.test_$anon" = linkonce global %.introspect { i8 10, i64 0, ptr null, i64 8, i64 0, i64 2, [0 x i64] zeroinitializer }, align 8 +@"$ct.test_Test" = linkonce global %.introspect { i8 10, i64 0, ptr null, i64 16, i64 0, i64 4, [0 x i64] zeroinitializer }, align 8 +@.enum.ABC = internal constant [4 x i8] c"ABC\00", align 1 +@.enum.DEF = internal constant [4 x i8] c"DEF\00", align 1 +@"$ct.int" = linkonce global %.introspect { i8 2, i64 0, ptr null, i64 4, i64 0, i64 0, [0 x i64] zeroinitializer }, align 8 +@"$ct.test_Abc" = linkonce global { i8, i64, ptr, i64, i64, i64, [2 x %"char[]"] } { i8 8, i64 0, ptr null, i64 4, i64 ptrtoint (ptr @"$ct.int" to i64), i64 2, [2 x %"char[]"] [%"char[]" { ptr @.enum.ABC, i64 3 }, %"char[]" { ptr @.enum.DEF, i64 3 }] }, align 8