[llvm-bugs] [Bug 42956] New: Assembler errors with __builtin_constant_p()
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Aug 10 09:15:20 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=42956
Bug ID: 42956
Summary: Assembler errors with __builtin_constant_p()
Product: clang
Version: 8.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C
Assignee: unassignedclangbugs at nondot.org
Reporter: clang at gmch.uk
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
Created attachment 22367
--> https://bugs.llvm.org/attachment.cgi?id=22367&action=edit
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 Bug 41027 -- 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
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190810/548c6991/attachment.html>
More information about the llvm-bugs
mailing list