RE: [auto-profile] Fix segfault in scale_bb_profile
Prathamesh Kulkarni <[email protected]>
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <DM4PR12MB519973222E3929FFA3B67529CEDE2@DM4PR12MB5199.namprd12.prod.outlook.com> |
> -----Original Message----- > From: Prathamesh Kulkarni <[email protected]> > Sent: 19 July 2026 19:42 > To: Jan Hubicka <[email protected]>; [email protected] > Subject: [auto-profile] Fix segfault in scale_bb_profile > > External email: Use caution opening links or attachments > > > Hi, > For the following test case: > > #include <regex> > #include <string> > #include <iostream> > int main() > { > std::string s="hello"; > std::regex re("h.*"); > std::cout << std::regex_match(s,re) << std::endl; > return 0; > } > > Compiling with -O2 -fauto-profile=<gcov> --param auto-profile-bbs=0 > results in: > > tr.cxx:4:118: internal compiler error: Segmentation fault > 4 | int main(){ std::string s="hello"; std::regex re("h.*"); > std::cout << std::regex_match(s,re) << std::endl; return 0; } > | > ^ > 0x29e0877 internal_error(char const*, ...) > ../../gcc/gcc/diagnostic-global-context.cc:787 > 0x1488763 crash_signal > ../../gcc/gcc/toplev.cc:325 > 0x2653ce4 autofdo::scale_bb_profile() > ../../gcc/gcc/auto-profile.cc:4061 > 0x265b517 afdo_annotate_cfg > ../../gcc/gcc/auto-profile.cc:4509 > 0x265b517 auto_profile > ../../gcc/gcc/auto-profile.cc:4677 > 0x265b517 execute > ../../gcc/gcc/auto-profile.cc:4850 > > That happens in scale_bb_profile at following place: > const function_instance *s > = afdo_source_profile->get_function_instance_by_decl > (current_function_decl); > > The issue is that get_function_instance_by_decl will return NULL if > DECL_SOURCE_FILE for current_function_decl, doesn't match with the > filename stored in afdo_string_table > > For above case, > current_function_decl is > _ZNSt15_Deque_iteratorINSt8__detail9_StateSeqINSt7__cxx1112regex_trait > sIcEEEERS5_PS5_EmmEv, > DECL_SOURCE_FILE is stl_deque.h > and s->file_name() corresponds to stl_tree.h > > and get_function_instance_by_decl thus returns NULL. > > In afdo_annotate_cfg, the workaround for that is to iterate over all > filenames to avoid dropping profile for that function if it has > mismatched filename: > > /* FIXME: This is a workaround for sourcefile tracking, if > afdo_string_table > ends up with empty filename or incorrect filename for the > function and > should be removed once issues with sourcefile tracking get fixed. > */ > if (s == NULL) > for (unsigned i = 0; i < afdo_string_table->filenames ().length > (); i++) > { > s = afdo_source_profile->get_function_instance_by_decl > (current_function_decl, afdo_string_table->filenames()[i]); > if (s) > break; > } > > > The attached patch passes the function_instance found in > afdo_annotate_cfg to scale_bb_profile, instead of recomputing it, > which fixes the segfault. > > Bootstrap+test in progress. > Is this patch OK to commit if testing passes ? Hi, ping: https://gcc.gnu.org/pipermail/gcc-patches/2026-July/724497.html Thanks, Prathamesh > > Thanks, > Prathamesh > > >