You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix backend panic when reading fields from aggregate constants #449
bugA problem that causes incorrect behavior or crashes.help wantedThe issue requires extra attention or help from others.needs testingIssues that require additional testing or verification.
I have reviewed the compiler panic occurring in llvm/src/codegen/address.rs. The root cause is a classic IR lowering mismatch: the compiler expects all base expressions of a field access to be runtime-addressable (backed by an alloca memory pointer), but aggregate constants exist natively as SSA values (or global constants), completely bypassing the local address environment.
To fix this and satisfy your acceptance criteria, you need to intercept the field access lowering step (likely in your codegen/expr.rs or codegen/address.rs) and introduce a bifurcated resolution path using LLVM's extractvalue instruction for pure SSA constants, rather than attempting a GEP (GetElementPtr) + Load combo.
Here is the architectural patch in Rust (assuming you are using inkwell or standard LLVM bindings):
// During AST -> IR lowering for Expr::FieldAccess(base, field_name)// 1. Resolve the symbol for the base expressionmatch env.get_symbol(&base.name){Some(Symbol::LocalVariable(ptr)) => {// [Existing Path] Base is in memory. Use GEP + Load.let field_ptr = builder.build_struct_gep(*ptr, field_index,"field_ptr").unwrap_or_else(|_| panic!("E9001 / ..."));// Existing error handlinglet loaded_val = builder.build_load(field_ptr,"load");return loaded_val;}Some(Symbol::Constant(const_value)) => {// [New Path] Base is a compile-time aggregate constant.// Do NOT try to fetch a local address. Use extract_value on the SSA struct.if const_value.is_struct_value(){let extracted = builder.build_extract_value(
const_value.into_struct_value(),
field_index,"extract_const_field").unwrap_or_else(|_| {// Raise a proper diagnostic rather than compiler panic if projection is invalid
session.emit_err(span,"Invalid constant projection");// Return dummy/poison value to allow compilation to fail gracefully
const_value
});return extracted;}elseif const_value.is_pointer_value(){// (Optional fallback) If you lowered the const as an LLVM GlobalVariablelet const_ptr = const_value.into_pointer_value();let field_ptr = builder.build_struct_gep(const_ptr, field_index,"const_gep").unwrap();return builder.build_load(field_ptr,"const_load");}}None => {// Replace E9001 internal panic with a graceful diagnostic
session.emit_err(span,format!("Variable {} not found", base.name));}}
This structural change guarantees that:
BOX.value correctly maps to an extractvalue instruction (or global load) returning 7.
E9001 is bypassed natively.
If an unsupported projection occurs (e.g. nested arrays inside consts that you haven't wired up yet), the unwrap_or_else cleanly converts the internal LLVM panic into a standard compiler diagnostic.
I have reviewed the compiler panic occurring in llvm/src/codegen/address.rs. The root cause is a classic IR lowering mismatch: the compiler expects all base expressions of a field access to be runtime-addressable (backed by an alloca memory pointer), but aggregate constants exist natively as SSA values (or global constants), completely bypassing the local address environment.
To fix this and satisfy your acceptance criteria, you need to intercept the field access lowering step (likely in your codegen/expr.rs or codegen/address.rs) and introduce a bifurcated resolution path using LLVM's extractvalue instruction for pure SSA constants, rather than attempting a GEP (GetElementPtr) + Load combo.
Here is the architectural patch in Rust (assuming you are using inkwell or standard LLVM bindings):
// During AST -> IR lowering for Expr::FieldAccess(base, field_name)// 1. Resolve the symbol for the base expressionmatch env.get_symbol(&base.name){Some(Symbol::LocalVariable(ptr)) => {// [Existing Path] Base is in memory. Use GEP + Load.let field_ptr = builder.build_struct_gep(*ptr, field_index,"field_ptr").unwrap_or_else(|_| panic!("E9001 / ..."));// Existing error handlinglet loaded_val = builder.build_load(field_ptr,"load");return loaded_val;}Some(Symbol::Constant(const_value)) => {// [New Path] Base is a compile-time aggregate constant.// Do NOT try to fetch a local address. Use extract_value on the SSA struct.if const_value.is_struct_value(){let extracted = builder.build_extract_value(
const_value.into_struct_value(),
field_index,"extract_const_field").unwrap_or_else(|_| {// Raise a proper diagnostic rather than compiler panic if projection is invalid
session.emit_err(span,"Invalid constant projection");// Return dummy/poison value to allow compilation to fail gracefully
const_value
});return extracted;}elseif const_value.is_pointer_value(){// (Optional fallback) If you lowered the const as an LLVM GlobalVariablelet const_ptr = const_value.into_pointer_value();let field_ptr = builder.build_struct_gep(const_ptr, field_index,"const_gep").unwrap();return builder.build_load(field_ptr,"const_load");}}None => {// Replace E9001 internal panic with a graceful diagnostic
session.emit_err(span,format!("Variable {} not found", base.name));}}
This structural change guarantees that:
BOX.value correctly maps to an extractvalue instruction (or global load) returning 7.
E9001 is bypassed natively.
If an unsupported projection occurs (e.g. nested arrays inside consts that you haven't wired up yet), the unwrap_or_else cleanly converts the internal LLVM panic into a standard compiler diagnostic.
However, I’d appreciate it if you could contribute by submitting a PR rather than opening an issue. Please refer to the GitHub section of the contribution guide.
Audited canonical master e1f8effd195b6339c3979b1e091e63c25f1da983 on Linux amd64 with checkout-built Wave 0.0.1-alpha-dev, matching std, Rust 1.89.0, Cargo jobs=2 and LLVM 21.1.8. The master SHA was rechecked before registration. This concerns the existing requirement to reject mutation and writable addresses of constants. It is not a new request for aggregate read support.
Observed: check accepts the assignment. LLVM IR generation reports E9001 with Variable A not found from llvm/src/codegen/address.rs:141. The direct form A[0] = 2 is correctly rejected. The struct equivalent and increment also reproduce the missing semantic rejection:
struct S { x: i32; }
const A: S = S { x: 1 };
fun main() {
deref A.x = 2;
}
Separate array variant: ++(deref A[0]);.
Starting point: find_base_var marks every Deref as pointer indirection, and assignment mutability validation uses that flag. A dereference around an aggregate projection must not automatically erase the constant-base mutability restriction. The current address lowering failure happens too late.
Remaining acceptance checks:
Reject constant aggregate assignment, compound assignment, increment/decrement and writable-address bypasses during semantic analysis, with the source span.
Retain valid scalar/aggregate constant reads and valid writes through a genuinely mutable pointee where the existing language contract permits them.
Test direct/grouped/dereferenced array and struct projections and ensure unsupported forms never reach E9001.
This was a semantic-check/IR reproduction; the invalid programs were not executed. Existing history, assignees and issue state are preserved by this update.
bugA problem that causes incorrect behavior or crashes.help wantedThe issue requires extra attention or help from others.needs testingIssues that require additional testing or verification.
Activity
pieromachacuaycabrera-cyber commentedon Sep 3, 2026
I have reviewed the compiler panic occurring in
llvm/src/codegen/address.rs. The root cause is a classic IR lowering mismatch: the compiler expects all base expressions of a field access to be runtime-addressable (backed by anallocamemory pointer), but aggregate constants exist natively as SSA values (or global constants), completely bypassing the local address environment.To fix this and satisfy your acceptance criteria, you need to intercept the field access lowering step (likely in your
codegen/expr.rsorcodegen/address.rs) and introduce a bifurcated resolution path using LLVM'sextractvalueinstruction for pure SSA constants, rather than attempting aGEP(GetElementPtr) +Loadcombo.Here is the architectural patch in Rust (assuming you are using
inkwellor standard LLVM bindings):This structural change guarantees that:
BOX.valuecorrectly maps to anextractvalueinstruction (or global load) returning7.unwrap_or_elsecleanly converts the internal LLVM panic into a standard compiler diagnostic.I hope this architectural patch saves you some debugging time! If you found my contribution helpful, I’d really appreciate a coffee/tip to support my open-source work: https://www.paypal.me/Asi150403
LunaStev commentedon Sep 3, 2026
Thank you!
However, I’d appreciate it if you could contribute by submitting a PR rather than opening an issue. Please refer to the GitHub section of the contribution guide.
LunaStev commentedon Nov 3, 2026
Current-master reproduction: explicit dereference bypasses constant projection mutation checks
Audited canonical master
e1f8effd195b6339c3979b1e091e63c25f1da983on Linux amd64 with checkout-built Wave 0.0.1-alpha-dev, matching std, Rust 1.89.0, Cargo jobs=2 and LLVM 21.1.8. The master SHA was rechecked before registration. This concerns the existing requirement to reject mutation and writable addresses of constants. It is not a new request for aggregate read support.Save as repro.wave:
Observed: check accepts the assignment. LLVM IR generation reports E9001 with Variable A not found from llvm/src/codegen/address.rs:141. The direct form A[0] = 2 is correctly rejected. The struct equivalent and increment also reproduce the missing semantic rejection:
Separate array variant: ++(deref A[0]);.
Starting point: find_base_var marks every Deref as pointer indirection, and assignment mutability validation uses that flag. A dereference around an aggregate projection must not automatically erase the constant-base mutability restriction. The current address lowering failure happens too late.
Remaining acceptance checks:
This was a semantic-check/IR reproduction; the invalid programs were not executed. Existing history, assignees and issue state are preserved by this update.