summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGen/atomic-ops.c
Commit message (Collapse)AuthorAgeFilesLines
* Atomics: support min/max orthogonallyTim Northover2019-11-211-0/+77
| | | | | | | | | | | | We seem to have been gradually growing support for atomic min/max operations (exposing longstanding IR atomicrmw instructions). But until now there have been gaps in the expected intrinsics. This adds support for the C11-style intrinsics (i.e. taking _Atomic, rather than individually blessed by C11 standard), and the variants that return the new value instead of the original one. That way, people won't be misled by trying one form and it not working, and the front-end is more friendly to people using _Atomic types, as we recommend.
* Do not use optimized atomic libcalls for misaligned atomics.Richard Smith2018-09-071-10/+37
| | | | | | | | | | | | | | | | | Summary: The optimized (__atomic_foo_<n>) libcalls assume that the atomic object is properly aligned, so should never be called on an underaligned object. This addresses one of several problems identified in PR38846. Reviewers: jyknight, t.p.northover Subscribers: jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D51817 llvm-svn: 341734
* Support implicit _Atomic struct load / storeJF Bastien2018-07-181-0/+12
| | | | | | | | | | | | | | | | | Summary: Using _Atomic to do implicit load / store is just a seq_cst atomic_load / atomic_store. Stores currently assert in Sema::ImpCastExprToType with 'can't implicitly cast lvalue to rvalue with this cast kind', but that's erroneous. The codegen is fine as the test shows. While investigating I found that Richard had found the problem here: https://reviews.llvm.org/D46112#1113557 <rdar://problem/40347123> Reviewers: dexonsmith Subscribers: cfe-commits, efriedma, rsmith, aaron.ballman Differential Revision: https://reviews.llvm.org/D49458 llvm-svn: 337410
* Generalize NRVO to cover C structs.Akira Hatanaka2018-03-291-2/+2
| | | | | | | | | | | This commit generalizes NRVO to cover C structs (both trivial and non-trivial structs). rdar://problem/33599681 Differential Revision: https://reviews.llvm.org/D44968 llvm-svn: 328809
* [OpenCL] Fix atomic Builtins check for address spaces of non-atomic pointerAnastasia Stulova2015-12-221-3/+11
| | | | | | | | | | | If there are two pointers passed to an atomic Builtin, Clang doesn't allow the second (non-atomic) one to be qualified with an address space. Remove this restriction by recording the address space of passed pointers in atomics type diagnostics. llvm-svn: 256243
* Atomics: support __c11_* calls on _Atomic struct types.Tim Northover2015-11-091-6/+12
| | | | | | | | | | | | | When a struct's size is not a power of 2, the corresponding _Atomic() type is promoted to the nearest. We already correctly handled normal C++ expressions of this form, but direct calls to the __c11_atomic_whatever builtins ended up performing dodgy operations on the smaller non-atomic types (e.g. memcpy too much). Later optimisations removed this as undefined behaviour. This patch converts EmitAtomicExpr to allocate its temporaries at the full atomic width, sidestepping the issue. llvm-svn: 252507
* Revert "Revert r241620 and follow-up commits" and move the initializationAdrian Prantl2015-07-081-0/+1
| | | | | | of the llvm targets from clang/CodeGen into ClangCheck.cpp and CIndex.cpp. llvm-svn: 241653
* Revert r241620 and follow-up commits while investigating linux buildbot ↵Adrian Prantl2015-07-071-1/+0
| | | | | | failures. llvm-svn: 241642
* Wrap clang modules and pch files in an object file container.Adrian Prantl2015-07-071-0/+1
| | | | | | | | | | | | | This patch adds ObjectFilePCHContainerOperations uses the LLVM backend to put the contents of a PCH into a __clangast section inside a COFF, ELF, or Mach-O object file container. This is done to facilitate module debugging by makeing it possible to store the debug info for the types defined by a module alongside the AST. rdar://problem/20091852 llvm-svn: 241620
* [Sema] Make the atomic builtins more efficient by reducing volatilityDavid Majnemer2015-06-031-0/+8
| | | | | | | | The parameter types and return type do not need to be volatile just because the pointer type's pointee type is volatile qualified. This is an unnecessary pessimization. llvm-svn: 238892
* Update Clang tests to handle explicitly typed load changes in LLVM.David Blaikie2015-02-271-27/+27
| | | | llvm-svn: 230795
* Revert "Wrap clang module files in a Mach-O, ELF, or COFF container."Adrian Prantl2015-02-251-1/+0
| | | | llvm-svn: 230454
* Wrap clang module files in a Mach-O, ELF, or COFF container.Adrian Prantl2015-02-251-0/+1
| | | | | | | | | | | | | | | | | This is a necessary prerequisite for debugging with modules. The .pcm files become containers that hold the serialized AST which allows us to store debug information in the module file that can be shared by all object files that were built importing the module. This reapplies r230044 with a fixed configure+make build and updated dependencies and testcase requirements. Over the last iteration this version adds - missing target requirements for testcases that specify an x86 triple, - a missing clangCodeGen.a dependency to libClang.a in the make build. rdar://problem/19104245 llvm-svn: 230423
* CodeGen: Loads/stores to allocas for atomic ops shouldn't be volatileDavid Majnemer2014-12-121-0/+32
| | | | | | | | | Don't inherit the volatile-ness of the input pointer to the volatile operation for memory allocated on the side. This fixes PR17306. llvm-svn: 224110
* CodeGen: Fix emission of __atomic_compare_exchangeDavid Majnemer2014-11-251-2/+11
| | | | | | We (wrongly) discarded the return value of the call. llvm-svn: 222798
* CodeGen: Make atomic operations play nice with address spacesDavid Majnemer2014-11-221-0/+15
| | | | | | | | We were being a little sloppy with our pointer/address space casts. This fixes PR21643. llvm-svn: 222615
* Make test/CodeGen/atomic-ops.c free-standingHal Finkel2014-10-031-3/+3
| | | | | | | | This test includes stdint.h (via stdatomic.h), which might include system headers (and that might not work, depending on the system configuration). Attempting to fix llvm-clang-lld-x86_64-debian-fast. llvm-svn: 218960
* Add an implementation of C11's stdatomic.hHal Finkel2014-10-031-8/+31
| | | | | | | | | | | | | | | | | | | | | | | | Adds a Clang-specific implementation of C11's stdatomic.h header. On systems, such as FreeBSD, where a stdatomic.h header is already provided, we defer to that header instead (using our __has_include_next technology). Otherwise, we provide an implementation in terms of our __c11_atomic_* intrinsics (that were created for this purpose). C11 7.1.4p1 requires function declarations for atomic_thread_fence, atomic_signal_fence, atomic_flag_test_and_set, atomic_flag_test_and_set_explicit, and atomic_flag_clear, and requires that they have external linkage. Accordingly, we provide these declarations, but if a user elides the shadowing macros and uses them, then they must have a libc (or similar) that actually provides definitions. atomic_flag is implemented using _Bool as the underlying type. This is consistent with the implementation provided by FreeBSD and also GCC 4.9 (at least when __GCC_ATOMIC_TEST_AND_SET_TRUEVAL == 1). Patch by Richard Smith (rebased and slightly edited by me -- Richard said I should drive at this point). llvm-svn: 218957
* CodeGen: Don't completely mess-up optimized atomic libcallsDavid Majnemer2014-08-291-0/+73
| | | | | | | | | | | | | | | | | | | | | | | Summary: We did a great job getting this wrong: - We messed up which LLVM IR types to use for arguments and return values. The optimized libcalls use integer types for values. Clang attempted to use the IR type which corresponds to the value passed in instead of using an appropriately sized integer type. This would result in violations of the ABI for, as an example, floating point types. - We didn't bother recording the result of the atomic libcall in the destination memory. Instead, call the functions with arguments matching the type of the libcall prototype's parameters. This fixes PR20780. Differential Revision: http://reviews.llvm.org/D5098 llvm-svn: 216714
* Fix test for release builds.Tim Northover2014-06-131-2/+2
| | | | llvm-svn: 210934
* Atomics: emit "cmpxchg weak" where possibleTim Northover2014-06-131-3/+44
| | | | | | | | | | | | | | | | | | Most builtins date from before the "cmpxchg weak" was a gleam in the C++ committee's eye, so fortunately not much needs to change. But a few of them *do* acknowledge that failure is possible. For these, we'll emit the usual cartesian product of cmpxchg operations if we can't statically determine weakness. CodeGen can sort it out later if the function gets inlined. The only other non-trivial aspect of this is (I think) that we emit the scalar expression for "IsWeak" once, at the beginning, and propagate its value through the successive blocks. There's not much in it, but it's slightly more consistent with the existing handling of FailureOrder. llvm-svn: 210932
* IR-change: cmpxchg operations now return { iN, i1 }.Tim Northover2014-06-131-6/+9
| | | | | | | | This is a minimal fix for clang. I'll soon add support for generating weak variants when requested, but that's not really necessary for the LLVM change in isolation. llvm-svn: 210907
* Tests: use CHECK-LABEL to help debugging failuresTim Northover2014-06-131-29/+29
| | | | llvm-svn: 210906
* CodeGen: make use of weaker failure orders on cmpxchg.Tim Northover2014-03-131-0/+88
| | | | | | | | | | | | This makes Clang take advantage of the recent IR addition of a "failure" memory ordering requirement. As with the "success" ordering, we try to emit just a single version if the expression is constant, but fall back to runtime detection (to allow optimisation across function-call boundaries). rdar://problem/15996804 llvm-svn: 203837
* Sema: produce error when invalid ordering is passed to atomic builtinTim Northover2014-03-111-9/+0
| | | | | | | | | This is a conservative check, because it's valid for the expression to be non-constant, and in cases like that we just don't know whether it's valid. rdar://problem/16242991 llvm-svn: 203561
* IRGen: __c11/__atomic compare-and-exchange should respect the standardDavid Majnemer2014-03-101-3/+12
| | | | | | | | | | | | | | | Summary: 'Expected' should only be modified if the operation fails. This fixes PR18899. Reviewers: chandlerc, rsmith, rjmccall CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D2922 llvm-svn: 203493
* Patch to issue error when target of MacOS and iOS Fariborz Jahanian2013-05-281-6/+1
| | | | | | | does not support large load/store of atomic objects. // rdar://13973577 llvm-svn: 182781
* Don't crash on bad atomic operations. PR14176.Eli Friedman2012-10-301-0/+9
| | | | llvm-svn: 166992
* Implement __atomic_fetch_nand and __atomic_nand_fetch to complete our set ofRichard Smith2012-04-131-0/+15
| | | | | | GNU __atomic builtins. llvm-svn: 154659
* Implement the missing pieces needed to support libstdc++4.7's <atomic>:Richard Smith2012-04-131-5/+51
| | | | | | | | | | | | | | | | | | | | | | | | __atomic_test_and_set, __atomic_clear, plus a pile of undocumented __GCC_* predefined macros. Implement library fallback for __atomic_is_lock_free and __c11_atomic_is_lock_free, and implement __atomic_always_lock_free. Contrary to their documentation, GCC's __atomic_fetch_add family don't multiply the operand by sizeof(T) when operating on a pointer type. libstdc++ relies on this quirk. Remove this handling for all but the __c11_atomic_fetch_add and __c11_atomic_fetch_sub builtins. Contrary to their documentation, __atomic_test_and_set and __atomic_clear take a first argument of type 'volatile void *', not 'void *' or 'bool *', and __atomic_is_lock_free and __atomic_always_lock_free have an argument of type 'const volatile void *', not 'void *'. With this change, libstdc++4.7's <atomic> passes libc++'s atomic test suite, except for a couple of libstdc++ bugs and some cases where libc++'s test suite tests for properties which implementations have latitude to vary. llvm-svn: 154640
* Implement support for 18 of the GNU-compatible __atomic builtins.Richard Smith2012-04-121-9/+134
| | | | | | | | | | | | This is not quite sufficient for libstdc++'s <atomic>: we still need __atomic_test_and_set and __atomic_clear, and may need a more complete __atomic_is_lock_free implementation. We are also missing an implementation of __atomic_always_lock_free, __atomic_nand_fetch, and __atomic_fetch_nand, but those aren't needed for libstdc++. llvm-svn: 154579
* Provide, and document, a set of __c11_atomic_* intrinsics to implement C11'sRichard Smith2012-04-111-18/+18
| | | | | | | | | <stdatomic.h> header. In passing, fix LanguageExtensions to note that C11 and C++11 are no longer "upcoming standards" but are now actually standardized. llvm-svn: 154513
* AtomicExpr: make ASTStmtReader a friend and remove setters. Also fix savingRichard Smith2012-04-101-0/+9
| | | | | | | of an uninitialized Stmt* in serialization of __atomic_init and add a test of atomics serialization. llvm-svn: 154448
* Relax the test slightly so that it should pass on other people's computers.David Chisnall2012-03-291-4/+4
| | | | llvm-svn: 153670
* Call out to GCC-compatible runtime functions for atomic ops that we can't useDavid Chisnall2012-03-291-0/+36
| | | | | | | | | | | | | | LLVM intrinsics for. I have an implementation of these functions, which wants to go in a libgcc_s equivalent in compiler-rt. It's currently here: http://people.freebsd.org/~theraven/atomic.c It will be committed to compiler-rt as soon as I work out where would be a sensible place to put it... llvm-svn: 153666
* Add missing newline.Eli Friedman2011-10-171-1/+1
| | | | llvm-svn: 142285
* Initial implementation of __atomic_is_lock_free. The input is the size of ↵Eli Friedman2011-10-171-0/+6
| | | | | | | | an atomic type rather than an atomic type itself just to save some implementation pain; I can change that if it seems worthwhile. I think this is the last hook needed for <atomic> besides defines for ATOMIC_CHAR_LOCK_FREE and friends. llvm-svn: 142281
* Misc fixes for atomics. Biggest fix is doing alignment correctly for ↵Eli Friedman2011-10-141-3/+1
| | | | | | _Atomic types. llvm-svn: 142002
* Initial implementation of __atomic_* (everything except __atomic_is_lock_free).Eli Friedman2011-10-111-0/+79
llvm-svn: 141632
OpenPOWER on IntegriCloud