Re: Properly handle C2x attributes on types

2019-12-07 Thread Jeff Law
On Wed, 2019-11-27 at 12:23 +0100, Rainer Orth wrote:
> Hi Joseph,
> 
> > On Mon, 25 Nov 2019, Rainer Orth wrote:
> > 
> > > it seems you missed updating a couple of testcases that are ia32-
> > > only:
> > 
> > I think it's unavoidable that such target-specific testcases need
> > updating 
> > by someone testing on the target in question.
> 
> like so?  Tested on i386-pc-solaris2.11.
> 
>   Rainer
> 
> 2019-11-26  Rainer Orth  
> 
> * g++.dg/cpp0x/gen-attrs-36.C: Update expected diagnostics.
> * g++.dg/cpp0x/gen-attrs-37.C: Likewise.
> * g++.dg/cpp0x/gen-attrs-8.C: Likewise.
OK
jeff



Re: Properly handle C2x attributes on types

2019-11-27 Thread Rainer Orth
Hi Joseph,

> On Mon, 25 Nov 2019, Rainer Orth wrote:
>
>> it seems you missed updating a couple of testcases that are ia32-only:
>
> I think it's unavoidable that such target-specific testcases need updating 
> by someone testing on the target in question.

like so?  Tested on i386-pc-solaris2.11.

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


2019-11-26  Rainer Orth  

* g++.dg/cpp0x/gen-attrs-36.C: Update expected diagnostics.
* g++.dg/cpp0x/gen-attrs-37.C: Likewise.
* g++.dg/cpp0x/gen-attrs-8.C: Likewise.

# HG changeset patch
# Parent  f266edd7bbd4f5485b25b37a46b4a89bc83eecec
Fix ia32 testsuite failures from C2x attributes on types

diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-36.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-36.C
--- a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-36.C
+++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-36.C
@@ -9,16 +9,16 @@ class T;
 class L { };
 class P : public L
 {
-  typedef void (T::* [[gnu::__stdcall__]] F2) (L*); // { dg-warning "ignored" }
-  typedef void (T::*F) (L*) [[gnu::__stdcall__]]; // { dg-warning "ignored" }
+  typedef void (T::* [[gnu::__stdcall__]] F2) (L*); // { dg-warning "only applies to function types" }
+  typedef void (T::*F) (L*) [[gnu::__stdcall__]];
   void f(bool aAdd);
 };
 
 class T
 {
 public:
-  virtual void  A(L *listener) [[gnu::__stdcall__]] = 0; // { dg-warning "ignored" }
-  virtual void R(L *listener)  [[gnu::__stdcall__]] = 0; // { dg-warning "ignored" }
+  virtual void  A(L *listener) [[gnu::__stdcall__]] = 0;
+  virtual void R(L *listener)  [[gnu::__stdcall__]] = 0;
 };
 void P::f(bool aAdd)
 {
diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-37.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-37.C
--- a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-37.C
+++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-37.C
@@ -10,7 +10,7 @@ struct S {
   S(const S ) {}
 };
 
-S getS() [[gnu::__stdcall__]];  // { dg-warning "ignored" }
+S getS() [[gnu::__stdcall__]];
 
 void test()
 {
diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-8.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-8.C
--- a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-8.C
+++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-8.C
@@ -3,5 +3,5 @@
 // { dg-require-effective-target c++11 }
 
 extern int * ([[gnu::stdcall]] *fooPtr)( void); // { dg-error "expected" }
-int * [[gnu::stdcall]] myFn01( void) { return 0; }// { dg-warning "ignored" }
+int * [[gnu::stdcall]] myFn01( void) { return 0; }// { dg-warning "only applies to function types" }
 


Re: Properly handle C2x attributes on types

2019-11-25 Thread Joseph Myers
On Mon, 25 Nov 2019, Rainer Orth wrote:

> it seems you missed updating a couple of testcases that are ia32-only:

I think it's unavoidable that such target-specific testcases need updating 
by someone testing on the target in question.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: Properly handle C2x attributes on types

2019-11-25 Thread Rainer Orth
Hi Joseph,

> attribs.c has code to ignore all scoped attributes appertaining to
> types except when they are part of the definition of that type.
>
> I think the premise of that code is incorrect, and its presence is a
> bug; such attributes are clearly valid in both C and C++, which
> explicitly specify that attributes in certain syntactic positions
> appertain to a particular type, only for that use of that type and not
> for other uses of the same type specifiers without that attribute
> specified, and while the standard attributes in C2x aren't relevant in
> such contexts, some gnu:: attributes certainly are.  Where some
> attributes are invalid on some types in such contexts, that's a matter
> for the individual attribute handlers to diagnose (or the front end if
> the requirements on a standard attribute in the standard are more
> strict than those of a handler shared with a GNU attribute).
>
> Thus, this patch removes the bogus code to allow such attributes to be
> used.  Doing so (and adding tests for attributes in such positions)
> shows up that the logic in the C front end for creating the
> c_declarator structures for such attributes put them in the wrong
> place relative to the structures for function and array types, and the
> logic for postfix attributes on a list of declaration specifiers
> failed to handle some cases, so those bugs are also fixed in this
> patch.
>
> Bootstrapped with no regressions for x86_64-pc-linux-gnu.  OK to commit 
> (attribs.c and C++ testsuite changes)?

it seems you missed updating a couple of testcases that are ia32-only:

+FAIL: g++.dg/cpp0x/gen-attrs-36.C  -std=gnu++14  (test for warnings, line 12)
+FAIL: g++.dg/cpp0x/gen-attrs-36.C  -std=gnu++14  (test for warnings, line 13)
+FAIL: g++.dg/cpp0x/gen-attrs-36.C  -std=gnu++14  (test for warnings, line 20)
+FAIL: g++.dg/cpp0x/gen-attrs-36.C  -std=gnu++14  (test for warnings, line 21)
+FAIL: g++.dg/cpp0x/gen-attrs-36.C  -std=gnu++14 (test for excess errors)

Excess errors:
/vol/gcc/src/hg/trunk/local/gcc/testsuite/g++.dg/cpp0x/gen-attrs-36.C:12:50: 
warning: 'stdcall' attribute only applies to function types [-Wattributes]

+FAIL: g++.dg/cpp0x/gen-attrs-36.C  -std=gnu++17  (test for warnings, line 12)
+FAIL: g++.dg/cpp0x/gen-attrs-36.C  -std=gnu++17  (test for warnings, line 13)
+FAIL: g++.dg/cpp0x/gen-attrs-36.C  -std=gnu++17  (test for warnings, line 20)
+FAIL: g++.dg/cpp0x/gen-attrs-36.C  -std=gnu++17  (test for warnings, line 21)
+FAIL: g++.dg/cpp0x/gen-attrs-36.C  -std=gnu++17 (test for excess errors)
+FAIL: g++.dg/cpp0x/gen-attrs-36.C  -std=gnu++2a  (test for warnings, line 12)
+FAIL: g++.dg/cpp0x/gen-attrs-36.C  -std=gnu++2a  (test for warnings, line 13)
+FAIL: g++.dg/cpp0x/gen-attrs-36.C  -std=gnu++2a  (test for warnings, line 20)
+FAIL: g++.dg/cpp0x/gen-attrs-36.C  -std=gnu++2a  (test for warnings, line 21)
+FAIL: g++.dg/cpp0x/gen-attrs-36.C  -std=gnu++2a (test for excess errors)
+FAIL: g++.dg/cpp0x/gen-attrs-37.C  -std=gnu++14  (test for warnings, line 13)
+FAIL: g++.dg/cpp0x/gen-attrs-37.C  -std=gnu++17  (test for warnings, line 13)
+FAIL: g++.dg/cpp0x/gen-attrs-37.C  -std=gnu++2a  (test for warnings, line 13)
+FAIL: g++.dg/cpp0x/gen-attrs-8.C  -std=gnu++14  (test for warnings, line 6)
+FAIL: g++.dg/cpp0x/gen-attrs-8.C  -std=gnu++14 (test for excess errors)
+FAIL: g++.dg/cpp0x/gen-attrs-8.C  -std=gnu++17  (test for warnings, line 6)
+FAIL: g++.dg/cpp0x/gen-attrs-8.C  -std=gnu++17 (test for excess errors)
+FAIL: g++.dg/cpp0x/gen-attrs-8.C  -std=gnu++2a  (test for warnings, line 6)
+FAIL: g++.dg/cpp0x/gen-attrs-8.C  -std=gnu++2a (test for excess errors)

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


Re: Properly handle C2x attributes on types

2019-11-23 Thread Jeff Law
On 11/21/19 7:42 PM, Joseph Myers wrote:
> attribs.c has code to ignore all scoped attributes appertaining to
> types except when they are part of the definition of that type.
> 
> I think the premise of that code is incorrect, and its presence is a
> bug; such attributes are clearly valid in both C and C++, which
> explicitly specify that attributes in certain syntactic positions
> appertain to a particular type, only for that use of that type and not
> for other uses of the same type specifiers without that attribute
> specified, and while the standard attributes in C2x aren't relevant in
> such contexts, some gnu:: attributes certainly are.  Where some
> attributes are invalid on some types in such contexts, that's a matter
> for the individual attribute handlers to diagnose (or the front end if
> the requirements on a standard attribute in the standard are more
> strict than those of a handler shared with a GNU attribute).
> 
> Thus, this patch removes the bogus code to allow such attributes to be
> used.  Doing so (and adding tests for attributes in such positions)
> shows up that the logic in the C front end for creating the
> c_declarator structures for such attributes put them in the wrong
> place relative to the structures for function and array types, and the
> logic for postfix attributes on a list of declaration specifiers
> failed to handle some cases, so those bugs are also fixed in this
> patch.
> 
> Bootstrapped with no regressions for x86_64-pc-linux-gnu.  OK to commit 
> (attribs.c and C++ testsuite changes)?
> 
> gcc:
> 2019-11-22  Joseph Myers  
> 
>   * attribs.c (decl_attributes): Do not ignore C++11 attributes on
>   types.
> 
> gcc/c:
> 2019-11-22  Joseph Myers  
> 
>   * c-tree.h (struct c_declarator): Use a structure for id member.
>   * c-decl.c (grokdeclarator): Extract attributes from cdk_id
>   declarators at the start, not when handling individual declarators
>   later.  Use u.id.id instead of u.id.
>   (grokfield): Use u.id.id instead of u.id.
>   (build_id_declarator): Set u.id.id and u.id.attrs.
>   (finish_declspecs): Handle postfix attributes in case of typedef
>   name or typeof used.
>   * c-parser.c (c_parser_direct_declarator)
>   (c_parser_direct_declarator_inner): Place declarator for
>   attributes inside that for function or array, not outside.  Set
>   u.id.attrs for identifiers.
>   (c_parser_parameter_declaration): Use u.id.id instead of u.id.
>   * gimple-parser.c (c_parser_gimple_declaration): Use u.id.id
>   instead of u.id.
> 
> gcc/testsuite:
> 2019-11-22  Joseph Myers  
> 
>   * gcc.dg/gnu2x-attrs-1.c: Do not expect message about attributes
>   appertaining to types.
>   * gcc.dg/gnu2x-attrs-2.c: New test.
>   * g++.dg/cpp0x/gen-attrs-1.C, g++.dg/cpp0x/gen-attrs-22.C,
>   g++.dg/cpp0x/gen-attrs-4.C, g++.dg/cpp0x/lambda/lambda-attr1.C:
>   Update expected diagnostics.
OK
jeff



Properly handle C2x attributes on types

2019-11-21 Thread Joseph Myers
attribs.c has code to ignore all scoped attributes appertaining to
types except when they are part of the definition of that type.

I think the premise of that code is incorrect, and its presence is a
bug; such attributes are clearly valid in both C and C++, which
explicitly specify that attributes in certain syntactic positions
appertain to a particular type, only for that use of that type and not
for other uses of the same type specifiers without that attribute
specified, and while the standard attributes in C2x aren't relevant in
such contexts, some gnu:: attributes certainly are.  Where some
attributes are invalid on some types in such contexts, that's a matter
for the individual attribute handlers to diagnose (or the front end if
the requirements on a standard attribute in the standard are more
strict than those of a handler shared with a GNU attribute).

Thus, this patch removes the bogus code to allow such attributes to be
used.  Doing so (and adding tests for attributes in such positions)
shows up that the logic in the C front end for creating the
c_declarator structures for such attributes put them in the wrong
place relative to the structures for function and array types, and the
logic for postfix attributes on a list of declaration specifiers
failed to handle some cases, so those bugs are also fixed in this
patch.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.  OK to commit 
(attribs.c and C++ testsuite changes)?

gcc:
2019-11-22  Joseph Myers  

* attribs.c (decl_attributes): Do not ignore C++11 attributes on
types.

gcc/c:
2019-11-22  Joseph Myers  

* c-tree.h (struct c_declarator): Use a structure for id member.
* c-decl.c (grokdeclarator): Extract attributes from cdk_id
declarators at the start, not when handling individual declarators
later.  Use u.id.id instead of u.id.
(grokfield): Use u.id.id instead of u.id.
(build_id_declarator): Set u.id.id and u.id.attrs.
(finish_declspecs): Handle postfix attributes in case of typedef
name or typeof used.
* c-parser.c (c_parser_direct_declarator)
(c_parser_direct_declarator_inner): Place declarator for
attributes inside that for function or array, not outside.  Set
u.id.attrs for identifiers.
(c_parser_parameter_declaration): Use u.id.id instead of u.id.
* gimple-parser.c (c_parser_gimple_declaration): Use u.id.id
instead of u.id.

gcc/testsuite:
2019-11-22  Joseph Myers  

* gcc.dg/gnu2x-attrs-1.c: Do not expect message about attributes
appertaining to types.
* gcc.dg/gnu2x-attrs-2.c: New test.
* g++.dg/cpp0x/gen-attrs-1.C, g++.dg/cpp0x/gen-attrs-22.C,
g++.dg/cpp0x/gen-attrs-4.C, g++.dg/cpp0x/lambda/lambda-attr1.C:
Update expected diagnostics.

Index: gcc/attribs.c
===
--- gcc/attribs.c   (revision 278604)
+++ gcc/attribs.c   (working copy)
@@ -583,21 +583,6 @@ decl_attributes (tree *node, tree attributes, int
}
   gcc_assert (is_attribute_p (spec->name, name));
 
-  if (TYPE_P (*node)
- && cxx11_attr_p
- && !(flags & ATTR_FLAG_TYPE_IN_PLACE))
-   {
- /* This is a c++11 attribute that appertains to a
-type-specifier, outside of the definition of, a class
-type.  Ignore it.  */
- auto_diagnostic_group d;
- if (warning (OPT_Wattributes, "attribute ignored"))
-   inform (input_location,
-   "an attribute that appertains to a type-specifier "
-   "is ignored");
- continue;
-   }
-
   if (spec->decl_required && !DECL_P (*anode))
{
  if (flags & ((int) ATTR_FLAG_DECL_NEXT
Index: gcc/c/c-decl.c
===
--- gcc/c/c-decl.c  (revision 278604)
+++ gcc/c/c-decl.c  (working copy)
@@ -5951,6 +5951,7 @@ grokdeclarator (const struct c_declarator *declara
   bool array_parm_static = false;
   bool array_parm_vla_unspec_p = false;
   tree returned_attrs = NULL_TREE;
+  tree decl_id_attrs = NULL_TREE;
   bool bitfield = width != NULL;
   tree element_type;
   tree orig_qual_type = NULL;
@@ -6013,8 +6014,9 @@ grokdeclarator (const struct c_declarator *declara
 
case cdk_id:
  loc = decl->id_loc;
- if (decl->u.id)
-   name = decl->u.id;
+ if (decl->u.id.id)
+   name = decl->u.id.id;
+ decl_id_attrs = decl->u.id.attrs;
  if (first_non_attr_kind == cdk_attrs)
first_non_attr_kind = decl->kind;
  decl = 0;
@@ -6300,7 +6302,9 @@ grokdeclarator (const struct c_declarator *declara
   Standard attributes applied to a function or array
   declarator apply exactly to that type; standard
   attributes applied to the identifier apply to the
-  declaration rather than