From 26c59b5a383bf2f8eab96f839281a0ac298c0f3c Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Thu, 28 Sep 2023 08:04:47 -0400 Subject: [PATCH 1/3] Support `DIAssignID` (LLVM 17) Adding support for `DIAssigID` is very straightforward, as it doessn't have any fields to parse (aside from `isDistinct`). This bumps the `llvm-pretty` submodule to bring in the related changes from elliottt/llvm-pretty#131. Fixes #258. --- disasm-test/Main.hs | 1 + disasm-test/tests/T258.c | 7 ++++ disasm-test/tests/T258.ll | 59 ++++++++++++++++++++++++++++ disasm-test/tests/T258.pre-llvm17.ll | 4 ++ src/Data/LLVM/BitCode/IR/Metadata.hs | 11 +++++- 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 disasm-test/tests/T258.c create mode 100644 disasm-test/tests/T258.ll create mode 100644 disasm-test/tests/T258.pre-llvm17.ll diff --git a/disasm-test/Main.hs b/disasm-test/Main.hs index 6c344d6..795ff4b 100644 --- a/disasm-test/Main.hs +++ b/disasm-test/Main.hs @@ -376,6 +376,7 @@ assemblyCube llvmver = TS.mkCUBE , "pre-llvm13" , "pre-llvm14" , "pre-llvm15" + , "pre-llvm17" ]) ] -- Somewhat unusually for tasty-sugar, we make the expectedSuffix the same diff --git a/disasm-test/tests/T258.c b/disasm-test/tests/T258.c new file mode 100644 index 0000000..604c6ad --- /dev/null +++ b/disasm-test/tests/T258.c @@ -0,0 +1,7 @@ +__attribute__((__noinline__)) void f(int* x) {} + +int main(void) { + int x; + f(&x); + return 0; +} diff --git a/disasm-test/tests/T258.ll b/disasm-test/tests/T258.ll new file mode 100644 index 0000000..1bdc534 --- /dev/null +++ b/disasm-test/tests/T258.ll @@ -0,0 +1,59 @@ +; ModuleID = 'T258.c' +source_filename = "T258.c" +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable +define dso_local void @f(ptr nocapture noundef %0) local_unnamed_addr #0 !dbg !10 { + call void @llvm.dbg.value(metadata ptr %0, metadata !16, metadata !DIExpression()), !dbg !17 + ret void, !dbg !18 +} + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable +define dso_local i32 @main() local_unnamed_addr #1 !dbg !19 { + call void @llvm.dbg.assign(metadata i1 undef, metadata !23, metadata !DIExpression(), metadata !24, metadata ptr undef, metadata !DIExpression()), !dbg !25 + ret i32 0, !dbg !26 +} + +; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) +declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #2 + +; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) +declare void @llvm.dbg.value(metadata, metadata, metadata) #3 + +attributes #0 = { mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +attributes #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) } +attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8} +!llvm.ident = !{!9} + +!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 17.0.2 (https://github.com/llvm/llvm-project b2417f51dbbd7435eb3aaf203de24de6754da50e)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "T258.c", directory: "/home/ryanscott/Documents/Hacking/Haskell/llvm-pretty-bc-parser/disasm-test/tests", checksumkind: CSK_MD5, checksum: "f929e28f718c84761ea699b3ede6b85d") +!2 = !{i32 7, !"Dwarf Version", i32 5} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = !{i32 1, !"wchar_size", i32 4} +!5 = !{i32 8, !"PIC Level", i32 2} +!6 = !{i32 7, !"PIE Level", i32 2} +!7 = !{i32 7, !"uwtable", i32 2} +!8 = !{i32 7, !"debug-info-assignment-tracking", i1 true} +!9 = !{!"clang version 17.0.2 (https://github.com/llvm/llvm-project b2417f51dbbd7435eb3aaf203de24de6754da50e)"} +!10 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !15) +!11 = !DISubroutineType(types: !12) +!12 = !{null, !13} +!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64) +!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!15 = !{!16} +!16 = !DILocalVariable(name: "x", arg: 1, scope: !10, file: !1, line: 1, type: !13) +!17 = !DILocation(line: 0, scope: !10) +!18 = !DILocation(line: 1, column: 47, scope: !10) +!19 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 3, type: !20, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !22) +!20 = !DISubroutineType(types: !21) +!21 = !{!14} +!22 = !{!23} +!23 = !DILocalVariable(name: "x", scope: !19, file: !1, line: 4, type: !14) +!24 = distinct !DIAssignID() +!25 = !DILocation(line: 0, scope: !19) +!26 = !DILocation(line: 6, column: 3, scope: !19) diff --git a/disasm-test/tests/T258.pre-llvm17.ll b/disasm-test/tests/T258.pre-llvm17.ll new file mode 100644 index 0000000..e02ee84 --- /dev/null +++ b/disasm-test/tests/T258.pre-llvm17.ll @@ -0,0 +1,4 @@ +SKIP_TEST + +This test case requires the use of the DIAssignID metadata node, which is only +available with LLVM 17 or later. diff --git a/src/Data/LLVM/BitCode/IR/Metadata.hs b/src/Data/LLVM/BitCode/IR/Metadata.hs index 028f4ae..28b8159 100644 --- a/src/Data/LLVM/BitCode/IR/Metadata.hs +++ b/src/Data/LLVM/BitCode/IR/Metadata.hs @@ -31,7 +31,7 @@ import Text.LLVM.Labels import qualified Codec.Binary.UTF8.String as UTF8 (decode) import Control.Applicative ((<|>)) import Control.Exception (throw) -import Control.Monad (foldM, guard, mplus, when) +import Control.Monad (foldM, guard, mplus, unless, when) import Data.Bits (shiftR, testBit, shiftL, (.&.), (.|.), bit, complement) import Data.Data (Data) import Data.Typeable (Typeable) @@ -1169,6 +1169,15 @@ parseMetadataEntry vt mt pm (fromEntry -> Just r) = return $! updateMetadataTable (addInlineDebugInfo (DebugInfoArgList dial)) pm + 47 -> label "METADATA_ASSIGN_ID" $ do + assertRecordSizeIn [1] + isDistinct <- parseField r 0 nonzero + -- Inspirted by a similar check in + -- https://github.com/llvm/llvm-project/blob/7a0b9daac9edde4293d2e9fdf30d8b35c04d16a6/llvm/lib/Bitcode/Reader/MetadataLoader.cpp#L2071-L2072 + unless isDistinct $ + fail "Invalid DIAssignID record. Must be distinct" + return $! updateMetadataTable + (addDebugInfo isDistinct DebugInfoAssignID) pm code -> fail ("unknown record code: " ++ show code) From f755a9c3ce677ce76049dfdd8b2adbb93c6b1e01 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Thu, 28 Sep 2023 08:07:46 -0400 Subject: [PATCH 2/3] README: Indicate support for LLVM 17 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2660a16..93184de 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ compilers. | | v14.0 | ✓ | | See [issues][llvm14] | | | v15.0 | ✓ | | See [issues][llvm15] | | | v16.0 | ✓ | | See [issues][llvm16] | +| | v17.0 | ✓ | | See [issues][llvm17] | | `clang++` | v3.4 | | | | | | v3.5 | | | | | | v3.6 | | | | @@ -68,3 +69,4 @@ the developers' documentation for more details and a rationale: [llvm14]: https://github.com/GaloisInc/llvm-pretty-bc-parser/issues?q=is%3Aopen+is%3Aissue+label%3Allvm%2F14.0 [llvm15]: https://github.com/GaloisInc/llvm-pretty-bc-parser/issues?q=is%3Aopen+is%3Aissue+label%3Allvm%2F15.0 [llvm16]: https://github.com/GaloisInc/llvm-pretty-bc-parser/issues?q=is%3Aopen+is%3Aissue+label%3Allvm%2F16.0 +[llvm17]: https://github.com/GaloisInc/llvm-pretty-bc-parser/issues?q=is%3Aopen+is%3Aissue+label%3Allvm%2F17.0 From a2d5ccb18e0f62c2009bc7e7a05ab05c92c01d94 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Thu, 28 Sep 2023 08:10:30 -0400 Subject: [PATCH 3/3] CI: Test LLVM 17 --- .github/workflows/llvm-quick-fuzz.yml | 3 ++- flake.nix | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/llvm-quick-fuzz.yml b/.github/workflows/llvm-quick-fuzz.yml index e1be050..52149af 100644 --- a/.github/workflows/llvm-quick-fuzz.yml +++ b/.github/workflows/llvm-quick-fuzz.yml @@ -35,7 +35,8 @@ jobs: os: [ubuntu-22.04] # See doc/developing.md ghc: ["9.2.8"] - llvm: [ "https://github.com/llvm/llvm-project/releases/download/llvmorg-16.0.2/clang+llvm-16.0.2-x86_64-linux-gnu-ubuntu-22.04.tar.xz" + llvm: [ "https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.2/clang+llvm-17.0.2-x86_64-linux-gnu-ubuntu-22.04.tar.xz" + , "https://github.com/llvm/llvm-project/releases/download/llvmorg-16.0.2/clang+llvm-16.0.2-x86_64-linux-gnu-ubuntu-22.04.tar.xz" , "https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.6/clang+llvm-15.0.6-x86_64-linux-gnu-ubuntu-18.04.tar.xz" , "https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz" , "https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/clang+llvm-13.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz" diff --git a/flake.nix b/flake.nix index 0f399c2..00516ce 100644 --- a/flake.nix +++ b/flake.nix @@ -152,6 +152,7 @@ "14" "15" "16" + "17" ] ); TESTS_PREP = wrap "llvm-pretty-bc-parser-TESTS_PREP"