<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 - __builtin_constant_p() appears to return true for non-constant argument"
   href="https://bugs.llvm.org/show_bug.cgi?id=41459">41459</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>__builtin_constant_p() appears to return true for non-constant argument
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>arnd@linaro.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</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>