I've written a patch to fix this. It's not super smart, but it should do the job. It currently targets the branch after my patch in #32408[1], but it's technically an independent change. [1]: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=32408