<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Clang should issue diagnostics for use of __sync_fetch_and_*() with (invalid) const-qualified pointer arguments"
   href="https://llvm.org/bugs/show_bug.cgi?id=30545">30545</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang should issue diagnostics for use of __sync_fetch_and_*() with (invalid) const-qualified pointer arguments
          </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>normal
          </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>srhines@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>chh@google.com, llvm-bugs@lists.llvm.org, pirama@google.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Builtin functions like __sync_fetch_and_add() currently don't issue diagnostics
for passing in const-qualified arguments for the part to be modified. For
example, the following sequence compiles without warnings/errors:


static const int i = 4;

void foo() {
  __sync_fetch_and_add(&i, 5);
}


My suspicion is that Clang ignores the const qualifier, while needing to
support the volatile qualifier, as most people writing atomic code like this
are going to declare the variable volatile. It is likely that there are other
builtins with similar const problems, but at least initially, Clang should be
able to properly diagnose this issue for:

__sync_fetch_and_add
__sync_fetch_and_sub
__sync_fetch_and_or
__sync_fetch_and_and
__sync_fetch_and_xor
__sync_fetch_and_nand

__sync_add_and_fetch
__sync_sub_and_fetch
__sync_or_and_fetch
__sync_and_and_fetch
__sync_xor_and_fetch
__sync_nand_and_fetch

__sync_bool_compare_and_swap
__sync_val_compare_and_swap

__sync_lock_test_and_set
__sync_lock_release

__sync_swap

__sync_fetch_and_min
__sync_fetch_and_max
__sync_fetch_and_umin
__sync_fetch_and_umax

Note that many of these have 1/2/4/8/16 variants for operating on several
values at once.</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>