Skip to content

Don't use down_cast<> with the assumption that type-mismatch returns … #2423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

hzeller
Copy link
Collaborator

@hzeller hzeller commented May 31, 2025

…null.

We typically don't compile-in RTTI so relying on down_cast<> returning nullptr or a correct type will result in subtle issues.

Instead, provide MaybeNode() and MaybeLeaf() that use the SymbolKind to provide such casts.

This should be expanded:

  • Ideally we remove all uses of down_cast<> and use type-safe ways of doing the same thing (and then: remove verible::down_cast<>).
  • There are a few places where we CHECK() fail on type-mismatch, assuming these can't happen; but that depends on how valid our syntax tree is, which depends on the input the the parser to reject such input. These should be reformulated with graceful error handling.

Fixes #2419

@hzeller hzeller force-pushed the feature-20250531-limit-down-cast branch from 4c88b0c to 5af8645 Compare May 31, 2025 14:06
…null.

We typically don't compile-in RTTI so relying on down_cast<> returning
nullptr or a correct type will result in subtle issues.

Instead, provide MaybeNode() and MaybeLeaf() that use the SymbolKind
to provide such casts.

This should be expanded:
  * Ideally we remove _all_ uses of down_cast<> and use type-safe
    ways of doing the same thing (and then: remove verible::down_cast<>).
  * There are a few places where we CHECK() fail on type-mismatch, assuming
    these can't happen; but that depends on how valid our syntax tree is,
    which depends on the input the the parser to reject such input. These
    should be reformulated with graceful error handling.

Fixes chipsalliance#2419
@hzeller hzeller force-pushed the feature-20250531-limit-down-cast branch from 5af8645 to b41588e Compare May 31, 2025 14:11
@hzeller hzeller requested a review from fangism May 31, 2025 15:10
@hzeller hzeller merged commit 6834307 into chipsalliance:master Jun 3, 2025
33 checks passed
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.

LSP crashes when opening a file (create-object-name-match-rule.cc)
2 participants