Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect pretty output ptr* #132

Closed
Ptival opened this issue Oct 27, 2023 · 2 comments
Closed

Incorrect pretty output ptr* #132

Ptival opened this issue Oct 27, 2023 · 2 comments

Comments

@Ptival
Copy link
Contributor

Ptival commented Oct 27, 2023

Encountered some incorrect roundtripping. Here is a fairly minimal reproducer:

define i32 @f(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8
  ret i32 0
}

Assembling to bitcode, parsing with llvm-pretty-bc-parser and then pretty-printing with ppModule yields:

source_filename = "./mini.ll"
target triple = "unknown-unknown-unknown-unknown-"
define default i32 @f(ptr %0) {
; <label>: 1
  %2 = alloca ptr, align 8
  store ptr %0, ptr* %2, align 8
  ret i32 0
}

which contains invalid LLVM IR ptr*. I'm assuming it's a llvm-pretty issue, though it could be the bitcode parser too...

I'm going to try and submit a patch.

@RyanGlScott
Copy link
Collaborator

This is an llvm-pretty-bc-parser issue rather than an llvm-pretty one, as the AST itself contains the pointer-to-ptr issue you observe, even before pretty-printing it:

λ> parseBitCodeFromFile "test.bc" >>= pPrint
Right
  Module
    { modSourceName = Just "test.ll"
    , modTriple =
        TargetTriple
          { ttArch = UnknownArch
          , ttSubArch = NoSubArch
          , ttVendor = UnknownVendor
          , ttOS = UnknownOS
          , ttEnv = UnknownEnvironment
          , ttObjFmt = UnknownObjectFormat
          }
    , modDataLayout = []
    , modTypes = []
    , modNamedMd = []
    , modUnnamedMd = []
    , modComdat = fromList []
    , modGlobals = []
    , modDeclares = []
    , modDefines =
        [ Define
            { defLinkage = Nothing
            , defVisibility = Just DefaultVisibility
            , defRetType = PrimType (Integer 32)
            , defName = Symbol "f"
            , defArgs =
                [ Typed { typedType = PtrOpaque , typedValue = Ident "0" } ]
            , defVarArgs = False
            , defAttrs = []
            , defSection = Nothing
            , defGC = Nothing
            , defBody =
                [ BasicBlock
                    { bbLabel = Just (Anon 1)
                    , bbStmts =
                        [ Result (Ident "2") (Alloca PtrOpaque Nothing (Just 8)) []
                        , Effect
                            (Store
                               Typed { typedType = PtrOpaque , typedValue = ValIdent (Ident "0") }
                               Typed
                                 { typedType = PtrTo PtrOpaque , typedValue = ValIdent (Ident "2") }
                               Nothing
                               (Just 8))
                            []
                        , Effect
                            (Ret
                               Typed
                                 { typedType = PrimType (Integer 32) , typedValue = ValInteger 0 })
                            []
                        ]
                    }
                ]
            , defMetadata = fromList []
            , defComdat = Nothing
            }
        ]
    , modInlineAsm = []
    , modAliases = []
    }

(Notice the PtrTo PtrOpaque part, which llvm-pretty faithfully prints as ptr*.)

Would you mind closing this issue and opening a new one on the llvm-pretty-bc-parser repo? I have more thoughts about what is causing this (and how we might fix it), but I'd prefer to do so once we have a proper home for the discussion.

@Ptival
Copy link
Contributor Author

Ptival commented Nov 1, 2023

Moving discussion here.

@Ptival Ptival closed this as completed Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants