@@ -253,15 +253,18 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
253253 // We are processing .debug_info section, implicit_const attribute
254254 // values are not really stored here, but in .debug_abbrev section.
255255 auto GetAsUnsignedConstant = [&]() -> int64_t {
256- return AttrSpec.isImplicitConst () ? AttrSpec.getImplicitConstValue ()
257- : *FormValue.getAsUnsignedConstant ();
256+ if (AttrSpec.isImplicitConst ())
257+ return AttrSpec.getImplicitConstValue ();
258+ if (std::optional<uint64_t > Val = FormValue.getAsUnsignedConstant ())
259+ return *Val;
260+ return 0 ;
258261 };
259262
260263 auto GetFlag = [](const DWARFFormValue &FormValue) -> bool {
261264 return FormValue.isFormClass (DWARFFormValue::FC_Flag);
262265 };
263266
264- auto GetBoundValue = [](const DWARFFormValue &FormValue) -> int64_t {
267+ auto GetBoundValue = [&AttrSpec ](const DWARFFormValue &FormValue) -> int64_t {
265268 switch (FormValue.getForm ()) {
266269 case dwarf::DW_FORM_ref_addr:
267270 case dwarf::DW_FORM_ref1:
@@ -282,6 +285,8 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
282285 return *FormValue.getAsUnsignedConstant ();
283286 case dwarf::DW_FORM_sdata:
284287 return *FormValue.getAsSignedConstant ();
288+ case dwarf::DW_FORM_implicit_const:
289+ return AttrSpec.getImplicitConstValue ();
285290 default :
286291 return 0 ;
287292 }
@@ -294,13 +299,13 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
294299
295300 switch (AttrSpec.Attr ) {
296301 case dwarf::DW_AT_accessibility:
297- CurrentElement->setAccessibilityCode (*FormValue. getAsUnsignedConstant ());
302+ CurrentElement->setAccessibilityCode (GetAsUnsignedConstant ());
298303 break ;
299304 case dwarf::DW_AT_artificial:
300305 CurrentElement->setIsArtificial ();
301306 break ;
302307 case dwarf::DW_AT_bit_size:
303- CurrentElement->setBitSize (*FormValue. getAsUnsignedConstant ());
308+ CurrentElement->setBitSize (GetAsUnsignedConstant ());
304309 break ;
305310 case dwarf::DW_AT_call_file:
306311 CurrentElement->setCallFilenameIndex (IncrementFileIndex
@@ -332,13 +337,12 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
332337 Stream << hexString (Value, 2 );
333338 CurrentElement->setValue (Stream.str ());
334339 } else
335- CurrentElement->setValue (
336- hexString (*FormValue.getAsUnsignedConstant (), 2 ));
340+ CurrentElement->setValue (hexString (GetAsUnsignedConstant (), 2 ));
337341 } else
338342 CurrentElement->setValue (dwarf::toStringRef (FormValue));
339343 break ;
340344 case dwarf::DW_AT_count:
341- CurrentElement->setCount (*FormValue. getAsUnsignedConstant ());
345+ CurrentElement->setCount (GetAsUnsignedConstant ());
342346 break ;
343347 case dwarf::DW_AT_decl_line:
344348 CurrentElement->setLineNumber (GetAsUnsignedConstant ());
@@ -357,10 +361,10 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
357361 CurrentElement->setIsExternal ();
358362 break ;
359363 case dwarf::DW_AT_GNU_discriminator:
360- CurrentElement->setDiscriminator (*FormValue. getAsUnsignedConstant ());
364+ CurrentElement->setDiscriminator (GetAsUnsignedConstant ());
361365 break ;
362366 case dwarf::DW_AT_inline:
363- CurrentElement->setInlineCode (*FormValue. getAsUnsignedConstant ());
367+ CurrentElement->setInlineCode (GetAsUnsignedConstant ());
364368 break ;
365369 case dwarf::DW_AT_lower_bound:
366370 CurrentElement->setLowerBound (GetBoundValue (FormValue));
@@ -380,7 +384,7 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
380384 CurrentElement->setUpperBound (GetBoundValue (FormValue));
381385 break ;
382386 case dwarf::DW_AT_virtuality:
383- CurrentElement->setVirtualityCode (*FormValue. getAsUnsignedConstant ());
387+ CurrentElement->setVirtualityCode (GetAsUnsignedConstant ());
384388 break ;
385389
386390 case dwarf::DW_AT_abstract_origin:
0 commit comments