@@ -199,10 +199,12 @@ impl<'tcx> DecodedFormatArgs<'tcx> {
199199 if let [
200200 SpirvValue {
201201 kind : SpirvValueKind :: Def ( a_id) ,
202+ ty : a_ty,
202203 ..
203204 } ,
204205 SpirvValue {
205206 kind : SpirvValueKind :: Def ( b_id) ,
207+ ty : b_ty,
206208 ..
207209 } ,
208210 ref other_args @ ..,
@@ -215,6 +217,17 @@ impl<'tcx> DecodedFormatArgs<'tcx> {
215217 decoded_format_args. const_pieces = Some ( [ const_msg] . into_iter ( ) . collect ( ) ) ;
216218 return Ok ( decoded_format_args) ;
217219 }
220+
221+ // Dynamic `&str` panic messages (e.g. `panic_display(&msg)` where
222+ // `msg` isn't a directly recoverable constant).
223+ if other_args. len ( ) <= 2
224+ && matches ! ( cx. lookup_type( a_ty) , SpirvType :: Pointer { .. } )
225+ && matches ! ( cx. lookup_type( b_ty) , SpirvType :: Integer ( ..) )
226+ {
227+ decoded_format_args. const_pieces =
228+ Some ( [ "<dynamic panic message>" . into ( ) ] . into_iter ( ) . collect ( ) ) ;
229+ return Ok ( decoded_format_args) ;
230+ }
218231 }
219232
220233 // Newer `core::fmt::Arguments` can be scalarized at the panic call-site
@@ -475,9 +488,10 @@ impl<'tcx> DecodedFormatArgs<'tcx> {
475488 try_rev_take ( 1 ) . unwrap ( ) ;
476489 lookup_fmt_args_ctor ( callee_id) ?
477490 } else {
478- return Err ( FormatArgsNotRecognized (
479- "fmt::Arguments::new call: split fmt::Arguments args without recoverable ctor metadata" . into ( ) ,
480- ) ) ;
491+ // We failed to recover constructor metadata for an already-split
492+ // `fmt::Arguments` value. Keep panic lowering sound by falling
493+ // back to an unknown panic message, without requiring decompilation.
494+ return Ok ( decoded_format_args) ;
481495 } ;
482496
483497 (
@@ -533,6 +547,9 @@ impl<'tcx> DecodedFormatArgs<'tcx> {
533547 if insts. is_empty ( ) {
534548 return Ok ( decoded_format_args) ;
535549 }
550+ if !insts. iter ( ) . any ( |inst| matches ! ( inst, Inst :: Call ( _, _, _) ) ) {
551+ return Ok ( decoded_format_args) ;
552+ }
536553 return Err ( FormatArgsNotRecognized ( format ! (
537554 "fmt::Arguments::new call sequence ({insts:?})" ,
538555 ) ) ) ;
@@ -551,6 +568,9 @@ impl<'tcx> DecodedFormatArgs<'tcx> {
551568 if insts. is_empty ( ) {
552569 return Ok ( decoded_format_args) ;
553570 }
571+ if !insts. iter ( ) . any ( |inst| matches ! ( inst, Inst :: Call ( _, _, _) ) ) {
572+ return Ok ( decoded_format_args) ;
573+ }
554574 return Err ( FormatArgsNotRecognized ( format ! (
555575 "fmt::Arguments::new call sequence ({insts:?})" ,
556576 ) ) ) ;
0 commit comments