Skip to content

ConstraintAnalysis: Fix a hang with a tee in an increment - #9058

Merged
kripken merged 6 commits into
WebAssembly:mainfrom
kripken:c.nohang
Aug 31, 2026
Merged

ConstraintAnalysis: Fix a hang with a tee in an increment#9058
kripken merged 6 commits into
WebAssembly:mainfrom
kripken:c.nohang

Conversation

@kripken

@kripken kripken commented Aug 31, 2026

Copy link
Copy Markdown
Member

No description provided.

@kripken
kripken requested a review from a team as a code owner August 31, 2026 18:14
@kripken
kripken requested review from stevenfontanella and tlively and removed request for a team August 31, 2026 18:14
Comment on lines -572 to -577
if (auto* binary = set->value->dynCast<Binary>()) {
if (binaryActionCounts[binary]++ >= MaxBinaryActions) {
constraints.setProvesNothing(set->index);
return;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why wasn't this catch-all widening sufficient to prevent the problem? Because the expression we have here isn't a Binary? Could we fix it by just handling any kind of expression here instead of just Binary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The issue was that we didn't handle this wrt a fallthrough. That is, we computed the fallthrough after, perhaps producing a Binary then - after this check.

That was silly and also inefficient...

// work.
break;
}
auto* next = Properties::getImmediateFallthrough(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't there an optional parameter to getFallthrough that will give us this NoTee behavior without us having to reimplement the loop?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There is, but it also skips BrIfs:

enum class FallthroughBehavior { AllowTeeBrIf, NoTeeBrIf };

We could perhaps make that flag more refined, but I'm not sure it's worth it.


// Now that we know the value, check binary action counting limits (see
// above).
if (auto* binary = value->dynCast<Binary>()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there any reason to continue restricting this to Binary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd like to keep this "precise" to the things it needs to handle. There is nothing else where we have this issue other than a Binary, atm (and I'm not sure we ever will?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I guess all infinite analysis loops would involve a Binary expression somewhere. But it seems somewhat arbitrary to attach the counter to only Binary expressions. Maybe instead of counting the number of times we analyze particular expressions, we can count the number of times we analyze each basic block. That would be even more precise and less arbitrary. I guess we could do that in a follow-up, though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To me it makes sense as a Binary is where x = x + 1 happens (the + 1). Other things only flow around data.

With that said, maybe it is nicer to count basic block operations? Worth thinking about.

@kripken
kripken enabled auto-merge (squash) August 31, 2026 23:11
@kripken
kripken merged commit f870c9e into WebAssembly:main Aug 31, 2026
16 checks passed
@kripken
kripken deleted the c.nohang branch August 31, 2026 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants