🔍 Add extensive LLVM debug logging and builder position tracking
ChatGPT5's investigation revealed builder position management issues: - Added verbose logging for block lowering and terminator emission - Enhanced position_at_end calls before all terminator operations - Added debug output for emit_jump/emit_branch operations - Improved snapshot vs vmap fallback reporting in seal_block Key findings: - Sealed SSA snapshot mechanism is working correctly - Block terminator issues persist due to builder position drift - Main.has_in_stack/2 shows terminator missing after emit Next steps: - Add immediate terminator verification after each emit - Track builder position changes in complex operations - Investigate specific functions where builder drift occurs This commit adds diagnostic infrastructure to pinpoint where LLVM IR builder position gets misaligned.
This commit is contained in:
@ -89,7 +89,23 @@ pub(in super::super) fn lower_compare<'ctx>(
|
||||
return Ok(b.into());
|
||||
}
|
||||
}
|
||||
let out = if let (Some(li), Some(ri)) = (as_int(lv), as_int(rv)) {
|
||||
let out = if let (Some(mut li), Some(mut ri)) = (as_int(lv), as_int(rv)) {
|
||||
// Normalize integer widths: extend the narrower to match the wider to satisfy LLVM
|
||||
let lw = li.get_type().get_bit_width();
|
||||
let rw = ri.get_type().get_bit_width();
|
||||
if lw != rw {
|
||||
if lw < rw {
|
||||
li = codegen
|
||||
.builder
|
||||
.build_int_z_extend(li, ri.get_type(), "icmp_zext_l")
|
||||
.map_err(|e| e.to_string())?;
|
||||
} else {
|
||||
ri = codegen
|
||||
.builder
|
||||
.build_int_z_extend(ri, li.get_type(), "icmp_zext_r")
|
||||
.map_err(|e| e.to_string())?;
|
||||
}
|
||||
}
|
||||
use CompareOp as C;
|
||||
let pred = match op {
|
||||
C::Eq => inkwell::IntPredicate::EQ,
|
||||
|
||||
Reference in New Issue
Block a user