Skip to content

Conversation

llvmbot
Copy link
Member

@llvmbot llvmbot commented Sep 22, 2023

(cherry picked from commit 8b4e29b35d21b079e8b30244cbbfc4d4bc4a29d4)
The write to the SEH catch object happens before cleanuppads are
executed, while the first reference to the object will typically
be in a catchpad.

If we make use of first-use analysis, we may end up allocating
an alloca used inside the cleanuppad and the catch object at the
same stack offset, which would be incorrect.

https://reviews.llvm.org/D86673 was a previous attempt to fix it.
It used the heuristic "a slot loaded in a WinEH pad and never
written" to detect catch objects. However, because it checks
for more than one load (while probably more than zero was
intended), the fix does not actually work.

The general approach also seems dubious to me, so this patch
reverts that change entirely, and instead marks all catch object
slots as conservative (i.e. excluded from first-use analysis)
based on the WinEHFuncInfo. As far as I can tell we don't need
any heuristics here, we know exactly which slots are affected.

Fixes llvm/llvm-project#66984.

(cherry picked from commit b3cb4f069c2cb99bdae68d6906156af20e76314f)
This is a followup to #66988. The implementation there did not
account for the possibility of the catch object frame index
referrring to a fixed object, which is the case on win64.

(cherry picked from commit aa70f4d8cf8f09a2997773156289b16d6a16ec01)
@tru
Copy link
Contributor

tru commented Sep 25, 2023

@nikic should we merge this into 17.0.1?

@nikic
Copy link
Contributor

nikic commented Sep 26, 2023

Yeah, this fixes a miscompile seen in the wild.

@tru tru merged commit 9678f11 into release/17.x Sep 27, 2023
@tru tru deleted the llvm-issue66984 branch September 27, 2023 15:53
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.

Incorrect stack coloring for alloca in SEH cleanuppad
3 participants