aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorJonathan Wakely <redi@gcc.gnu.org>2015-09-17 16:46:04 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2015-09-17 16:46:04 +0100
commit310055e7b481eb86318dc75dcf67f4091e395757 (patch)
tree1f0c51ea5f77e0d267433e5aeeec1b8ac770b3b8 /gcc/builtins.c
parent308fbc42903ba2f97c29eea52928802686a917f1 (diff)
downloadgcc-310055e7b481eb86318dc75dcf67f4091e395757.zip
gcc-310055e7b481eb86318dc75dcf67f4091e395757.tar.gz
gcc-310055e7b481eb86318dc75dcf67f4091e395757.tar.bz2
Handle alignment in __atomic_is_lock_free
gcc: 2015-09-17 Richard Henderson <rth@redhat.com> PR libstdc++/65913 * builtins.c (fold_builtin_atomic_always_lock_free): Handle fake pointers that encode the alignment of the object. libstdc++-v3: 2015-09-17 Jonathan Wakely <jwakely@redhat.com> PR libstdc++/65913 * include/bits/atomic_base.h (__atomic_base<_TTp>::is_lock_free(), __atomic_base<_PTp*>::is_lock_free()): Call the built-in with the immediate pointer value, not a variable. * include/std/atomic (atomic<T>::is_lock_free()): Likewise. * testsuite/29_atomics/atomic/65913.cc: New. From-SVN: r227878
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index d79372c..aeec170 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -5635,8 +5635,20 @@ fold_builtin_atomic_always_lock_free (tree arg0, tree arg1)
mode = mode_for_size (size, MODE_INT, 0);
mode_align = GET_MODE_ALIGNMENT (mode);
- if (TREE_CODE (arg1) == INTEGER_CST && INTVAL (expand_normal (arg1)) == 0)
- type_align = mode_align;
+ if (TREE_CODE (arg1) == INTEGER_CST)
+ {
+ unsigned HOST_WIDE_INT val = UINTVAL (expand_normal (arg1));
+
+ /* Either this argument is null, or it's a fake pointer encoding
+ the alignment of the object. */
+ val = val & -val;
+ val *= BITS_PER_UNIT;
+
+ if (val == 0 || mode_align < val)
+ type_align = mode_align;
+ else
+ type_align = val;
+ }
else
{
tree ttype = TREE_TYPE (arg1);