<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Implicit basic block labels are undocumented and confusing"
href="http://llvm.org/bugs/show_bug.cgi?id=16043">16043</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Implicit basic block labels are undocumented and confusing
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>pmiscml@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Running "clang -x c -emit-llvm -S -O2 test.c" on:
---------
int bar(int a);
int foo(int a, int b)
{
if (bar(a))
return a + b;
else
return a * b;
}
---------
Leads to following LLVM asm output:
---------
define i32 @foo(i32 %a, i32 %b) nounwind {
%1 = tail call i32 @bar(i32 %a) nounwind
%2 = icmp eq i32 %1, 0
br i1 %2, label %5, label %3
; <label>:3 ; preds = %0
%4 = add nsw i32 %b, %a
br label %7
; <label>:5 ; preds = %0
%6 = mul nsw i32 %b, %a
br label %7
; <label>:7 ; preds = %5, %3
%.0 = phi i32 [ %4, %3 ], [ %6, %5 ]
ret i32 %.0
}
declare i32 @bar(i32)
---------
Lack of explicit %3, %5, %7 labels looks rather confusing.
<a href="http://llvm.org/docs/LangRef.html">http://llvm.org/docs/LangRef.html</a> gives very vague hint: "Each basic block may
optionally start with a label", it doesn't describe how handled a case when
label is not given. Googling with terms like "llvm implicit basic block labels"
and "llvm basic block without labels" didn't provide any useful hits.
After some consideration, and based on previous experience with LLVM internal
structures, I was abel to understand how implicit labels handled, the algorithm
for assigning names to unnamed entities within a function appears to be:
1. For each function, "unnamed entity" counter is initialized with 0.
2. Whenever unnamed tmp var is seen, it's assigned name as counter++
value.
3. Whenever unlabeled block is seen, it's assigned label as counter++
value.
However, all this matters got to be very confusing for novices, and thus reduce
adoption of LLVM technology.
Suggestions for resolution:
1. Definitely describe implicit label behavior in LangRef and probably, FAQ.
2. Consider always outputting explicit labels. Still support implicit labels
for parsing.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>