Skip to content

Conversation

jbj
Copy link
Contributor

@jbj jbj commented Sep 11, 2018

On a snapshot of Postgres, evaluation of getNextExplicitlyInitializedElementAfter#fff#antijoin_rhs#1 took forever, preventing the computation of the IR. I haven't been able to reproduce it with a small test case, but the implementation of getNextExplicitlyInitializedElementAfter was fragile because it called the inline predicate ArrayAggregateLiteral.isInitialized. It also seemed inefficient that getNextExplicitlyInitializedElementAfter was computed for many values of its parameters that were never needed by the caller.

This commit replaces getNextExplicitlyInitializedElementAfter with a new predicate named getEndOfValueInitializedRange, which should have the same behavior but a more efficient implementation. It uses a helper predicate getNextExplicitlyInitializedElementAfter, which shares its name with the now-deleted predicate but has behavior that I think matches the name.

I've made this PR against the RC because I worry that the IR will be useless on too many snapshots without this fix.

On a snapshot of Postgres, evaluation of
`getNextExplicitlyInitializedElementAfter#fff#antijoin_rhs#1` took
forever, preventing the computation of the IR. I haven't been able to
reproduce it with a small test case, but the implementation of
`getNextExplicitlyInitializedElementAfter` was fragile because it called
the inline predicate `ArrayAggregateLiteral.isInitialized`. It also
seemed inefficient that `getNextExplicitlyInitializedElementAfter` was
computed for many values of its parameters that were never needed by the
caller.

This commit replaces `getNextExplicitlyInitializedElementAfter` with a
new predicate named `getEndOfValueInitializedRange`, which should have
the same behavior but a more efficient implementation. It uses a helper
predicate `getNextExplicitlyInitializedElementAfter`, which shares its
name with the now-deleted predicate but has behavior that I think
matches the name.
@jbj jbj added the C++ label Sep 11, 2018
@jbj jbj added this to the 1.18 milestone Sep 11, 2018
isFirstValueInitializedElementInRange(initList, elementIndex) and
elementCount =
getNextExplicitlyInitializedElementAfter(initList, elementIndex) -
getEndOfValueInitializedRange(initList, elementIndex) -
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you need an or getNextExplicitlyInitializedElementAfter too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Fixed.

private int getEndOfValueInitializedRange(ArrayAggregateLiteral initList, int afterElementIndex) {
result = getNextExplicitlyInitializedElementAfter(initList, afterElementIndex)
or
isFirstValueInitializedElementInRange(initList, afterElementIndex) and
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be in both halves of the disjunction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getNextExplicitlyInitializedElementAfter calls isFirstValueInitializedElementInRange, so adding another call in this predicate would be redundant.

@jbj
Copy link
Contributor Author

jbj commented Sep 11, 2018

It sounds like I ought to add a test that depends on a non-empty getNextExplicitlyInitializedElementAfter in order to gain confidence that this change is right. Now that we have designated initializers for arrays, that should be possible.

@jbj
Copy link
Contributor Author

jbj commented Sep 11, 2018

I've added a simple test to exercise the changed predicate. The results are the same before and after this change. The generated IR looks wrong in both cases, though. All the right code is generated, but Block 0 jumps to Block 2 and never lets Block 1 and Block 3 run. Can you explain this, @dave-bartolomeo?

Copy link
Contributor

@dave-bartolomeo dave-bartolomeo left a comment

Choose a reason for hiding this comment

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

LGTM

The bad IR seems to be unaffected by your change, so I don't think it should block the merge of this PR. Please open a JIRA ticket and I'll investigate the bad IR.

@dave-bartolomeo dave-bartolomeo merged commit c9cb2a0 into github:rc/1.18 Sep 14, 2018
@jbj
Copy link
Contributor Author

jbj commented Sep 14, 2018

Bug filed: https://jira.semmle.com/browse/CPP-260

smowton pushed a commit to smowton/codeql that referenced this pull request Jan 17, 2022
Adjust PrintAST query to handle kotlin constructs
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.

3 participants