Skip to content

Commit

Permalink
Support alignment in DILocalVariable
Browse files Browse the repository at this point in the history
Fixes #217.
  • Loading branch information
RyanGlScott committed Apr 10, 2023
1 parent 3a68590 commit 22c4fdc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
32 changes: 32 additions & 0 deletions disasm-test/tests/dilocalvariable.at-least-llvm14.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
;; Adapted from https://github.com/llvm/llvm-project/blob/2ede126b1b3fae52cddece5cf1f75b474a9c7932/llvm/test/Assembler/dilocalvariable.ll

; CHECK: !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}
!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}

!llvm.module.flags = !{!10}
!llvm.dbg.cu = !{!1}

!0 = distinct !DISubprogram(unit: !1)
!1 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
file: !2,
isOptimized: true, flags: "-O2",
splitDebugFilename: "abc.debug", emissionKind: 2)
!2 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
!3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!4 = !DILocation(scope: !0)

; CHECK: !5 = !DILocalVariable(name: "foo", arg: 3, scope: !0, file: !2, line: 7, type: !3, flags: DIFlagArtificial, align: 32)
; CHECK: !6 = !DILocalVariable(name: "foo", scope: !0, file: !2, line: 7, type: !3, flags: DIFlagArtificial)
!5 = !DILocalVariable(name: "foo", arg: 3,
scope: !0, file: !2, line: 7, type: !3,
flags: DIFlagArtificial, align: 32)
!6 = !DILocalVariable(name: "foo", scope: !0,
file: !2, line: 7, type: !3, flags: DIFlagArtificial)

; CHECK: !7 = !DILocalVariable(arg: 1, scope: !0)
; CHECK: !8 = !DILocalVariable(scope: !0)
!7 = !DILocalVariable(scope: !0, arg: 1)
!8 = !DILocalVariable(scope: !0)
!9 = distinct !{}

!10 = !{i32 2, !"Debug Info Version", i32 3}
2 changes: 1 addition & 1 deletion llvm-pretty
9 changes: 5 additions & 4 deletions src/Data/LLVM/BitCode/IR/Metadata.hs
Original file line number Diff line number Diff line change
Expand Up @@ -953,14 +953,14 @@ parseMetadataEntry vt mt pm (fromEntry -> Just r) =

adj i = i + hasTag

_alignInBits <-
alignInBits <-
if hasAlignment
then do n <- parseField r (adj 8) numeric
then do n <- parseField r 8 numeric
when ((n :: Word64) > fromIntegral (maxBound :: Word32))
(fail "Alignment value is too large")
return (fromIntegral n :: Word32)
return $ Just (fromIntegral n :: Word32)

else return 0
else return Nothing

dilv <- DILocalVariable
<$> (mdForwardRefOrNull ("dilvScope":ctx) mt
Expand All @@ -974,6 +974,7 @@ parseMetadataEntry vt mt pm (fromEntry -> Just r) =
<$> parseField r (adj 5) numeric) -- dilvType
<*> parseField r (adj 6) numeric -- dilvArg
<*> parseField r (adj 7) numeric -- dilvFlags
<*> pure alignInBits -- dilvAlignment
return $! updateMetadataTable
(addDebugInfo isDistinct (DebugInfoLocalVariable dilv)) pm

Expand Down

0 comments on commit 22c4fdc

Please sign in to comment.