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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to