aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/DebugInfo.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-03-14[RemoveDIs][NFC] Move DPValue::filter -> filterDbgVars (#85208)Stephen Tozer1-2/+2
This patch changes DPValue::filter to be a non-member method filterDbgVars. There are two reasons for this: firstly, the name of DPValue is about to change to DbgVariableRecord, which will result in every `for` loop that uses DPValue::filter to require a line break. This is a small thing, but it makes the rename patch more difficult to review, and is just generally more awkward for what is a fairly common loop. Secondly, the intent is to later break up the DPValue class into subclasses, at which point it would be better to have a non-member function that allows template arguments for the cases we want to filter with greater specificity.
2024-03-13[RemoveDI][NFC] Rename DPValue->DbgRecord in comments and varnames (#84939)Stephen Tozer1-1/+1
This patch continues the ongoing rename work, replacing DPValue with DbgRecord in comments and the names of variables, both members and fn-local. This is the most labour-intensive part of the rename, as it is where the most decisions have to be made about whether a given comment or variable is referring to DPValues (equivalent to debug variable intrinsics) or DbgRecords (a catch-all for all debug intrinsics); these decisions are not individually difficult, but comprise a fairly large amount of text to review. This patch still largely performs basic string substitutions followed by clang-format; there are almost* no places where, for example, a comment has been expanded or modified to reflect the semantic difference between DPValues and DbgRecords. I don't believe such a change is generally necessary in LLVM, but it may be useful in the docs, and so I'll be submitting docs changes as a separate patch. *In a few places, `dbg.values` was replaced with `debug intrinsics`.
2024-03-12[RemoveDIs][NFC] Rename common interface functions for DPValues->DbgRecords ↵Stephen Tozer1-5/+5
(#84793) As part of the effort to rename the DbgRecord classes, this patch renames the widely-used functions that operate on DbgRecords but refer to DbgValues or DPValues in their names to refer to DbgRecords instead; all such functions are defined in one of `BasicBlock.h`, `Instruction.h`, and `DebugProgramInstruction.h`. This patch explicitly does not change the names of any comments or variables, except for where they use the exact name of one of the renamed functions. The reason for this is reviewability; this patch can be trivially examined to determine that the only changes are direct string substitutions and any results from clang-format responding to the changed line lengths. Future patches will cover renaming variables and comments, and then renaming the classes themselves.
2024-03-12[RemoveDIs] Update DIBuilder to conditionally insert DbgRecords (#84739)Orlando Cazalet-Hyams1-40/+49
Have DIBuilder conditionally insert either debug intrinsics or DbgRecord depending on the module's IsNewDbgInfoFormat flag. The insertion methods now return a `DbgInstPtr` (a `PointerUnion<Instruction *, DbgRecord *>`). Add a unittest for both modes (I couldn't find an existing test testing insertion behaviours specifically). This patch changes the existing assumption that DbgRecords are only ever inserted if there's an instruction to insert-before because clang currently inserts debug intrinsics while CodeGening (like any other instruction) meaning it'll try inserting to the end of a block without a terminator. We already have machinery in place to maintain the DbgRecords when a terminator is removed - these become "trailing DbgRecords" which are re-attached when a new instruction is inserted. All I've done is allow this state to occur while inserting DbgRecords too, i.e., it's not only removing terminators that causes this valid transient state, but inserting DbgRecords into incomplete blocks too. The C API will be updated in follow up patches. --- Note: this doesn't mean clang is emitting DbgRecords yet, because the modules it creates are still always in the old debug mode. That will come in a future patch.
2024-03-02Revert "[Dwarf] Support `__ptrauth` qualifier in metadata nodes" (#83672)Daniil Kovalev1-3/+3
Reverts llvm/llvm-project#82363 See a build failure related to an issue discovered by memory sanitizer (use of uninitialized value): https://lab.llvm.org/buildbot/#/builders/37/builds/31965
2024-03-01[Dwarf] Support `__ptrauth` qualifier in metadata nodes (#82363)Daniil Kovalev1-3/+3
Emit `__ptrauth`-qualified types as `DIDerivedType` metadata nodes in IR with tag `DW_TAG_LLVM_ptrauth_type`, baseType referring to the type which has the qualifier applied, and the following parameters representing the signing schema: - `ptrAuthKey` (integer) - `ptrAuthIsAddressDiscriminated` (boolean) - `ptrAuthExtraDiscriminator` (integer) - `ptrAuthIsaPointer` (boolean) - `ptrAuthAuthenticatesNullValues` (boolean) Co-authored-by: Ahmed Bougacha <ahmed@bougacha.org>
2024-02-29[DebugInfo][RemoveDIs] Prevent duplicate DPValues from being returned by ↵Stephen Tozer1-3/+4
findDbgIntrinsics (#82764) Fixes the error described here: https://github.com/llvm/llvm-project/commit/a93a4ec7dd205b965ee5597314bb376520cd736c#commitcomment-138965199 The function `findDbgIntrinsics` is used to return a list of debug intrinsics and DPValues that use a given value, with the intent that no duplicates are returned in either list. For DPValues, we've guarded against DPValues that use a value multiple times as part of a DIArgList, but we have not guarded against DPValues that use a value multiple times as separate operands (currently only possible for `dbg_assign`s, something I missed in my implementation of that type!). This patch adds a guard, and also updates a test to cover this case.
2024-02-26[RemoveDIs] Fix DPLabel crash reported in #82854Orlando Cazalet-Hyams1-7/+4
2024-02-20[RemoveDIs][NFC] Introduce DbgRecord base class [1/3] (#78252)Orlando Cazalet-Hyams1-4/+8
Patch 1 of 3 to add llvm.dbg.label support to the RemoveDIs project. The patch stack adds a new base class -> 1. Add DbgRecord base class for DPValue and the not-yet-added DPLabel class. 2. Add the DPLabel class. 3. Enable dbg.label conversion and add support to passes. Patches 1 and 2 are NFC. In the near future we also will rename DPValue to DbgVariableRecord and DPLabel to DbgLabelRecord, at which point we'll overhaul the function names too. The name DPLabel keeps things consistent for now.
2024-02-13[HWASAN] Update dbg.assign intrinsics in HWAsan pass (#79864)Orlando Cazalet-Hyams1-4/+0
llvm.dbg.assign intrinsics have 2 {value, expression} pairs; fix hwasan to update the second expression. Fixes #76545. This is #78606 rebased and with the addition of DPValue handling. Note the addition of --try-experimental-debuginfo-iterators in the tests and some shuffling of code in MemoryTaggingSupport.cpp.
2024-02-05Revert "[IR] Use range-based for loops (NFC)"Shubham Sandeep Rastogi1-2/+2
This reverts commit e8512786fedbfa6ddba70ceddc29d7122173ba5e. This revert is done because llvm::drop_begin over an empty ArrayRef doesn't return an empty range, and therefore can lead to an invalid address returned instead. See discussion in https://github.com/llvm/llvm-project/pull/80737 for more context.
2024-01-31[IR] Use range-based for loops (NFC)Kazu Hirata1-2/+2
2024-01-23[DebugInfo][RemoveDIs] "Final" cleanup for non-instr debug-info (#79121)Jeremy Morse1-0/+3
Here's a raft of minor fixes for the RemoveDIs project that's replacing dbg.value intrinsics with DPValue objects, all IMO trivial: * When inserting functions or blocks and calling setIsNewDbgInfoFormat, do that after setting the Parent pointer, just in case conversion from (or to) dbg.value mode is triggered. * When transferring DPValues from an empty range in a splice call, don't transfer if there are no DPValues attached to the source block at all. * stripNonLineTableDebugInfo should drop DPValues. * In insertBefore, don't try to transfer DPValues if there aren't any.
2024-01-23Revert "Reapply [hwasan] Update dbg.assign intrinsics in HWAsan pass … ↵gulfemsavrun1-0/+4
(#79186) …#78606" This reverts commit 13c6f1ea2e7eb15fe492d8fca4fa1857c6f86370 because it causes an assertion in DebugInfoMetadata.cpp:1968 in Clang Linux builders for Fuchsia. https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8758111613576762817/+/u/clang/build/stdout
2024-01-23[RemoveDIs][DebugInfo] Enable creation of DPVAssigns, update outstanding AT ↵Stephen Tozer1-51/+63
tests (#79148) This is the final patch for DPVAssign support, implementing the actual creation of DPVAssigns and allowing them to be converted along with dbg.values and dbg.declares. Numerous tests landed in previous patches will no longer be rotten after this patch lands (previously they would trivially pass due to DPVAssigns not actually being used), and a further batch of tests have been added here that require the changes in this patch before they pass.
2024-01-23Reapply [hwasan] Update dbg.assign intrinsics in HWAsan pass #78606OCHyams1-4/+0
llvm.dbg.assign intrinsics have 2 {value, expression} pairs; fix hwasan to update the second expression. Fixes #76545
2024-01-22Revert "Reapply [hwasan] Update dbg.assign intrinsics in HWAsan pass … ↵gulfemsavrun1-0/+4
(#79053) …#78606" This reverts commit 76160718df7c1f31ff50a4964d749c2b9d83f9cf because it caused an assertion failure in emitDbgValue function in Codegen in Clang Linux toolchain builders for Fuchsia. https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8758181086086431185/+/u/clang/build/stdout
2024-01-22Reapply [hwasan] Update dbg.assign intrinsics in HWAsan pass #78606OCHyams1-4/+0
llvm.dbg.assign intrinsics have 2 {value, expression} pairs; fix hwasan to update the second expression. Fixes #76545
2024-01-22Revert "[hwasan] Update dbg.assign intrinsics in HWAsan pass" (#78971)Orlando Cazalet-Hyams1-0/+4
Reverts llvm/llvm-project#78606 https://lab.llvm.org/buildbot/#/builders/77/builds/33963
2024-01-22[hwasan] Update dbg.assign intrinsics in HWAsan pass (#78606)Orlando Cazalet-Hyams1-4/+0
llvm.dbg.assign intrinsics have 2 {value, expression} pairs; fix hwasan to update the second expression. Fixes #76545
2024-01-22[RemoveDIs][DebugInfo] Add interface changes for AT analysis (#78460)Stephen Tozer1-21/+89
This patch adds the preliminary changes for handling DPValues in AssignmentTrackingAnalysis - very few functional changes are included, but internal data structures have been changed to operate with DPValues as well as Instructions, allowing future patches to process DPValues correctly.
2024-01-17Revert "Create overloads of debug intrinsic utilities for DPValues (#78313)"Stephen Tozer1-38/+1
This reverts commit 4f57e207, which added several unused functions, causing build errors on some buildbots.
2024-01-17[RemoveDIs][DebugInfo] Create overloads of debug intrinsic utilities for ↵Stephen Tozer1-1/+38
DPValues (#78313) In preparation for the major chunk of the assignment tracking implementation, this patch adds a new set of overloaded versions of existing functions that take DbgVariableIntrinsics, with the overloads taking DPValues. This is used specifically to allow us to use generic code to handle both DbgVariableIntrinsics and DPValues, reducing code duplication. This patch doesn't actually add the uses of these functions.
2024-01-17[RemoveDIs][DebugInfo] Make DIAssignID always replaceable (#78300)Stephen Tozer1-7/+2
This patch is a necessary step to allowing the new non-intrinsic debug info to replace llvm.dbg.assign intrinsics. DIAssignIDs must be able to look up the debug assigns that refer to them, and this patch makes them always be considered "replaceable", allowing us to track and replace uses for non-temporary instances.
2024-01-16Revert "[CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined ↵Davide Italiano1-10/+4
functions (#75385)" This reverts commit fc6faa1113e9069f41b5500db051210af0eea843.
2024-01-15[DebugInfo][RemoveDIs][NFC] Split findDbgDeclares into two functions (#77478)Stephen Tozer1-6/+36
This patch follows on from comments on https://github.com/llvm/llvm-project/pull/73498, implementing the proposed split of findDbgDeclares into two separate functions for DbgDeclareInsts and DPVDeclares, which return containers rather than taking containers by reference.
2024-01-11[CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined ↵Vladislav Dzhidzhoev1-4/+10
functions (#75385) - [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7) - [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions This is a follow-up for https://reviews.llvm.org/D144006, fixing a crash reported in Chromium (https://reviews.llvm.org/D144006#4651955). The first commit is added for convenience, as it has already been accepted. If DISubpogram was not cloned (e.g. we are cloning a function that has other functions inlined into it, and subprograms of the inlined functions are not supposed to be cloned), it doesn't make sense to clone its DILocalVariables as well. Otherwise get duplicated DILocalVariables not tracked in their subprogram's retainedNodes, that crash LTO with Chromium. This is meant to be committed along with https://reviews.llvm.org/D144006.
2024-01-02[hwasan] Workaround unsupported AssignmentTrackingPass (#76547)Vitaly Buka1-0/+4
Temporarily fix for issue #76545 Hwasan does not attach tags to @llvm.dbg.assign. It's not clear if we can attach tags to @llvm.dbg.assign. For now we just disable the path replacing llvm.dbg.declare with llvm.dbg.assign. It may reduce the quality of interactive debugging with HWASAN, but usually it's a smaller priority for sanitizers than the quality if reports.
2023-12-12Reapply "[RemoveDIs][NFC] Find DPValues using findDbgDeclares (#73500)"OCHyams1-26/+16
This patch doesn't change any call sites. Depends on #73498. Reverted in 87c686700f68ce24191f027082ef5fb9a654e9d8.
2023-12-12Revert "[RemoveDIs][NFC] Find DPValues using findDbgDeclares (#73500)"OCHyams1-16/+26
This reverts commit 17b8f87f76365e65350ec3f7f982b21b8d895598. Buildbot: https://lab.llvm.org/buildbot/#/builders/77/builds/32927
2023-12-12[RemoveDIs][NFC] Find DPValues using findDbgDeclares (#73500)Orlando Cazalet-Hyams1-26/+16
This patch doesn't change any call sites. Depends on #73498.
2023-12-12[NFC] Change FindDbgDeclareUsers interface to match findDbgUsers/values (#73498)Orlando Cazalet-Hyams1-8/+6
This simplifies an upcoming patch to support the RemoveDIs project (tracking variable locations without using intrinsics). Next in this series is #73500.
2023-12-11[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)Kazu Hirata1-1/+1
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-11-26[DebugInfo][RemoveDIs] Instrument inliner for non-instr debug-info (#72884)Jeremy Morse1-10/+10
With intrinsics representing debug-info, we just clone all the intrinsics when inlining a function and don't think about it any further. With non-instruction debug-info however we need to be a bit more careful and manually move the debug-info from one place to another. For the most part, this means keeping a "cursor" during block cloning of where we last copied debug-info from, and performing debug-info copying whenever we successfully clone another instruction. There are several utilities in LLVM for doing this, all of which now need to manually call cloneDebugInfo. The testing story for this is not well covered as we could rely on normal instruction-cloning mechanisms to do all the hard stuff. Thus, I've added a few tests to explicitly test dbg.value behaviours, ahead of them becoming not-instructions.
2023-11-22[llvm][TypeSize] Fix addition/subtraction in TypeSize. (#72979)Sander de Smalen1-1/+1
It seems TypeSize is currently broken in the sense that: TypeSize::Fixed(4) + TypeSize::Scalable(4) => TypeSize::Fixed(8) without failing its assert that explicitly tests for this case: assert(LHS.Scalable == RHS.Scalable && ...); The reason this fails is that `Scalable` is a static method of class TypeSize, and LHS and RHS are both objects of class TypeSize. So this is evaluating if the pointer to the function Scalable == the pointer to the function Scalable, which is always true because LHS and RHS have the same class. This patch fixes the issue by renaming `TypeSize::Scalable` -> `TypeSize::getScalable`, as well as `TypeSize::Fixed` to `TypeSize::getFixed`, so that it no longer clashes with the variable in FixedOrScalableQuantity. The new methods now also better match the coding standard, which specifies that: * Variable names should be nouns (as they represent state) * Function names should be verb phrases (as they represent actions)
2023-11-21[DebugInfo][RemoveDIs] Make dropping variable locations explicit (#72399)Jeremy Morse1-0/+1
In present-day debug-info, when you delete all instructions, you delete all their debug-info with it because debug-info is stored in instructions. With debug-info stored in DPValue objects however, deleting instructions causes DPValue objects to clump together into a large blob of debug-info that hangs around in the block, as nothing has explicitly deleted it. To restore this behaviour, scatter calls to dropDbgValues around in places that used to delete chunks of dbg.values, for example during stripDebugInfo and in the code that deletes everything after an Unreachable instruction. DCE is another example. The tests with --try... added to them are new scenarios where we can now correctly replicate the "normal" debug-info behaviour. Alas, there's no explicit test for the opt -strip-debug option though (in dbg.value mode or DPValue mode).
2023-11-18[DebugInfo][RemoveDIs] Support finding DPValues like dbg.values (#71952)Jeremy Morse1-7/+29
This patch extends findDbgValue and friends to optionally fill out a vector of DPValue pointers, containing DPValues that refer to the sought Value. This will allow us to incrementally add instrumentation to other optimisation passes one-at-a-time, while un-instrumented passes will not (yet) update DPValues. Unit tests to check this behaves in the same way as dbg.values.
2023-11-15Add RunTimeLang to Class and Enumeration DIBuilder functions (#72011)Augusto Noronha1-7/+6
RunTimeLang is already supported by DICompositeType, and already used by structs and unions. Add a new parameter in the class and enumeration create methods, so they can use the RunTimeLang attribute as well.
2023-11-15Reland "[llvm][DebugInfo] DWARFv5: static data members declarations are ↵Michael Buch1-6/+4
DW_TAG_variable (#72234)" This was reverted because it broke the OCaml LLVM bindings. Relanding the original patch but without changing the C-API. They'll continue to work just fine as they do today. If in the future there is a need to pass a new tag to the C-API for creating static members, then we'll make the change to the OCaml bindings at that time. Original commit message: """ This patch adds the LLVM-side infrastructure to implement DWARFv5 issue 161118.1: "DW_TAG for C++ static data members". The clang-side of this patch will simply construct the DIDerivedType with a different DW_TAG. """
2023-11-15Revert "[llvm][DebugInfo] DWARFv5: static data members declarations are ↵Michael Buch1-5/+7
DW_TAG_variable (#72234)" This reverts commit 9a9933fae23249fbf6cf5b3c090e630f578b7f98. The OCaml bindings were using `LLVMDIBuilderCreateStaticMemberType`, causing the API change in `9a9933fae23249fbf6cf5b3c090e630f578b7f98` to break buildbots that built the bindings. Revert until we figure out whether to fixup the bindings or just not change the C-API
2023-11-15[llvm][DebugInfo] DWARFv5: static data members declarations are ↵Michael Buch1-7/+5
DW_TAG_variable (#72234) This patch adds the LLVM-side infrastructure to implement DWARFv5 issue 161118.1: "DW_TAG for C++ static data members". The clang-side of this patch will simply construct the DIDerivedType with a different DW_TAG.
2023-11-08Revert "[DebugMetadata][DwarfDebug] Support function-local types in lexical ↵Vladislav Dzhidzhoev1-10/+1
block scopes (4/7)" This caused assert: llvm/llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp:110: void llvm::DwarfFile::addScopeVariable(LexicalScope *, DbgVariable *): Assertion `Ret.second' failed. See comments https://reviews.llvm.org/D144006#4656350. This reverts commit 3b449bd46a11a55a40cbc0016a99b202fa05248e.
2023-11-02[DebugMetadata][DwarfDebug] Support function-local types in lexical block ↵Vladislav Dzhidzhoev1-1/+10
scopes (4/7) RFC https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544 Similar to imported declarations, the patch tracks function-local types in DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with the aforementioned metadata change and provided a support of function-local types scoped within a lexical block. The patch assumes that DICompileUnit's 'enums field' no longer tracks local types and DwarfDebug would assert if any locally-scoped types get placed there. Reviewed By: jmmartinez Authored-by: Kristina Bessonova <kbessonova@accesssoftek.com> Differential Revision: https://reviews.llvm.org/D144006
2023-10-27Replace TypeSize::{getFixed,getScalable} with canonical ↵Fangrui Song1-1/+1
TypeSize::{Fixed,Scalable}. NFC
2023-09-29Revert "[DebugMetadata][DwarfDebug] Support function-local types in lexical ↵Hans Wennborg1-10/+1
block scopes (4/7)" This caused asserts: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:2331: virtual void llvm::DwarfDebug::endFunctionImpl(const llvm::MachineFunction *): Assertion `LScopes.getAbstractScopesList().size() == NumAbstractSubprograms && "getOrCreateAbstractScope() inserted an abstract subprogram scope"' failed. See comment on the code review for reproducer. > RFC https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544 > > Similar to imported declarations, the patch tracks function-local types in > DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with > the aforementioned metadata change and provided a support of function-local > types scoped within a lexical block. > > The patch assumes that DICompileUnit's 'enums field' no longer tracks local > types and DwarfDebug would assert if any locally-scoped types get placed there. > > Reviewed By: jmmartinez > > Differential Revision: https://reviews.llvm.org/D144006 This reverts commit f8aab289b5549086062588fba627b0e4d3a5ab15.
2023-09-26[DebugMetadata][DwarfDebug] Support function-local types in lexical block ↵Vladislav Dzhidzhoev1-1/+10
scopes (4/7) RFC https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544 Similar to imported declarations, the patch tracks function-local types in DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with the aforementioned metadata change and provided a support of function-local types scoped within a lexical block. The patch assumes that DICompileUnit's 'enums field' no longer tracks local types and DwarfDebug would assert if any locally-scoped types get placed there. Reviewed By: jmmartinez Differential Revision: https://reviews.llvm.org/D144006
2023-07-07[LLVM-C] Use unwrapDI in LLVMDITypeGetNameTamir Duberstein1-1/+1
This function otherwise crashes. This behavior has been incorrect since its introduction in 260b581498bed0b847e7e086852e0082d266711d (D46627). Reviewed By: scott.linder Differential Revision: https://reviews.llvm.org/D154630
2023-05-31[Assignment Tracking] Ignore stores to a negative offset from an allocaOCHyams1-1/+6
Fixes crash reported in llvm.org/PR62838. Reviewed By: jryans Differential Revision: https://reviews.llvm.org/D151326
2023-05-15[IR] Drop const in DILocation::getMergedLocationChristian Ulmann1-2/+1
This commit removes constness from DILocation::getMergedLocation and fixes all its users accordingly. Having constness on the parameters forced the return type to be const as well, which does force usage of `const_cast` when the location needs to be used in metadata nodes. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D149942
2023-05-05[Assignment Tracking] Skip scalable vectors in declare-to-assign passOCHyams1-1/+4
Do not convert dbg.declares to dbg.assigns for variables backed by scalable vector allocas as this isn't yet supported. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D149959