[cfe-dev] CFG Terminator Conditions
Gábor Horváth via cfe-dev
cfe-dev at lists.llvm.org
Fri Aug 3 14:35:47 PDT 2018
Hi!
I found the terminator condition for binary operators a bit unintuitive in
the CFG. I was wondering if I am missing something or it is a possible
improvement.
Let's consider the following simple code snippet:
void g(bool a, bool b) {
if (a || b) {
body();
} else {
body2();
}
}
We get the following CFG:
[B1]
1: body2
2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(void))
3: [B1.2]()
Preds (1): B3
Succs (1): B0
[B2]
1: body
2: [B2.1] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(void))
3: [B2.2]()
Preds (2): B3 B4
Succs (1): B0
[B3]
1: b
2: [B3.1] (ImplicitCastExpr, LValueToRValue, _Bool)
T: if [B4.2] || [B3.2]
Preds (1): B4
Succs (2): B2 B1
[B4]
1: a
2: [B4.1] (ImplicitCastExpr, LValueToRValue, _Bool)
T: [B4.2] || ...
Preds (1): B5
Succs (2): B2 B3
The terminator condition for [B4] is (a cast above) a. This is pretty
intuitive. This value will determine which branch do we take when we leave
the basic block.
The terminator condition for [B3], however, is the whole binary or
expression. I would expect it to be the right hand side of the logical or.
What do you think? What is the reason that we have the whole expression
here?
Regards,
Gabor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180803/6b6feb31/attachment.html>
More information about the cfe-dev
mailing list