Skip to content

Conversation

@Lunderberg
Copy link
Contributor

Prior to this commit, after the DiagnosticContext prints its error, it overwrites the DiagnosticRenderer with a NULL renderer. If a second call to DiagnosticContext::Render occurs, it will segfault. This appears to be intended to prevent double-printing of error messages, but double-printing error messages is much worse than a segfault.

In addition, DiagnosticContext::Render should only be called once. There's a common pattern in the parser where it will wrap exceptions in DiagnosticError, but re-raise exceptions that are already a DiagnosticError. This requires every such location to include except DiagnosticError: raise, and can easily be missed.

This PR makes two changes: First, the DiagnosticRenderer is updated to have a no-op callback rather than a NULL callback. Second, the re-raising of DiagnosticError is moved to Parser.report_error, so that it does not need to be handled separately at several independent locations in the TVMScript parser.

Prior to this commit, after the `DiagnosticContext` prints its error,
it overwrites the `DiagnosticRenderer` with a NULL renderer.  If a
second call to `DiagnosticContext::Render` occurs, it will segfault.
This appears to be intended to prevent double-printing of error
messages, but double-printing error messages is much worse than a
segfault.

In addition, `DiagnosticContext::Render` should only be called once.
There's a common pattern in the parser where it will wrap exceptions
in `DiagnosticError`, but re-raise exceptions that are already a
`DiagnosticError`.  This requires every such location to include
`except DiagnosticError: raise`, and can easily be missed.

This PR makes two changes: First, the `DiagnosticRenderer` is updated
to have a no-op callback rather than a NULL callback.  Second, the
re-raising of `DiagnosticError` is moved to `Parser.report_error`, so
that it does not need to be handled separately at several independent
locations in the TVMScript parser.
@Lunderberg Lunderberg force-pushed the relax_avoid_segfault_from_incorrect_tensor_annotation branch from d62a4e9 to ac86991 Compare September 16, 2024 13:14
@tqchen
Copy link
Member

tqchen commented Sep 17, 2024

@tvm-bot rerun

@tqchen tqchen merged commit ff8e416 into apache:main Sep 17, 2024
@Lunderberg Lunderberg deleted the relax_avoid_segfault_from_incorrect_tensor_annotation branch September 17, 2024 14:30
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