Skip to content

Query running forever #4909

Description

@powerthe900

I was running a query on a project and it is stuck on Running query: Stage 10/10 - computing '#select#ff' for hours. I tried different projects and the same thing happened.

My query is

import cpp
import semmle.code.cpp.ir.IR

/** Holds if `i` is a narrowing conversion. */
predicate isNarrowingConversion(ConvertInstruction i) {
  i.getResultSize() < i.getUnary().getResultSize()
}

from ConvertInstruction conv, Type inputType, Type outputType, FunctionCall fc
where
fc.getTarget().getQualifiedName() = "accept" or fc.getTarget().getQualifiedName() = "accept4" and
conv.getEnclosingFunction().calls(fc.getTarget()) and
isNarrowingConversion(conv) and
inputType = conv.getUnary().getResultType() and
outputType = conv.getResultType()
select conv, "Narrowing conversion from " + inputType + " to " + outputType + "."

Activity

  1. rdmarsh2 commented on Jan 4, 2021

    @rdmarsh2
    Contributor

    It looks like you're missing some parentheses around the or, which is leading to an unconstrained join (also called a Cartesian product) across multiple tables. In CodeQL, a() or b() and c() is parsed as a() or (b() and c()). In this case, since fc.getTarget().getQualifiedName() = "accept" doesn't set any requirements for the other variables, you'll get every possible combination of ConvertInstruction and two types, plus the results you were expecting where fc is a call to accept4.

    I'd recommend using the autoformatter (alt+shift+F in the VS Code extension) to make these kinds of mistakes more obvious. In this particular case, the formatted code would look like this:

    from ConvertInstruction conv, Type inputType, Type outputType, FunctionCall fc
    where
      fc.getTarget().getQualifiedName() = "accept"
      or
      fc.getTarget().getQualifiedName() = "accept4" and
      conv.getEnclosingFunction().calls(fc.getTarget()) and
      isNarrowingConversion(conv) and

    And the fixed code would look like this:

    from ConvertInstruction conv, Type inputType, Type outputType, FunctionCall fc
    where
      (
        fc.getTarget().getQualifiedName() = "accept"
        or
        fc.getTarget().getQualifiedName() = "accept4"
      ) and
      conv.getEnclosingFunction().calls(fc.getTarget()) and
      isNarrowingConversion(conv) and
  2. powerthe900 commented on Jan 5, 2021

    @powerthe900
    Author

    thanks

  3. github-actions commented on Apr 16, 2021

    @github-actions
    Contributor

    This issue is stale because it has been open 14 days with no activity. Comment or remove the stale label in order to avoid having this issue closed in 7 days.

  4. locked and limited conversation to collaborators on Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    StalequestionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions