Skip to content

Commit 2f5daca

Browse files
authored
fix alignment of emit_unbox_store copy (#52505)
The dest alignment might be determined to be greater than the source. For example, observed with: code_llvm(dump_module=true, optimize=false, (Int,)) do x Pair(ntuple(i -> 0x00, 8), x) end Where the alignment of the first field of the Pair is at least 4, but the alignment of the ntuple data is 1. (discovered while analyzing an ARM build failure @staticfloat)
1 parent 406f5b4 commit 2f5daca

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

doc/src/devdocs/debuggingtips.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,16 @@ useful.
4141

4242
## Useful Julia functions for Inspecting those variables
4343

44-
* `jl_gdblookup($rip)` :: For looking up the current function and line. (use `$eip` on i686 platforms)
44+
* `jl_print_task_backtraces(0)` :: Similar to gdb's `thread apply all bt` or lldb's `thread backtrace
45+
all`. Runs all threads while printing backtraces for all existing tasks.
46+
* `jl_gdblookup($pc)` :: For looking up the current function and line.
47+
* `jl_gdblookupinfo($pc)` :: For looking up the current method instance object.
48+
* `jl_gdbdumpcode(mi)` :: For dumping all of `code_typed/code_llvm/code_asm` when the REPL is not working right.
4549
* `jlbacktrace()` :: For dumping the current Julia backtrace stack to stderr. Only usable after
4650
`record_backtrace()` has been called.
4751
* `jl_dump_llvm_value(Value*)` :: For invoking `Value->dump()` in gdb, where it doesn't work natively.
4852
For example, `f->linfo->functionObject`, `f->linfo->specFunctionObject`, and `to_function(f->linfo)`.
53+
* `jl_dump_llvm_module(Module*)` :: For invoking `Module->dump()` in gdb, where it doesn't work natively.
4954
* `Type->dump()` :: only works in lldb. Note: add something like `;1` to prevent lldb from printing
5055
its prompt over the output
5156
* `jl_eval_string("expr")` :: for invoking side-effects to modify the current state or to lookup

src/aotcompile.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,6 +1820,58 @@ void addTargetPasses(legacy::PassManagerBase *PM, const Triple &triple, TargetIR
18201820
PM->add(createTargetTransformInfoWrapperPass(std::move(analysis)));
18211821
}
18221822

1823+
// sometimes in GDB you want to find out what code was created from a mi
1824+
extern "C" JL_DLLEXPORT_CODEGEN jl_code_info_t *jl_gdbdumpcode(jl_method_instance_t *mi)
1825+
{
1826+
jl_llvmf_dump_t llvmf_dump;
1827+
size_t world = jl_current_task->world_age;
1828+
JL_STREAM *stream = (JL_STREAM*)STDERR_FILENO;
1829+
1830+
jl_printf(stream, "---- dumping IR for ----\n");
1831+
jl_static_show(stream, (jl_value_t*)mi);
1832+
jl_printf(stream, "\n----\n");
1833+
1834+
jl_printf(stream, "\n---- unoptimized IR ----");
1835+
jl_get_llvmf_defn(&llvmf_dump, mi, world, 0, false, jl_default_cgparams);
1836+
if (llvmf_dump.F) {
1837+
jl_value_t *ir = jl_dump_function_ir(&llvmf_dump, 0, 1, "source");
1838+
jl_static_show(stream, ir);
1839+
}
1840+
jl_printf(stream, "----\n");
1841+
1842+
jl_printf(stream, "\n---- optimized IR ----");
1843+
jl_get_llvmf_defn(&llvmf_dump, mi, world, 0, true, jl_default_cgparams);
1844+
if (llvmf_dump.F) {
1845+
jl_value_t *ir = jl_dump_function_ir(&llvmf_dump, 0, 1, "source");
1846+
jl_static_show(stream, ir);
1847+
}
1848+
jl_printf(stream, "----\n");
1849+
1850+
jl_printf(stream, "\n---- assembly ----");
1851+
jl_get_llvmf_defn(&llvmf_dump, mi, world, 0, true, jl_default_cgparams);
1852+
if (llvmf_dump.F) {
1853+
jl_value_t *ir = jl_dump_function_asm(&llvmf_dump, 0, "", "source", 0, true);
1854+
jl_static_show(stream, ir);
1855+
}
1856+
jl_printf(stream, "----\n");
1857+
1858+
jl_code_info_t *src = NULL;
1859+
jl_value_t *ci = jl_default_cgparams.lookup(mi, world, world);
1860+
if (ci != jl_nothing) {
1861+
jl_code_instance_t *codeinst = (jl_code_instance_t*)ci;
1862+
src = (jl_code_info_t*)jl_atomic_load_relaxed(&codeinst->inferred);
1863+
if ((jl_value_t*)src != jl_nothing && !jl_is_code_info(src) && jl_is_method(mi->def.method)) {
1864+
JL_GC_PUSH2(&codeinst, &src);
1865+
src = jl_uncompress_ir(mi->def.method, codeinst, (jl_value_t*)src);
1866+
JL_GC_POP();
1867+
}
1868+
}
1869+
if (!src || (jl_value_t*)src == jl_nothing) {
1870+
src = jl_type_infer(mi, world, 0);
1871+
}
1872+
return src;
1873+
}
1874+
18231875
// --- native code info, and dump function to IR and ASM ---
18241876
// Get pointer to llvm::Function instance, compiling if necessary
18251877
// for use in reflection from Julia.

src/cgutils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2911,7 +2911,8 @@ static void init_bits_cgval(jl_codectx_t &ctx, Value *newv, const jl_cgval_t& v,
29112911
{
29122912
// newv should already be tagged
29132913
if (v.ispointer()) {
2914-
emit_memcpy(ctx, newv, jl_aliasinfo_t::fromTBAA(ctx, tbaa), v, jl_datatype_size(v.typ), sizeof(void*), julia_alignment(v.typ));
2914+
unsigned align = std::max(julia_alignment(v.typ), (unsigned)sizeof(void*));
2915+
emit_memcpy(ctx, newv, jl_aliasinfo_t::fromTBAA(ctx, tbaa), v, jl_datatype_size(v.typ), align, julia_alignment(v.typ));
29152916
}
29162917
else {
29172918
init_bits_value(ctx, newv, v.V, tbaa);

src/intrinsics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ static void emit_unbox_store(jl_codectx_t &ctx, const jl_cgval_t &x, Value *dest
520520
}
521521

522522
Value *src = data_pointer(ctx, x);
523-
emit_memcpy(ctx, dest, jl_aliasinfo_t::fromTBAA(ctx, tbaa_dest), src, jl_aliasinfo_t::fromTBAA(ctx, x.tbaa), jl_datatype_size(x.typ), alignment, alignment, isVolatile);
523+
emit_memcpy(ctx, dest, jl_aliasinfo_t::fromTBAA(ctx, tbaa_dest), src, jl_aliasinfo_t::fromTBAA(ctx, x.tbaa), jl_datatype_size(x.typ), alignment, julia_alignment(x.typ), isVolatile);
524524
}
525525

526526
static jl_datatype_t *staticeval_bitstype(const jl_cgval_t &targ)

0 commit comments

Comments
 (0)