Skip to content

Conversation

dbartol
Copy link

@dbartol dbartol commented Jun 15, 2020

This PR introduces a new IR consistency check (for Instructions with zero or multiple getEnclosingIRFunction() results), fixes the existing instances of those, and improves the output of the consistency queries to handle missing and duplicate results when creating the actual failure result tuples.

Fixed failures
C++ - TTranslatedAllocationSideEffects wasn't limiting itself to functions that actually have IR, so it was getting used even in template definitions.
C# - We were creating a TranslatedFunction even for functions that were not from source code, but then telling the IR package that those functions didn't have IR. This resulted in having prologue/epilogue instructions (e.g. EnterFunction, ExitFunction) with no enclosing IRFunction.

Improved output
Some of our IR consistency failure query predicates already produced results in the schema as an @kind problem query, including $@ replacements for the enclosing IRFunction to make it easier to figure out which function to dump when debugging. This change moves the rest of the query predicates in IRConsistency.qll to do the same. In addition, it wraps each call to getEnclosingIRFunction() to return an OptionalIRFunction, which can be either a real IRFunction or a placeholder in case getEnclosingIRFunction() returned no results. This exposes a couple new consistency failures in syntax-zoo, which will be fixed in a subsequent commit.

This change also deals with consistency failures when the enclosing IRFunction has more than one Function or Location. For multiple Functions, we concatenate the function names. For multiple Locations, we pick the first one in lexicographical order. This changes the number of results produced in the existing tests, but does't change the actual number of problems.

Dave Bartolomeo added 3 commits June 15, 2020 10:46
Some of our IR consistency failure query predicates already produced results in the schema as an `@kind problem` query, including `$@` replacements for the enclosing `IRFunction` to make it easier to figure out which function to dump when debugging. This change moves the rest of the query predicates in `IRConsistency.qll` to do the same. In addition, it wraps each call to `getEnclosingIRFunction()` to return an `OptionalIRFunction`, which can be either a real `IRFunction` or a placeholder in case `getEnclosingIRFunction()` returned no results. This exposes a couple new consistency failures in `syntax-zoo`, which will be fixed in a subsequent commit.

This change also deals with consistency failures when the enclosing `IRFunction` has more than one `Function` or `Location`. For multiple `Function`s, we concatenate the function names. For multiple `Location`s, we pick the first one in lexicographical order. This changes the number of results produced in the existing tests, but does't change the actual number of problems.
`TTranslatedAllocationSideEffects` wasn't limiting itself to functions that actually have IR, so it was getting used even in template definitions.
We were creating a `TranslatedFunction` even for functions that were not from source code, but then telling the IR package that those functions didn't have IR. This resulted in having prologue/epilogue instructions (e.g. `EnterFunction`, `ExitFunction`) with no enclosing `IRFunction`.
@dbartol dbartol added the C++ label Jun 15, 2020
@dbartol dbartol requested review from a team as code owners June 15, 2020 15:46
Copy link
Contributor

@jbj jbj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// To avoid an overwhelming number of results when the extractor merges functions with the
// same name, just pick a single location.
result =
rank[1](Language::Location loc | loc = irFunc.getLocation() | loc order by loc.toString())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rank[1] can also be spelled min

@jbj jbj merged commit d80a033 into github:master Jun 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants