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

Support DIAssignID (LLVM 17) #261

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/llvm-quick-fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | | | |
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions disasm-test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@
, "pre-llvm13"
, "pre-llvm14"
, "pre-llvm15"
, "pre-llvm17"
])
]
-- Somewhat unusually for tasty-sugar, we make the expectedSuffix the same
Expand Down Expand Up @@ -912,7 +913,7 @@
_ -> const True
found = find matchOf $ Map.assocs knownBugs
getSummary (f,_) = (f
, head (fromMaybe [] (knownBugs ! f !? "summary:")

Check warning on line 916 in disasm-test/Main.hs

View workflow job for this annotation

GitHub Actions / build - 9.8.1 - ubuntu-22.04

In the use of ‘head’
<> ["this is a known bug"])
)
in getSummary <$> found
7 changes: 7 additions & 0 deletions disasm-test/tests/T258.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__attribute__((__noinline__)) void f(int* x) {}

int main(void) {
int x;
f(&x);
return 0;
}
59 changes: 59 additions & 0 deletions disasm-test/tests/T258.ll
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions disasm-test/tests/T258.pre-llvm17.ll
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"14"
"15"
"16"
"17"
]
);
TESTS_PREP = wrap "llvm-pretty-bc-parser-TESTS_PREP"
Expand Down
11 changes: 10 additions & 1 deletion src/Data/LLVM/BitCode/IR/Metadata.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
Loading