-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
| Bugzilla Link | 2343 |
| Resolution | FIXED |
| Resolved on | Nov 07, 2018 00:17 |
| Version | trunk |
| OS | Linux |
| Attachments | Function is question |
| CC | @isanbard,@nlewycky |
Extended Description
It seems, that recent taildup changes revealed some subtle bugs not known before. Consider attached .bc file. The C snippet in question is:
tree cases = get_cases_for_edge (e, stmt);
/* If we have a list of cases associated with E, then use it
as it's a lot faster than walking the entire case vector. */
if (cases)
{
edge e2 = find_edge (e->src, dest);
tree last, first;
first = cases;
while (cases)
{
last = cases;
CASE_LABEL (cases) = label;
cases = TREE_CHAIN (cases);
}
/* If there was already an edge in the CFG, then we need
to move all the cases associated with E to E2. */
if (e2)
{
tree cases2 = get_cases_for_edge (e2, stmt);
TREE_CHAIN (last) = TREE_CHAIN (cases2);
TREE_CHAIN (cases2) = first;
}
}
From this we can see, that last is the 'if (e2)' is always non-NULL. The LLVM IR is also fine (only part showed):
bb392: ; preds = %bb379, %bb319
%last.0 = phi %struct.tree_node* [ undef, %bb319 ], [ %cases.0, %bb379 ] ; <%struct.tree_node*> [#use$
%cases.0 = phi %struct.tree_node* [ %tmp314, %bb319 ], [ %tmp391, %bb379 ] ; <%struct.tree_node*> [#use$
%tmp394 = icmp eq %struct.tree_node* %cases.0, null ; [#uses=1]
br i1 %tmp394, label %bb397, label %bb326
This is header of the loop and jump from %bb319 is possible iff %tmp314 is non-null, thus loop executes at least one time and %last.0 is properly initialized (thus - non null).
Let's look into generated assembler:
movl %ecx, %ebx
testl %ebx, %ebx
jne .LBB1_47 # bb326
.LBB1_52: # bb397
testl %eax, %eax
je .LBB1_80 # bb695
.LBB1_53: # bb402
movl %esi, 4(%esp)
movl %eax, (%esp)
call get_cases_for_edge
movl (%eax), %esi
movl %esi, (%ebx)
here %last.0 is %ebx and we saw that after call %ebx is always zero! I suppose, that codedegen 'merged' %last.0 and %cases.0 somehow (or some codegen passes)