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E83y54Pm0HI14VvBUTNKMszmN43g2mfTKURS9J9pTMpKLvr0_-MEkRqMoWSzAriVK2EXfHcd0mgtF9Wfl-4PIa3ACqL0p5KCedfQQDuMLyDt_LaFMPnxEHdj07okCE5JFaGNp74QRB4b2J9F0HKTLr-UVCh_4oM3x-lRSvlP4VdiNr238fB4PNOYb316c-p-0lwpF9cxRr3hxplWGm2IhOhdCx1bIXxYvTLVvVkQnu2FDmB19JfTLNRJ7Ly8Y_jP1byLyP-Qdat-t8uXBS5AAfzTDxfY2NCy8be8k53xafHY-z7RfY_v3Kwbz7Vmwr6MzWb_fv0n-j8tp_w4SbXv0Nc4xKKZRDoU6kkZZM1TKZ8Yt9lAL9RnYjGmz8SwWhZFC4XEjlGtoWKzSYpkuxRCw1tqsuPE3XTXsTLOqnWutZ3dyhYbaUnfZCLfl2Tl7-06S1qJoojNN00kyrFdpucyQtTQTSbmMC8HJJBVptpiJvBwvcx42IuPGrgZTnOBE8RMFE_6pMN0O3x-BXCVxksTjZDxeTNMkHZWzosyWKEhjFmKGXE9ixrOwGXk7I22qoVkFkyjlFpNIBp4Cr5PChrcUh4ARoZO4vlY_fvr9f68oXAinV9Qw7HcVNvsnZV9-_w>53342</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
DwarfExpression.cpp: Assertion `SizeInBits >= OffsetInBits - FragmentOffset && "size underflow"` failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ellishg
</td>
</tr>
</table>
<pre>
I'm hitting a crash when compiling with debug info on the main branch.
```
clang: llvm-project/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp:508: bool llvm::DwarfExpression::addExpression(llvm::DIExpressionCursor &&, llvm::function_ref<bool (unsigned int, DIExpressionCursor &)>): Assertion `SizeInBits >= OffsetInBits - FragmentOffset && "size underflow"' failed.
```
Unfortunately, I hit a wall when trying to simplify the reproducer. It seems to depend on a very large set of complicated statements. I can't publish the code here because it is proprietary, but here is the clang invocation I'm using.
```
clang -g -Oz --sysroot=/opt/android_ndk/r17fb2/sysroot -target aarch64-none-linux-android21 -D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS -fprofile-generate -c bug.cpp
```
I studied the code a little and found a patch that prevents the bug in this case, but I don't understand it enough to have confidence that it is the right solution. My wild guess was that this was a single-line-if-statement bug and that `Register::SubRegSize` is invalid if `Register::DwarfRegNo` is zero.
```diff
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
index 37407c98e75f..e6de5a43beb7 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -288,9 +288,10 @@ bool DwarfExpression::addMachineRegExpression(const TargetRegisterInfo &TRI,
if ((!isParameterValue() && !isMemoryLocation() && !HasComplexExpression) ||
isEntryValue()) {
for (auto &Reg : DwarfRegs) {
- if (Reg.DwarfRegNo >= 0)
+ if (Reg.DwarfRegNo >= 0) {
addReg(Reg.DwarfRegNo, Reg.Comment);
- addOpPiece(Reg.SubRegSize);
+ addOpPiece(Reg.SubRegSize);
+ }
}
if (isEntryValue()) {
```
I'm happy to test out any other fixes. Thanks! CC @adrian-prantl
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1Vttu2zgQ_Rr7ZSDDlu8PfnDsZGsgTYImLbBPBiWOJG5lUiCpJO7X7yHlpE4veyvWICxehjPDOTOHzIw8rna9dH6gSnmvdEmCcitcRU8Va8rNoVF1mH5SviLJWVuS0oUho8lXTAehNGVW6Lwa9Ibb3nDdmw1PLQ7zWuiyN15TXT8eksaaPzj3vfQqDMNHZfjfGMm_sUZv7Q53VmnPFoPtk7DF5XNj2Tll9CBvGmiaDhdBX2ZMHZVigPaNbDcppDybShdn4ruvC5vWOmOpl85i25x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