Skip to content

Commit 4cae591

Browse files
committed
C++: Remove one nomagic and explain the other
1 parent 2332dad commit 4cae591

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

cpp/ql/src/semmle/code/cpp/controlflow/SubBasicBlocks.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ class SubBasicBlock extends ControlFlowNodeBase {
101101
* start from 0, and the node at index 0 always exists and compares equal
102102
* to `this`.
103103
*/
104-
pragma[nomagic]
105104
ControlFlowNode getNode(int index) {
106105
exists(BasicBlock bb |
107106
exists(int outerIndex |
@@ -115,6 +114,10 @@ class SubBasicBlock extends ControlFlowNodeBase {
115114
* Gets the index of the node in this `SubBasicBlock` that has `indexInBB` in
116115
* `bb`, where `bb` is equal to `getBasicBlock()`.
117116
*/
117+
// This predicate is factored out of `getNode` to ensure a good join order.
118+
// It's sensitive to bad magic, so it has `pragma[nomagic]` on it. For
119+
// example, it can get very slow if `getNode` is pragma[nomagic], which could
120+
// mean it might get very slow if `getNode` is used in the wrong context.
118121
pragma[nomagic]
119122
private int outerToInnerIndex(BasicBlock bb, int indexInBB) {
120123
indexInBB = result + this.getIndexInBasicBlock(bb) and

cpp/ql/src/semmle/code/cpp/dataflow/internal/SubBasicBlocks.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ class SubBasicBlock extends ControlFlowNodeBase {
101101
* start from 0, and the node at index 0 always exists and compares equal
102102
* to `this`.
103103
*/
104-
pragma[nomagic]
105104
ControlFlowNode getNode(int index) {
106105
exists(BasicBlock bb |
107106
exists(int outerIndex |
@@ -115,6 +114,10 @@ class SubBasicBlock extends ControlFlowNodeBase {
115114
* Gets the index of the node in this `SubBasicBlock` that has `indexInBB` in
116115
* `bb`, where `bb` is equal to `getBasicBlock()`.
117116
*/
117+
// This predicate is factored out of `getNode` to ensure a good join order.
118+
// It's sensitive to bad magic, so it has `pragma[nomagic]` on it. For
119+
// example, it can get very slow if `getNode` is pragma[nomagic], which could
120+
// mean it might get very slow if `getNode` is used in the wrong context.
118121
pragma[nomagic]
119122
private int outerToInnerIndex(BasicBlock bb, int indexInBB) {
120123
indexInBB = result + this.getIndexInBasicBlock(bb) and

0 commit comments

Comments
 (0)