[llvm-bugs] [Bug 30545] New: Clang should issue diagnostics for use of __sync_fetch_and_*() with (invalid) const-qualified pointer arguments

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 27 14:54:58 PDT 2016


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

            Bug ID: 30545
           Summary: Clang should issue diagnostics for use of
                    __sync_fetch_and_*() with (invalid) const-qualified
                    pointer arguments
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: srhines at google.com
                CC: chh at google.com, llvm-bugs at lists.llvm.org,
                    pirama at google.com
    Classification: Unclassified

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.

-- 
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/20160927/8ed78c9f/attachment.html>


More information about the llvm-bugs mailing list