[llvm-bugs] [Bug 41459] New: __builtin_constant_p() appears to return true for non-constant argument

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Apr 10 14:36:58 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=41459

            Bug ID: 41459
           Summary: __builtin_constant_p() appears to return true for
                    non-constant argument
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: arnd at linaro.org
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Building an s390 linux allmodconfig kernel produced an error message for a
misoptimized code path:

pblk-rb.i:...: error: invalid operand for inline asm constraint 'i'

I managed to reduce the test case and make it architecture independent, test
with "clang-9 pblk-rb.i -Wall -O2 -S":

typedef struct { long counter; } atomic64_t;
static inline void __atomic64_add_const(long val, long *ptr)
{
        asm volatile (" agsi     %[ptr],%[val]"
                        :[ptr] "+Q"(*ptr)
                        :[val] "i"(val)
                        :"cc", "memory");
}
void __atomic64_add_var(long val, long *ptr);
static inline void atomic64_add(long i, atomic64_t * v)
{
        if (__builtin_constant_p(i) && (i > -129) && (i < 128))
                __atomic64_add_const(i, &v->counter);
        else
                __atomic64_add_var(i, &v->counter);
}
void pblk_rb_read_to_bio(atomic64_t *pblk, int count)
{
        if (count)
                atomic64_add(count, pblk);
        atomic64_add(count, pblk);
}

The __builtin_constant_p() should never hit here, since 'count' is clearly not
constant. If a special case is made for 'count=0', then I would expect 'val' to
be 0 in that branch and fit into an "i" constraint.

-- 
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/20190410/2b2b4196/attachment.html>


More information about the llvm-bugs mailing list