File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3919,6 +3919,38 @@ def testfunc(args):
39193919 expected = TIER2_THRESHOLD * (5.0 / Fraction (4 ))
39203920 self .assertAlmostEqual (res , float (expected ))
39213921
3922+ def test_float_truediv_partial_float_no_stack_underflow (self ):
3923+ # gh-149049: a speculative _GUARD_*_FLOAT for a partially-float
3924+ # truediv/remainder must not drop the original _BINARY_OP.
3925+ def truediv (args ):
3926+ n , = args
3927+ nan = float ("nan" )
3928+ def victim (a = 0 , b = nan , c = 2 ):
3929+ return (a + b ) / c
3930+ for _ in range (n ):
3931+ victim ()
3932+
3933+ def remainder (args ):
3934+ n , = args
3935+ nan = float ("nan" )
3936+ def victim (a = 0 , b = nan , c = 2 ):
3937+ return (a + b ) % c
3938+ for _ in range (n ):
3939+ victim ()
3940+
3941+ for testfunc in (truediv , remainder ):
3942+ with self .subTest (op = testfunc .__name__ ):
3943+ # Iterations must be high enough that the buggy trace
3944+ # is not only built but executed (where it underflows).
3945+ _ , ex = self ._run_with_optimizer (
3946+ testfunc , (TIER2_THRESHOLD * 10 ,))
3947+ self .assertIsNotNone (ex )
3948+ uops = get_opnames (ex )
3949+ self .assertTrue (
3950+ "_GUARD_TOS_FLOAT" in uops or "_GUARD_NOS_FLOAT" in uops ,
3951+ uops ,
3952+ )
3953+
39223954 def test_int_add_inplace_unique_lhs (self ):
39233955 # a * b produces a unique compact int; adding c reuses it in place
39243956 def testfunc (args ):
You can’t perform that action at this time.
0 commit comments