Skip to content

Commit 0e40a22

Browse files
assert()ing seems easier than trying to make the compiler to not optimize
1 parent 0fcb4e4 commit 0e40a22

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

ext/zend_test/test.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
+----------------------------------------------------------------------+
1515
*/
1616

17+
#include <stdint.h>
1718
#ifdef HAVE_CONFIG_H
1819
# include "config.h"
1920
#endif
@@ -367,7 +368,6 @@ static ZEND_FUNCTION(zend_test_crash)
367368

368369
zend_mm_heap* zend_test_heap;
369370
zend_mm_heap* zend_orig_heap;
370-
volatile uint32_t lineno = 0;
371371

372372
static bool has_opline(zend_execute_data *execute_data)
373373
{
@@ -378,32 +378,29 @@ static bool has_opline(zend_execute_data *execute_data)
378378
;
379379
}
380380

381-
#pragma GCC push_options
382-
#pragma GCC optimize("O0")
383-
void * __attribute__((optnone)) zend_test_custom_malloc(size_t len)
381+
void * zend_test_custom_malloc(size_t len)
384382
{
385383
if (has_opline(EG(current_execute_data))) {
386-
lineno = EG(current_execute_data)->opline->lineno;
384+
assert(EG(current_execute_data)->opline->lineno != (uint32_t)-1);
387385
}
388386
return _zend_mm_alloc(zend_orig_heap, len);
389387
}
390388

391-
void __attribute__((optnone)) zend_test_custom_free(void *ptr)
389+
void zend_test_custom_free(void *ptr)
392390
{
393391
if (has_opline(EG(current_execute_data))) {
394-
lineno = EG(current_execute_data)->opline->lineno;
392+
assert(EG(current_execute_data)->opline->lineno != (uint32_t)-1);
395393
}
396394
_zend_mm_free(zend_orig_heap, ptr);
397395
}
398396

399-
void * __attribute__((optnone)) zend_test_custom_realloc(void * ptr, size_t len)
397+
void * zend_test_custom_realloc(void * ptr, size_t len)
400398
{
401399
if (has_opline(EG(current_execute_data))) {
402-
lineno = EG(current_execute_data)->opline->lineno;
400+
assert(EG(current_execute_data)->opline->lineno != (uint32_t)-1);
403401
}
404402
return _zend_mm_realloc(zend_orig_heap, ptr, len);
405403
}
406-
#pragma GCC pop_options
407404

408405
static ZEND_FUNCTION(zend_test_observe_opline_in_zendmm)
409406
{

0 commit comments

Comments
 (0)