🔧 Fix LLVM basic block naming collision (ChatGPT5)
- Add function name prefix to basic block labels to avoid cross-function conflicts - blocks.rs: create_basic_blocks now takes fn_label parameter - Format: 'Main_join_2_bb23' instead of just 'bb23' - Add conservative fallback for missing terminators (jump to next or entry) - This fixes 'Basic Block does not have terminator' verification error Analysis insights: - MIR output was correct (all blocks had terminators) - Problem was LLVM-side block name collision between functions - Classic case of 'Rust complexity' - simple C++ style fix works best - Sometimes the simplest solution is the right one\!
This commit is contained in:
@ -11,18 +11,19 @@ pub(in super::super) fn create_basic_blocks<'ctx>(
|
||||
codegen: &CodegenContext<'ctx>,
|
||||
llvm_func: FunctionValue<'ctx>,
|
||||
func: &MirFunction,
|
||||
fn_label: &str,
|
||||
) -> (HashMap<BasicBlockId, BasicBlock<'ctx>>, BasicBlock<'ctx>) {
|
||||
let mut bb_map: HashMap<BasicBlockId, BasicBlock> = HashMap::new();
|
||||
let entry_first = func.entry_block;
|
||||
let entry_bb = codegen
|
||||
.context
|
||||
.append_basic_block(llvm_func, &format!("bb{}", entry_first.as_u32()));
|
||||
.append_basic_block(llvm_func, &format!("{}_bb{}", fn_label, entry_first.as_u32()));
|
||||
bb_map.insert(entry_first, entry_bb);
|
||||
for bid in func.block_ids() {
|
||||
if bid == entry_first {
|
||||
continue;
|
||||
}
|
||||
let name = format!("bb{}", bid.as_u32());
|
||||
let name = format!("{}_bb{}", fn_label, bid.as_u32());
|
||||
let bb = codegen.context.append_basic_block(llvm_func, &name);
|
||||
bb_map.insert(bid, bb);
|
||||
}
|
||||
|
||||
@ -71,6 +71,27 @@ pub(in super::super) fn lower_boxcall<'ctx>(
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Minimal untyped fallback: Array.length with missing annotations
|
||||
if method == "length" && args.is_empty() {
|
||||
let fnty = i64t.fn_type(&[i64t.into()], false);
|
||||
let callee = codegen
|
||||
.module
|
||||
.get_function("nyash_array_length_h")
|
||||
.unwrap_or_else(|| codegen.module.add_function("nyash_array_length_h", fnty, None));
|
||||
let call = codegen
|
||||
.builder
|
||||
.build_call(callee, &[recv_h.into()], "alen_fallback")
|
||||
.map_err(|e| e.to_string())?;
|
||||
if let Some(d) = dst {
|
||||
let rv = call
|
||||
.try_as_basic_value()
|
||||
.left()
|
||||
.ok_or("array_length_h returned void".to_string())?;
|
||||
vmap.insert(*d, rv);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(mid) = method_id {
|
||||
invoke::try_handle_tagged_invoke(
|
||||
codegen,
|
||||
|
||||
Reference in New Issue
Block a user