Skip to content

zend_cfg: use uint32_t type rather than int type#21542

Draft
Girgias wants to merge 5 commits intophp:masterfrom
Girgias:blocks_count_uint32t
Draft

zend_cfg: use uint32_t type rather than int type#21542
Girgias wants to merge 5 commits intophp:masterfrom
Girgias:blocks_count_uint32t

Conversation

@Girgias
Copy link
Member

@Girgias Girgias commented Mar 26, 2026

These are count values and thus should never be negative, more over their use site usually wants them to be uint32_t too. Aligning these types makes the intention clearer.

I have also trying to propagate those changes to use sites of these struct members.

Comment on lines +940 to 946
int backtracking_block_num = block_num;
do {
block_num--;
} while (block_num >= 0
backtracking_block_num--;
} while (backtracking_block_num >= 0
&& !(ssa->cfg.blocks[block_num].flags & ZEND_BB_REACHABLE));
if (block_num >= 0) {
if (backtracking_block_num >= 0) {
continue;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that there should be a better way to solve this but when I initially did:

Suggested change
int backtracking_block_num = block_num;
do {
block_num--;
} while (block_num >= 0
backtracking_block_num--;
} while (backtracking_block_num >= 0
&& !(ssa->cfg.blocks[block_num].flags & ZEND_BB_REACHABLE));
if (block_num >= 0) {
if (backtracking_block_num >= 0) {
continue;
do {
block_num--;
} while (block_num > 0
&& !(ssa->cfg.blocks[block_num].flags & ZEND_BB_REACHABLE));
if (!(ssa->cfg.blocks[block_num].flags & ZEND_BB_REACHABLE)) {
continue;

it didn't behave as expected, so I guess I'm not fully grasping what is happening here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you had inverted the logic in if (!(ssa->cfg.blocks[block_num].flags & ZEND_BB_REACHABLE)) {. Before, if (block_num >= 0) implied that ssa->cfg.blocks[block_num] was reachable. So it should be if ((ssa->cfg.blocks[block_num].flags & ZEND_BB_REACHABLE)) {.

But I find the original logic easier to follow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to keep the original logic, although I might add a comment explaining what is happening :)

Copy link
Member

@arnaud-lb arnaud-lb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a partial review up to dfa_pass.c

Girgias added 5 commits March 27, 2026 11:06
These are count values and thus should never be negative, more over their use site usually wants them to be uint32_t too.
Aligning these types makes the intention clearer.

I have also trying to propagate those changes to use sites of these struct members.
@Girgias Girgias force-pushed the blocks_count_uint32t branch from 9966838 to 31201ca Compare March 27, 2026 11:19
@Girgias
Copy link
Member Author

Girgias commented Mar 27, 2026

Needed to force-push after a rebase due to conflicts arising after the merge of #21540, but follow-up commits address the review comments. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants