diff --git a/disasm-test/tests/dilocalvariable.at-least-llvm14.ll b/disasm-test/tests/dilocalvariable.at-least-llvm14.ll new file mode 100644 index 00000000..05b84498 --- /dev/null +++ b/disasm-test/tests/dilocalvariable.at-least-llvm14.ll @@ -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} diff --git a/llvm-pretty b/llvm-pretty index cd9a513f..9f776215 160000 --- a/llvm-pretty +++ b/llvm-pretty @@ -1 +1 @@ -Subproject commit cd9a513fcf33312824cdc0ecd6e3ca7172bc592f +Subproject commit 9f7762155226ad576cf4ff843eada0a73c4aaed4 diff --git a/src/Data/LLVM/BitCode/IR/Metadata.hs b/src/Data/LLVM/BitCode/IR/Metadata.hs index e42f6a7c..598d42d8 100644 --- a/src/Data/LLVM/BitCode/IR/Metadata.hs +++ b/src/Data/LLVM/BitCode/IR/Metadata.hs @@ -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 @@ -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