<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/97635>97635</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MC] SIGSEGV due to uninitialized AsmParser.Out.CurrFrag
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
sivan-shani
</td>
</tr>
</table>
<pre>
Due to several recent changes, the function `AsmParser::checkForValidSection() `is now utilizing (among other functions) also `CurFrag->getParent()` instead of `getCurrentSection().first`
This seems to cause a SIGSEV in some cases when `AsmParser::Run()` is called via API.
`AsmParser.Out.CurFrag` is not set, `AsmParser::Run()` -> call -> `AsmParser::parseStatement` -> `checkForValidSection` and this terminates in SIGSEV.
gdb output:
```
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
MC Feature String: +v8a,+crc,+fp-armv8,+neon,+crypto
Running slice:
arch: core_v8A_64+vfpneon_v8A_fp_neon+extension_cryptography
mode: feature_AArch64
slice range: 0x15000000 - 0x15ffffff (provided (val & 0xff000000) == 0x15000000)
operation: assemble
Program received signal SIGSEGV, Segmentation fault.
0x0000555555b587ee in llvm::MCFragment::getParent (this=0x0) at /llvm-project/llvm/include/llvm/MC/MCFragment.h:93
93 MCSection *getParent() const { return Parent; } // (this=0x0)
(gdb) bt
#0 0x0000555555b587ee in llvm::MCFragment::getParent (this=0x0) at /llvm-project/llvm/include/llvm/MC/MCFragment.h:93
#1 0x000055555615d545 in llvm::MCStreamer::getCurrentFragment (this=0x555557af6a60) at /llvm-project/llvm/include/llvm/MC/MCStreamer.h:412
#2 0x0000555556137125 in (anonymous namespace)::AsmParser::checkForValidSection (this=0x555557af74b0) at /llvm-project/llvm/lib/MC/MCParser/AsmParser.cpp:1085
#3 0x000055555613c857 in (anonymous namespace)::AsmParser::parseStatement (this=0x555557af74b0, Info=..., SI=0x0) at /llvm-project/llvm/lib/MC/MCParser/AsmParser.cpp:2308
#4 0x0000555556136817 in (anonymous namespace)::AsmParser::Run (this=0x555557af74b0, NoInitialTextSection=false, NoFinalize=false)
at /llvm-project/llvm/lib/MC/MCParser/AsmParser.cpp:999
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVsuO27gS_Rp6U7AgUQ9bCy_8iINe9L2NOJOtQUkliTMUKfDhuPP1A1K2291pJJlgFiMYskgWT51TLBbJjOGdRFyRfEPy3Yw52yu9MvzE5Nz0TPJZpZrn1c4hWAUGT6iZAI01Sgt1z2SHhtAt2B6hdbK2XEkgRbw2wxPTBjVJ1yRd1z3Wf-2V_sIEbw4YzAhdElp6Y25Aqq_gLBf8G5cdELpkg5IdKNujvgEbb8-EUX7S1um9Zt2cpB86tE9Mo7QTJCli4NJYZA2o1tt2aLdOe4tXvqOWa2NJEZN4R-L19P7ccwMGcTBecc2cQWBwePh4-PAFuASjBoSaGTTwtcf3xH5y8o6IgZoJgQ2cOIP100ME997uZ0f_dza6yLpMlcqCQesj_BM_Pg7B0_T1vfXovw-WWRx8pK5TSBG_uzhFDEw2YH00LOqBS2bR-ABMoYjuVXRNBcrZ0Vnv6yrs8pua-eZzr_2KNFi5rvOr7Ix_C17ZMHJsKkDJKoENyXfTtD-CSa-MfW0neKWZfgZCKaF7wStC9-dlcSyyueDSneeddNPAbU5kVJQQSi_EH7ewR2adRjhYzWVH0jUQujktGaFbQje1rqePdpwzPZyWU0uiz57J4Hm0akL75KT0TI3gNd5iwHTde9haaTyelutjkXkP7ehBQkc7HifADZ4tSsOVPE64nWZj_zzhDKrxoNBOhI_rta77IpsGg0vQfid6m_ic5HF4YB4abXj8lhq1OvEGG_99YgIILSA-t-1kHvZiuiPp7g7DJ1fwokbULCRGugZmDA6VwPsUeNKe8hBKAz9hA76wMDFly8cvPoMP2PnUCzDQMifsZS3is_eVh6fKlwtEn2dCnIYpdR-3fkuEtA3t2373SnyGknQXn4MC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