php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80046 FREE for SWITCH_STRING optimized away
Submitted: 2020-09-03 08:13 UTC Modified: 2020-09-03 09:16 UTC
From: sjon@php.net Assigned:
Status: Closed Package: opcache
PHP Version: 8.0.0beta2 OS:
Private report: No CVE-ID: None
 [2020-09-03 08:13 UTC] sjon@php.net
Description:
------------
I'm seeing an assertion that doesn't really seem to be related to my code. I don't mind debugging this but the exception seems (..) somewhat self-explanatory.

this in beta3

Test script:
---------------
Zend/zend_opcode.c:773: keeps_op1_alive: Assertion `opline->opcode != 188 && opline->opcode != 78 && opline->opcode != 126 && opline->opcode != 155 && opline->opcode != 124 && opline->opcode != 182 && opline->opcode != 55' failed.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-03 08:17 UTC] nikic@php.net
Can you check what the actual value of opline->opcode is?
 [2020-09-03 08:19 UTC] sjon@php.net
(gdb) print opline->opcode 
$1 = 188 '\274'
 [2020-09-03 08:29 UTC] sjon@php.net
repro:

class a
{
	protected function x(): bool
	{
		try
		{
			$credentials = something();
		}
		catch (Exception $e)
		{
			switch (get_class($e))
			{
				case Ex1::class:
				case Ex2::class:
					throw new Exception('');
				default:
					throw $e;
			}
		}

		return true;
	}
}
 [2020-09-03 08:40 UTC] nikic@php.net
Slightly tweaked test case:

<?php
function test($foo) {
    switch ($foo . 'Bar') {
        case 'A':
            throw new Exception('A');
        default:
            throw new Exception('Default');
    }
}
try { 
    test('Foo');
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}

Asserts on master and 7.4. I had hoped it would show a leak on 7.3, but everything is alright there.

The problem is that the FREE for the SWITCH_STRING is optimized away, which shouldn't happen, as it is a loop free.
 [2020-09-03 09:16 UTC] nikic@php.net
-Summary: b3: Zend/zend_opcode.c:773: keeps_op1_alive: Assertion `opline->opcode != 188 +Summary: FREE for SWITCH_STRING optimized away
 [2020-09-03 09:18 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=04e77d2dea03955b987bc6e253ea236c2c7a12aa
Log: Fixed bug #80046
 [2020-09-03 09:18 UTC] nikic@php.net
-Status: Open +Status: Closed
 [2020-09-03 09:19 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8516434a56d279b4f5fbe9497b0dd6365350383c
Log: Fixed bug #80046
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Oct 21 08:01:23 2020 UTC