<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - Assembler errors with __builtin_constant_p()"
href="https://bugs.llvm.org/show_bug.cgi?id=42956">42956</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Assembler errors with __builtin_constant_p()
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>8.0
</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>C
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>clang@gmch.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=22367" name="attach_22367" title="Program showing bug and workaround. With correctly compiled code attached.">attachment 22367</a> <a href="attachment.cgi?id=22367&action=edit" title="Program showing bug and workaround. With correctly compiled code attached.">[details]</a></span>
Program showing bug and workaround. With correctly compiled code attached.
I have some small assembler functions, __attribute__((__always_inline__)),
which do slightly different things where arguments are __builtin_constant_p().
In the attachment there is a small test for one of the functions, followed by
the code generated when it can be persuaded to work.
[Lines 61, 65 and 104 in the attachment have been marked for reference.]
When the attached code is compiled for x86-64 with clang 8.0.0 -O3 -std=c11, I
get the following:
<source>:104:13: error: invalid operand for inline asm constraint 'i'
__asm__("\t shll %[s], %k[r]\n" : [r] "+r" (r32) : [s] "i" (I)) ;
^
<source>:104:13: error: invalid operand for inline asm constraint 'i'
<source>:104:13: error: invalid operand for inline asm constraint 'i'
3 errors generated.
ASM generation compiler returned: 1
<source>:104:13: error: invalid operand for inline asm constraint 'i'
__asm__("\t shll %[s], %k[r]\n" : [r] "+r" (r32) : [s] "i" (I)) ;
^
<source>:104:13: error: invalid operand for inline asm constraint 'i'
<source>:104:13: error: invalid operand for inline asm constraint 'i'
3 errors generated.
Execution build compiler returned: 1
Note that line 81 is similar to line 104, but does *not* generate an error.
By process of elimination, I find that it is "trial"s 4, 8 and 12 which
generate errors. Those have not-compile-time-constant 's' argument. The
"trial"s 3, 7 and 11 also have not-compile-time-constant 's', but do not
generate an error.
Changing the '#if 0' to '#if 1' on line 61 turns on a "workaround", and the
test produces the expected results:
ASM generation compiler returned: 0
Execution build compiler returned: 0
Program returned: 0
1: qbins(d32=ffffffff, u32=a5a5a5a5, s=$5, l=$17) -> fff4b4bf
2: qbins(d32=ffffffff, u32=a5a5a5a5, s=$7, l=15) -> ffd2d2ff
3: qbins(d32=ffffffff, u32=a5a5a5a5, s=9, l=$13) -> ffcb4bff
4: qbins(d32=ffffffff, u32=a5a5a5a5, s=11, l=11) -> ffed2fff
5: qbins(d32=ffffffff, u32=a5a5a5a5, s=$13, l=$0) -> ffffffff
6: qbins(d32=ffffffff, u32=a5a5a5a5, s=$15, l=0) -> ffffffff
7: qbins(d32=ffffffff, u32=a5a5a5a5, s=17, l=$0) -> ffffffff
8: qbins(d32=ffffffff, u32=a5a5a5a5, s=19, l=0) -> ffffffff
9: qbins(d32=ffffffff, u32=a5a5a5a5, s=$0, l=$32) -> a5a5a5a5
10: qbins(d32=ffffffff, u32=a5a5a5a5, s=$0, l=32) -> a5a5a5a5
11: qbins(d32=ffffffff, u32=a5a5a5a5, s=0, l=$32) -> a5a5a5a5
12: qbins(d32=ffffffff, u32=a5a5a5a5, s=0, l=32) -> a5a5a5a5
Where values with a '$' are compile-time-constants.
For completeness, the attachment includes the code generated when the
"workaround" is in place, showing the expected variation in the code generated,
depending on whether the 's' and/or 'l' arguments are compile-time-constant or
not (annotated).
This is a slightly long report. The cases which do not generate errors seem
almost as interesting as the ones which don't. So I have not cut this down to
only show the errors.
I guess this is related to <a class="bz_bug_link
bz_status_NEW "
title="NEW - Inline asm validation doesn't use delayed warnings"
href="show_bug.cgi?id=41027">Bug 41027</a> -- though that speaks only of warnings.
The workaround provides a valid compile-time-constant as 'im' for when 's' is
not a compile-time-constant.
Chris</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>