Skip to content
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

Missing IR generation for field initialization via NSDMI #8256

Open
dbartol opened this issue Feb 25, 2022 · 2 comments
Open

Missing IR generation for field initialization via NSDMI #8256

dbartol opened this issue Feb 25, 2022 · 2 comments
Labels

Comments

@dbartol
Copy link
Contributor

dbartol commented Feb 25, 2022

I think there's an expression that isn't being translated which causes this. This also happens before any of my changes. I can look into fixing this, but would prefer to do this outside of this PR.

Originally posted by @jketema in #8225 (comment)

@jketema
Copy link
Contributor

jketema commented Feb 28, 2022

See TranslatedElement.qll. We currently handle the cases where the initializer is either a ClassAggregateLiteral or a ConstructorFieldInit which has an explicit initializer expression. Not covered is the case where there is no initializer expression, but where field being initialized does have have an initializer.

We could add something along the lines of:

    exists(ConstructorFieldInit init |
       not ignoreExpr(init) and
       ast = init and
       field = init.getTarget() and
       not exists(init.getExpr()) and
       expr = field.getInitializer().getExpr().getFullyConverted()
     )

However, this by itself is not sufficient, as the expression field.getInitializer().getExpr() does not have an enclosing function, while one is assumed to exist in the translation.

Note that the extractor does not generate a value for init.getExpr() in this case, to avoid ending up in a situation where an expression has multiple parents.

@dbartol dbartol changed the title Missing IR generation for field initialization of compiler-generated default constructor Missing IR generation for field initialization via NSDMI Mar 1, 2022
@dbartol
Copy link
Contributor Author

dbartol commented Mar 1, 2022

Thanks for the investigation. This is indeed not a trivial fix.

Ideas for whoever does attempt to tackle this:

  1. Generate a separate set of IR instructions/operands for the field initializer expression in each constructor in which it is implicitly used. Pro: probably the simplest solution. Con: Breaks the existing invariant that each AST expression has a single IR instruction that produces its result.
  2. Have the extractor generate a copy of the initializer expression to use as the actual field initializer in each constructor that needs it. The IR construction would then treat this like any other initializer. Pro: Preserves existing invariants. Con: Requires extractor change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants