Unable to access fields of a const inline enum with an aggregate underlying type. #2802

This commit is contained in:
Christoffer Lerno
2026-01-21 13:22:46 +01:00
parent a126a25d66
commit cef48482f1
3 changed files with 45 additions and 0 deletions

View File

@@ -99,6 +99,7 @@
- When a global const has invalid attributes, handling is incorrect, leading to a crash #2785. - When a global const has invalid attributes, handling is incorrect, leading to a crash #2785.
- `int? ?` was not correctly handled. #2786 - `int? ?` was not correctly handled. #2786
- Casting const bytes to vector with different element size was broken #2787 - Casting const bytes to vector with different element size was broken #2787
- Unable to access fields of a const inline enum with an aggregate underlying type. #2802
### Stdlib changes ### Stdlib changes
- Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads. - Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads.

View File

@@ -251,6 +251,14 @@ Expr *sema_enter_inline_member(Expr *parent, CanonicalType *type)
expr->type = type; expr->type = type;
break; break;
} }
case TYPE_CONST_ENUM:
{
Decl *decl = type->decl;
if (!decl->is_substruct) return NULL;
expr = expr_copy(parent);
expr->type = decl->enums.type_info->type;
return expr;
}
case TYPE_ENUM: case TYPE_ENUM:
{ {
Decl *decl = type->decl; Decl *decl = type->decl;

View File

@@ -0,0 +1,36 @@
// #target: macos-x64
module test;
struct Bar
{
uint x, y, z;
}
enum Foo : const inline Bar
{
X = {1, 0, 0},
Y = {0, 1, 0},
Z = {0, 0, 1},
}
fn int main()
{
uint a = Foo.X.x;
Foo b = X;
uint c = b.y;
return 0;
}
/* #expect: test.ll
define i32 @main() #0 {
entry:
%a = alloca i32, align 4
%b = alloca %Bar, align 4
%c = alloca i32, align 4
store i32 1, ptr %a, align 4
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %b, ptr align 4 @.__const, i32 12, i1 false)
%ptradd = getelementptr inbounds i8, ptr %b, i64 4
%0 = load i32, ptr %ptradd, align 4
store i32 %0, ptr %c, align 4
ret i32 0
}