diff --git a/releasenotes.md b/releasenotes.md index f589c18c1..70040444e 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -60,6 +60,7 @@ - Incorrect handling of constant null fault causing compiler crash #2232. - Overload resolution fixes to inline typedef #2226. - `math::overflow_*` wrappers incorrectly don't allow distinct integers #2221. +- Compiler segfault when using distinct type in attribute imported from other module #2234. ### Stdlib changes - Deprecate `String.is_zstr` and `String.quick_zstr` #2188. diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index a93458953..955cf2002 100755 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -3529,7 +3529,9 @@ static inline bool sema_analyse_custom_attribute(SemaContext *context, ResolvedA Expr *expr = args[j]; if (param->var.type_info) { + if (!sema_resolve_type_info(context, type_infoptr(param->var.type_info), RESOLVE_TYPE_DEFAULT)) return false; Type *type = typeget(param->var.type_info); + ASSERT_SPAN(decl, type); if (!sema_analyse_inferred_expr(context, type, expr)) goto ERR; if (!cast_implicit(context, expr, type, false)) goto ERR; if (!sema_cast_const(expr)) diff --git a/test/test_suite/attributes/attribute_no_infer_type.c3t b/test/test_suite/attributes/attribute_no_infer_type.c3t new file mode 100644 index 000000000..a08f6d401 --- /dev/null +++ b/test/test_suite/attributes/attribute_no_infer_type.c3t @@ -0,0 +1,23 @@ +module test; +import other; + +struct Foo @Attr(0) {int x;} + +fn void main() +{ + Foo x; +} +module other; +typedef MyInt = int; +attrdef @Attr(MyInt x); + +/* #expect: test.ll + +@"$ct.test.Foo" = linkonce global %.introspect { i8 9, i64 0, ptr null, i64 4, i64 0, i64 1, [0 x i64] zeroinitializer }, align 8 + +define void @test.main() #0 { +entry: + %x = alloca %Foo, align 4 + store i32 0, ptr %x, align 4 + ret void +}