From bb48c9358a33e390a8279a5cfda36731a45d9a46 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Mon, 27 Nov 2023 01:41:27 +0000 Subject: [PATCH] fix #976 (asm mode): ensure we always have ptr bytes when reading ints since asm mode allows transparent type punning --- tests/alive-tv/asm/load.srctgt.ll | 13 +++++++++++++ tools/transform.cpp | 3 +++ 2 files changed, 16 insertions(+) create mode 100644 tests/alive-tv/asm/load.srctgt.ll diff --git a/tests/alive-tv/asm/load.srctgt.ll b/tests/alive-tv/asm/load.srctgt.ll new file mode 100644 index 000000000..ff2f5c612 --- /dev/null +++ b/tests/alive-tv/asm/load.srctgt.ll @@ -0,0 +1,13 @@ +target datalayout = "e-i64:64" + +@g = external global i64 + +define i64 @src() { + %1 = load i64, ptr @g, align 16 + ret i64 %1 +} + +define i64 @tgt() { + %1 = load i64, ptr @g + ret i64 %1 +} diff --git a/tools/transform.cpp b/tools/transform.cpp index 35a2135fd..616cc4e8e 100644 --- a/tools/transform.cpp +++ b/tools/transform.cpp @@ -1133,6 +1133,9 @@ static void calculateAndInitConstants(Transform &t) { if (!does_int_mem_access && !does_ptr_mem_access && has_fncall) does_int_mem_access = true; + if (does_int_mem_access && t.tgt.has(FnAttrs::Asm)) + does_ptr_mem_access = true; + auto has_attr = [&](ParamAttrs::Attribute a) -> bool { for (auto fn : { &t.src, &t.tgt }) { for (auto &v : fn->getInputs()) {