From 990bb6981f6214d9c1bbf46fd9e9ce5596d3bf30 Mon Sep 17 00:00:00 2001 From: Daniel Gorin Date: Fri, 15 Oct 2021 12:07:31 +0000 Subject: [PATCH] Fix handling of GlobalAlias (#84) The rule for GlobalAlias was assuming the type of the alias matches the type of the aliasee (and both were pointers), but actually the aliasee is to be a pointer-to-type-of-the-alias. Adding a test-case that otherwise fails --- src/LLVM/Pretty.hs | 4 +--- tests/input/alias.ll | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 tests/input/alias.ll diff --git a/src/LLVM/Pretty.hs b/src/LLVM/Pretty.hs index e40c025..22ccce8 100644 --- a/src/LLVM/Pretty.hs +++ b/src/LLVM/Pretty.hs @@ -271,9 +271,7 @@ instance Pretty Global where kind | isConstant = "constant" | otherwise = "global" - pretty GlobalAlias {..} = global (pretty name) <+> "=" <+> pretty linkage <+> ppMaybe unnamedAddr <+> "alias" <+> pretty typ `cma` ppTyped aliasee - where - typ = getElementType type' + pretty GlobalAlias {..} = global (pretty name) <+> "=" <+> pretty linkage <+> ppMaybe unnamedAddr <+> "alias" <+> pretty type' `cma` ppTyped aliasee ppFunctionAttribute :: Either GroupID FunctionAttribute -> Doc ann ppFunctionAttribute (Left grpId) = pretty grpId diff --git a/tests/input/alias.ll b/tests/input/alias.ll new file mode 100644 index 0000000..5392787 --- /dev/null +++ b/tests/input/alias.ll @@ -0,0 +1,7 @@ +; ModuleID = 'simple module' + +define i32 @foo() { + ret i32 42 +} + +@bar = external alias i32 (), i32 ()* @foo