Patchwork [C++] Fix cplus_decl_attributes (PR c++/54988)

login
register
mail settings
Submitter Jakub Jelinek
Date Oct. 22, 2012, 7:25 p.m.
Message ID <20121022192544.GF1752@tucnak.redhat.com>
Download mbox | patch
Permalink /patch/193265/
State New
Headers show

Comments

Jakub Jelinek - Oct. 22, 2012, 7:25 p.m.
Hi!

cplus_decl_attributes assumes that if attributes is NULL, there is nothing
to do in decl_attributes, unfortunately that call can add implicit
attributes based on currently active pragmas, at least for FUNCTION_DECLs.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2012-10-22  Jakub Jelinek  <jakub@redhat.com>

	PR c++/54988
	* decl2.c (cplus_decl_attributes): Don't return early
	if attributes is NULL.

	* c-c++-common/pr54988.c: New test.


	Jakub
Jason Merrill - Oct. 23, 2012, 4:38 p.m.
OK.

Jason
Jason Merrill - Nov. 6, 2012, 7:21 p.m.
Please add a comment.  OK with that change.

Jason

Patch

--- gcc/cp/decl2.c.jj	2012-10-08 21:37:27.000000000 +0200
+++ gcc/cp/decl2.c	2012-10-22 12:43:04.994700609 +0200
@@ -1309,8 +1309,7 @@  void
 cplus_decl_attributes (tree *decl, tree attributes, int flags)
 {
   if (*decl == NULL_TREE || *decl == void_type_node
-      || *decl == error_mark_node
-      || attributes == NULL_TREE)
+      || *decl == error_mark_node)
     return;
 
   if (processing_template_decl)
@@ -1319,8 +1318,6 @@  cplus_decl_attributes (tree *decl, tree
 	return;
 
       save_template_attributes (&attributes, decl);
-      if (attributes == NULL_TREE)
-	return;
     }
 
   cp_check_const_attributes (attributes);
--- gcc/testsuite/c-c++-common/pr54988.c.jj	2012-10-22 12:50:56.332853880 +0200
+++ gcc/testsuite/c-c++-common/pr54988.c	2012-10-22 12:50:04.000000000 +0200
@@ -0,0 +1,20 @@ 
+/* PR c++/54988 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-additional-options "-msse2" { target { i?86-*-* x86_64-*-* } } } */
+
+#if defined(__i386__) || defined(__x86_64__)
+#pragma GCC target "fpmath=sse"
+#endif
+
+static inline __attribute__ ((always_inline)) int
+foo (int x)
+{
+  return x;
+}
+
+int
+bar (int x)
+{
+  return foo (x);
+}