Skip to content

Conversation

dbartol
Copy link

@dbartol dbartol commented Jun 26, 2020

This PR adds QLDoc for every opcode in Opcode.qll. It's is all copied from the corresponding Instruction.qll QLDoc via a Python script, included as part of the PR.

There are a few preparatory commits to clean up some existing QLDoc comments, add a few missing Instruction classes, etc.

Dave Bartolomeo added 3 commits June 26, 2020 09:04
- Remove unused `MemoryAccessOpcode`
- Make `OpcodeWithCondition` private
- Add QLDoc for `Opcode` module
- Renamed `DynamicCastToVoid` to the more descriptive `CompleteObjectAddress`
- Split verbose description from summary in a few Instruction QLDoc comments.
- Added `Instruction` classes for the few remaining `Opcode`s that didn't have one.
- Removed a use of "e.g."
For every concrete `Opcode`, there is a corresponding `Instruction` class. Rather than duplicate all of the QLDoc by hand, I wrote a quick Python script to copy the QLDoc from `Instruction.qll` to `Opcode.qll`. I don't expect that we will need to do this often, so I'm not hooking it up to a PR check or anything like that, but I did commit the script itself in case we need it again.
@dbartol dbartol requested review from a team as code owners June 26, 2020 15:44
@dbartol dbartol added the C++ label Jun 26, 2020
Dave Bartolomeo added 4 commits June 26, 2020 13:45
This auto-generates even more QLDoc for `Opcode.qll`
As discussed in today's C++ analysis team meeting. `Opcode` is rarely used directly, so we'll just refer to the documentation for the corresponding `Instruction` class.

I've preserved the script in case we want to do a bulk change of all of the `Opcode` comments, but I don't expect it will be needed if we just add a new `Opcode` or two.
@dbartol
Copy link
Author

dbartol commented Jun 29, 2020

I've implemented the changes we discussed in today's C++ analysis team meeting, so now the Opcode docs just refer to the corresponding Instruction docs.

@dbartol dbartol changed the title C++: QLDoc for Opcode.qll C++: More IR QLDoc (including Opcode.qll) Jun 29, 2020
@dbartol
Copy link
Author

dbartol commented Jun 29, 2020

Since this PR hadn't been reviewed yet anyway, I've added QLDoc for several more files.

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.

The addition of all this documentation clears one of the big hurdles for the IR to become more widely used. Well done!

I have some comments that I think should be addressed, but I don't think they're blocking the merge of this PR.

final Language::Location getLocation() { result = getFirstInstruction().getLocation() }

/**
* Gets a string that uniquely identifies this block within its enclosing function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be marked INTERNAL: Do not use.?

final Language::Location getLocation() { result = getFirstInstruction().getLocation() }

/**
* Gets a string that uniquely identifies this block within its enclosing function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be marked INTERNAL: Do not use.? Same for getDisplayIndex.

final PhiInstruction getAPhiInstruction() {
Construction::getPhiInstructionBlockStart(result) = getFirstInstruction()
}

/**
* Get the instructions in this block, including `Phi` instructions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Get the instructions in this block, including `Phi` instructions.
* Gets an instruction in this block. This includes `Phi` instructions.

https://github.com/github/codeql/blob/master/docs/qldoc-style-guide.md#predicates-with-result

@@ -74,28 +110,65 @@ class IRBlockBase extends TIRBlock {
* instruction of another block.
*/
class IRBlock extends IRBlockBase {
/**
* Gets the blocks to which control flows directly from this block.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Gets the blocks to which control flows directly from this block.
* Gets a block to which control flows directly from this block.

final IRBlock getASuccessor() { blockSuccessor(this, result) }

/**
* Gets the blocks from which control flows directly to this block.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Gets the blocks from which control flows directly to this block.
* Gets a block from which control flows directly to this block.

final predicate dominates(IRBlock block) { strictlyDominates(block) or this = block }

/**
* Gets the set of blocks on the dominance frontier of this block.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Gets the set of blocks on the dominance frontier of this block.
* Gets a block on the dominance frontier of this block.

@@ -162,20 +163,26 @@ class IRGeneratedVariable extends IRVariable {

override string getUniqueId() { none() }

/**
* Gets a string containing the source code location of the AST that generated this variable.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be marked INTERNAL: Do not use.? Same for getBaseString.

@@ -1880,6 +1988,10 @@ class BuiltInOperationInstruction extends Instruction {
operation = Raw::getInstructionBuiltInOperation(this)
}

/**
* Gets the language-specific `BuildInOperation` object that specifies the operation that is
Copy link
Contributor

Choose a reason for hiding this comment

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

s/BuildInOperation/BuiltInOperation/

@dbartol
Copy link
Author

dbartol commented Jun 30, 2020

Thanks. I'll address all of the above feedback in a follow-up PR.

@jbj jbj merged commit 63de58c into github:master Jun 30, 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