* [PATCH v2] typeof: Remove type qualifiers for atomic types
@ 2014-06-26 7:42 Sebastian Huber
2014-06-26 15:52 ` Joseph S. Myers
0 siblings, 1 reply; 6+ messages in thread
From: Sebastian Huber @ 2014-06-26 7:42 UTC (permalink / raw)
To: gcc-patches; +Cc: joseph, Sebastian Huber
GCC provides its own version of stdatomic.h since GCC 4.9. Here we
have:
#define atomic_load_explicit(PTR, MO) \
__extension__ \
({ \
__auto_type __atomic_load_ptr = (PTR); \
__typeof__ (*__atomic_load_ptr) __atomic_load_tmp; \
__atomic_load (__atomic_load_ptr, &__atomic_load_tmp, (MO)); \
__atomic_load_tmp; \
})
According to
http://en.cppreference.com/w/c/atomic/atomic_load
(or in the standard "7.17.7.2 The atomic_load generic functions") we
have
C atomic_load_explicit( volatile A* obj, memory_order order );
This test case
#include <stdatomic.h>
int ld(volatile atomic_int *i)
{
return atomic_load_explicit(i, memory_order_relaxed);
}
yields on ARM
arm-rtems4.11-gcc -march=armv7-a -O2 test.c -S && cat test.s
.arch armv7-a
.fpu softvfp
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 1
.eabi_attribute 30, 2
.eabi_attribute 34, 1
.eabi_attribute 18, 4
.file "test.c"
.text
.align 2
.global ld
.type ld, %function
ld:
@ args = 0, pretend = 0, frame = 8
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
ldr r3, [r0]
sub sp, sp, #8
str r3, [sp, #4]
ldr r0, [sp, #4]
add sp, sp, #8
@ sp needed
bx lr
.size ld, .-ld
.ident "GCC: (GNU) 4.9.1 20140515 (prerelease)
To solve this performance issue discard all qualifiers in __typeof__ and
__auto_type for atomic types.
With this patch we have
rm-rtems4.11-gcc -march=armv7-a -O2 test.c -S && cat test.s
.arch armv7-a
.fpu softvfp
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 1
.eabi_attribute 30, 2
.eabi_attribute 34, 1
.eabi_attribute 18, 4
.file "test.c"
.text
.align 2
.global ld
.type ld, %function
ld:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
ldr r0, [r0]
bx lr
.size ld, .-ld
.ident "GCC: (GNU) 4.9.1 20140625 (prerelease)
gcc/c/ChangeLog
2014-06-26 Sebastian Huber <sebastian.huber@embedded-brains.de>
* c-parser.c (c_parser_declaration_or_fndef): Discard all type
qualifiers in __auto_type for atomic types.
(c_parser_typeof_specifier): Discard all type qualifiers in
__typeof__ for atomic types.
gcc/testsuite/ChangeLog
2014-06-26 Sebastian Huber <sebastian.huber@embedded-brains.de>
* gcc.dg/typeof-2.c: New testcase.
---
gcc/c/c-parser.c | 21 ++++++---------------
gcc/testsuite/gcc.dg/typeof-2.c | 28 ++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 15 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/typeof-2.c
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 99ff546..037da03 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -1707,14 +1707,10 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
" initializer");
init = convert_lvalue_to_rvalue (init_loc, init, true, true);
tree init_type = TREE_TYPE (init.value);
- /* As with typeof, remove _Atomic and const
- qualifiers from atomic types. */
+ /* As with typeof, remove all qualifiers from atomic types. */
if (init_type != error_mark_node && TYPE_ATOMIC (init_type))
init_type
- = c_build_qualified_type (init_type,
- (TYPE_QUALS (init_type)
- & ~(TYPE_QUAL_ATOMIC
- | TYPE_QUAL_CONST)));
+ = c_build_qualified_type (init_type, TYPE_UNQUALIFIED);
bool vm_type = variably_modified_type_p (init_type,
NULL_TREE);
if (vm_type)
@@ -3011,16 +3007,11 @@ c_parser_typeof_specifier (c_parser *parser)
if (was_vm)
ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands);
pop_maybe_used (was_vm);
- /* For use in macros such as those in <stdatomic.h>, remove
- _Atomic and const qualifiers from atomic types. (Possibly
- all qualifiers should be removed; const can be an issue for
- more macros using typeof than just the <stdatomic.h>
- ones.) */
+ /* For use in macros such as those in <stdatomic.h>, remove all
+ qualifiers from atomic types. (const can be an issue for more macros
+ using typeof than just the <stdatomic.h> ones.) */
if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec))
- ret.spec = c_build_qualified_type (ret.spec,
- (TYPE_QUALS (ret.spec)
- & ~(TYPE_QUAL_ATOMIC
- | TYPE_QUAL_CONST)));
+ ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED);
}
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
return ret;
diff --git a/gcc/testsuite/gcc.dg/typeof-2.c b/gcc/testsuite/gcc.dg/typeof-2.c
new file mode 100644
index 0000000..e916900
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/typeof-2.c
@@ -0,0 +1,28 @@
+/* Test qualifier discard of typeof for atomic types. */
+/* { dg-do compile } */
+/* { dg-options "-std=c11" } */
+
+extern int i;
+
+extern int * p;
+
+extern int _Atomic const ci;
+extern __typeof (ci) i;
+
+extern int _Atomic volatile vi;
+extern __typeof (vi) i;
+
+extern int * _Atomic restrict ri;
+extern __typeof (ri) p;
+
+void f(void)
+{
+ __auto_type aci = ci;
+ int *paci = &aci;
+
+ __auto_type avi = vi;
+ int *pavi = &avi;
+
+ __auto_type ari = ri;
+ int **pari = &ari;
+}
--
1.7.7
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] typeof: Remove type qualifiers for atomic types
2014-06-26 7:42 [PATCH v2] typeof: Remove type qualifiers for atomic types Sebastian Huber
@ 2014-06-26 15:52 ` Joseph S. Myers
2014-06-27 6:36 ` Sebastian Huber
0 siblings, 1 reply; 6+ messages in thread
From: Joseph S. Myers @ 2014-06-26 15:52 UTC (permalink / raw)
To: Sebastian Huber; +Cc: gcc-patches
On Thu, 26 Jun 2014, Sebastian Huber wrote:
> gcc/c/ChangeLog
> 2014-06-26 Sebastian Huber <sebastian.huber@embedded-brains.de>
>
> * c-parser.c (c_parser_declaration_or_fndef): Discard all type
> qualifiers in __auto_type for atomic types.
> (c_parser_typeof_specifier): Discard all type qualifiers in
> __typeof__ for atomic types.
>
> gcc/testsuite/ChangeLog
> 2014-06-26 Sebastian Huber <sebastian.huber@embedded-brains.de>
>
> * gcc.dg/typeof-2.c: New testcase.
OK.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] typeof: Remove type qualifiers for atomic types
2014-06-26 15:52 ` Joseph S. Myers
@ 2014-06-27 6:36 ` Sebastian Huber
2014-06-27 6:49 ` Marek Polacek
0 siblings, 1 reply; 6+ messages in thread
From: Sebastian Huber @ 2014-06-27 6:36 UTC (permalink / raw)
To: Joseph S. Myers; +Cc: gcc-patches
On 2014-06-26 17:51, Joseph S. Myers wrote:
> On Thu, 26 Jun 2014, Sebastian Huber wrote:
>
>> >gcc/c/ChangeLog
>> >2014-06-26 Sebastian Huber<sebastian.huber@embedded-brains.de>
>> >
>> > * c-parser.c (c_parser_declaration_or_fndef): Discard all type
>> > qualifiers in __auto_type for atomic types.
>> > (c_parser_typeof_specifier): Discard all type qualifiers in
>> > __typeof__ for atomic types.
>> >
>> >gcc/testsuite/ChangeLog
>> >2014-06-26 Sebastian Huber<sebastian.huber@embedded-brains.de>
>> >
>> > * gcc.dg/typeof-2.c: New testcase.
> OK.
Thanks for your patience. It would be nice if this can be applied to GCC 4.9
as well.
Can someone please commit this for me, since I don't have write access.
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] typeof: Remove type qualifiers for atomic types
2014-06-27 6:36 ` Sebastian Huber
@ 2014-06-27 6:49 ` Marek Polacek
2014-06-30 13:04 ` Marek Polacek
0 siblings, 1 reply; 6+ messages in thread
From: Marek Polacek @ 2014-06-27 6:49 UTC (permalink / raw)
To: Sebastian Huber; +Cc: Joseph S. Myers, gcc-patches
On Fri, Jun 27, 2014 at 08:36:38AM +0200, Sebastian Huber wrote:
> Thanks for your patience. It would be nice if this can be applied to GCC
> 4.9 as well.
>
> Can someone please commit this for me, since I don't have write access.
I will commit it for you.
Marek
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] typeof: Remove type qualifiers for atomic types
2014-06-27 6:49 ` Marek Polacek
@ 2014-06-30 13:04 ` Marek Polacek
2014-07-04 9:33 ` Sebastian Huber
0 siblings, 1 reply; 6+ messages in thread
From: Marek Polacek @ 2014-06-30 13:04 UTC (permalink / raw)
To: Sebastian Huber; +Cc: Joseph S. Myers, gcc-patches
On Fri, Jun 27, 2014 at 08:49:24AM +0200, Marek Polacek wrote:
> On Fri, Jun 27, 2014 at 08:36:38AM +0200, Sebastian Huber wrote:
> > Thanks for your patience. It would be nice if this can be applied to GCC
> > 4.9 as well.
> >
> > Can someone please commit this for me, since I don't have write access.
>
> I will commit it for you.
Now applied to 4.9 as well.
Marek
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] typeof: Remove type qualifiers for atomic types
2014-06-30 13:04 ` Marek Polacek
@ 2014-07-04 9:33 ` Sebastian Huber
0 siblings, 0 replies; 6+ messages in thread
From: Sebastian Huber @ 2014-07-04 9:33 UTC (permalink / raw)
To: gcc-patches
On 2014-06-30 15:03, Marek Polacek wrote:
> On Fri, Jun 27, 2014 at 08:49:24AM +0200, Marek Polacek wrote:
>> On Fri, Jun 27, 2014 at 08:36:38AM +0200, Sebastian Huber wrote:
>>> Thanks for your patience. It would be nice if this can be applied to GCC
>>> 4.9 as well.
>>>
>>> Can someone please commit this for me, since I don't have write access.
>>
>> I will commit it for you.
>
> Now applied to 4.9 as well.
>
> Marek
>
Should this __typeof and __auto_type behaviour for atomic types show up in the
documentation?
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-07-04 9:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-26 7:42 [PATCH v2] typeof: Remove type qualifiers for atomic types Sebastian Huber
2014-06-26 15:52 ` Joseph S. Myers
2014-06-27 6:36 ` Sebastian Huber
2014-06-27 6:49 ` Marek Polacek
2014-06-30 13:04 ` Marek Polacek
2014-07-04 9:33 ` Sebastian Huber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).