Skip to content

Conversation

@MathiasVP
Copy link
Contributor

@MathiasVP MathiasVP commented Jan 13, 2025

On main we have BarrierGuards for:

  • Operand/Instruction nodes for reasoning about barriers at the instruction level (using DataFlow::InstructionBarrierGuard<myPredicate/3>::getABarrierNode())
  • Expr nodes for reasoning about barriers at the expression level (using DataFlow::BarrierGuard<myPredicate/3>::getABarrierNode()`)
  • Indirect Expr nodes for reasoning about barriers on the pointed-to value of an expression (using DataFlow::BarrierGuard<myPredicate/3>::getAnIndirectBarrierNode())

Spot an obvious missing one? We never added a BarrierGuard for reasoning about indirect instruction/operand nodes.

Barriers on indirections are nice when working with functions that validate the data pointed to by an argument to a function call. For example:

bool isValidData(char* data);
// ...
data = getInput();
if(isValidData(data)) {
 // process data
}

currently, if you want to reason about *data (that is, the indirection of data) you need to use an Expr-based BarrierGuard as there is no module for indirect instruction/operand nodes.

This PR adds DataFlow::InstructionBarrierGuard<myPredicate/3>::getAnIndirectBarrierNode() to complete the missing API. We plan on using this predicate internally at Microsoft.

Commit-by-commit review recommended:

  • d63b734 adds a skeleton predicate that's necessary to compile the test in the next commit.
  • 4e3b27e adds a testcase that needs indirect barrier guards for instruction/operand nodes.
  • 6f3a2c4 fills in the skeleton. This is pretty much a copy/paste of the direct case, but with node.asOperand replaced with node.asIndirectOperand. So nothing interesting going on there.
  • 91992e2 accepts the test changes

I have not started a DCA run as this code isn't used by any queries yet.

Copilot AI review requested due to automatic review settings January 13, 2025 18:45
@MathiasVP MathiasVP requested a review from a team as a code owner January 13, 2025 18:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 1 out of 4 changed files in this pull request and generated no comments.

Files not reviewed (3)
  • cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll: Language not supported
  • cpp/ql/test/library-tests/dataflow/ir-barrier-guards/test.cpp: Language not supported
  • cpp/ql/test/library-tests/dataflow/ir-barrier-guards/test.ql: Language not supported

Tip: If you use Visual Studio Code, you can request a review from Copilot before you push from the "Source Control" tab. Learn more

@github-actions github-actions bot added the C++ label Jan 13, 2025
Copy link
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

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

LGTM

@MathiasVP MathiasVP merged commit 0ff37f1 into github:main Jan 14, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants