Fix an ICE on diagnostics originating in external macros

Closes #14091.
Closes #19195.