[llvm] [NFC] Add fragment-getting functions to DbgRecord (PR #97705)
Stephen Tozer via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 5 10:50:07 PDT 2024
================
@@ -460,6 +461,19 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser {
resetDebugValue(0, NewLocation);
}
+ std::optional<DbgVariableFragmentInfo> getFragment() const;
+ /// Get the FragmentInfo for the variable if it exists, otherwise return a
+ /// FragmentInfo that covers the entire variable if the variable size is
+ /// known, otherwise return a zero-sized fragment.
+ DbgVariableFragmentInfo getFragmentOrEntireVariable() const {
+ DbgVariableFragmentInfo VariableSlice(0, 0);
+ // Get the fragment or variable size, or zero.
+ if (auto Sz = getFragmentSizeInBits())
+ VariableSlice.SizeInBits = *Sz;
+ if (auto Frag = getFragment())
+ VariableSlice.OffsetInBits = Frag->OffsetInBits;
+ return VariableSlice;
+ }
----------------
SLTozer wrote:
```suggestion
DbgVariableFragmentInfo getFragmentOrEntireVariable() const {
if (auto Frag = getFragment())
return *Frag;
if (auto Sz = getVariable()->getSizeInBits())
return {*Sz, 0};
return {0, 0};
}
```
YMMV, but personally I feel this style is better for using just simple returns; could also replace the last lines with just `return {getVariable()->getSizeInBits().value_or(0), };`, but personally I find the above easier to read.
https://github.com/llvm/llvm-project/pull/97705
More information about the llvm-commits
mailing list