Skip to content

Commit

Permalink
C++: Fix IR printing when multiple edges point to the same block
Browse files Browse the repository at this point in the history
  • Loading branch information
jketema committed Dec 10, 2024
1 parent f491672 commit 8c49470
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,18 @@ query predicate edges(PrintableIRBlock pred, PrintableIRBlock succ, string key,
succBlock = succ.getBlock() and
predBlock.getSuccessor(kind) = succBlock and
(
(
key = "semmle.label" and
key = "semmle.label" and
exists(string kinds |
kinds =
concat(EdgeKind k |
predBlock.getSuccessor(k) = succBlock
|
k.toString(), "|" order by k.toString()
)
|
if predBlock.getBackEdgeSuccessor(kind) = succBlock
then value = kind.toString() + " (back edge)"
else value = kind.toString()
then value = kinds + " (back edge)"
else value = kinds
)
or
key = "semmle.order" and
Expand Down
15 changes: 11 additions & 4 deletions cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/PrintIR.qll
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,18 @@ query predicate edges(PrintableIRBlock pred, PrintableIRBlock succ, string key,
succBlock = succ.getBlock() and
predBlock.getSuccessor(kind) = succBlock and
(
(
key = "semmle.label" and
key = "semmle.label" and
exists(string kinds |
kinds =
concat(EdgeKind k |
predBlock.getSuccessor(k) = succBlock
|
k.toString(), "|" order by k.toString()
)
|
if predBlock.getBackEdgeSuccessor(kind) = succBlock
then value = kind.toString() + " (back edge)"
else value = kind.toString()
then value = kinds + " (back edge)"
else value = kinds
)
or
key = "semmle.order" and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,18 @@ query predicate edges(PrintableIRBlock pred, PrintableIRBlock succ, string key,
succBlock = succ.getBlock() and
predBlock.getSuccessor(kind) = succBlock and
(
(
key = "semmle.label" and
key = "semmle.label" and
exists(string kinds |
kinds =
concat(EdgeKind k |
predBlock.getSuccessor(k) = succBlock
|
k.toString(), "|" order by k.toString()
)
|
if predBlock.getBackEdgeSuccessor(kind) = succBlock
then value = kind.toString() + " (back edge)"
else value = kind.toString()
then value = kinds + " (back edge)"
else value = kinds
)
or
key = "semmle.order" and
Expand Down
4 changes: 2 additions & 2 deletions cpp/ql/test/library-tests/ir/ir/aliased_ir.expected
Original file line number Diff line number Diff line change
Expand Up @@ -38831,7 +38831,7 @@ try_except.c:
# 23| v23_3(void) = Call[ProbeFunction] : func:r23_1, 0:r23_2
# 23| m23_4(unknown) = ^CallSideEffect : ~m21_5
# 23| m23_5(unknown) = Chi : total:m21_5, partial:m23_4
#-----| SEH Exception -> Block 4
#-----| Goto|SEH Exception -> Block 4

# 26| Block 4
# 26| m26_1(unknown) = Phi : from 0:~m21_5, from 3:~m23_5
Expand Down Expand Up @@ -39028,7 +39028,7 @@ try_except.cpp:
# 23| v23_3(void) = Call[ProbeFunction] : func:r23_1, 0:r23_2
# 23| m23_4(unknown) = ^CallSideEffect : ~m21_5
# 23| m23_5(unknown) = Chi : total:m21_5, partial:m23_4
#-----| SEH Exception -> Block 4
#-----| Goto|SEH Exception -> Block 4

# 26| Block 4
# 26| m26_1(unknown) = Phi : from 0:~m21_5, from 3:~m23_5
Expand Down
4 changes: 2 additions & 2 deletions cpp/ql/test/library-tests/ir/ir/raw_ir.expected
Original file line number Diff line number Diff line change
Expand Up @@ -37077,7 +37077,7 @@ try_except.c:
# 23| r23_2(int) = Constant[0] :
# 23| v23_3(void) = Call[ProbeFunction] : func:r23_1, 0:r23_2
# 23| mu23_4(unknown) = ^CallSideEffect : ~m?
#-----| SEH Exception -> Block 4
#-----| Goto|SEH Exception -> Block 4

# 26| Block 4
# 26| r26_1(glval<unknown>) = FunctionAddress[sink] :
Expand Down Expand Up @@ -37266,7 +37266,7 @@ try_except.cpp:
# 23| r23_2(int) = Constant[0] :
# 23| v23_3(void) = Call[ProbeFunction] : func:r23_1, 0:r23_2
# 23| mu23_4(unknown) = ^CallSideEffect : ~m?
#-----| SEH Exception -> Block 4
#-----| Goto|SEH Exception -> Block 4

# 26| Block 4
# 26| r26_1(glval<unknown>) = FunctionAddress[sink] :
Expand Down

0 comments on commit 8c49470

Please sign in to comment.