Re: [PATCH] Fix 67064 - Register asm variable broken

2015-10-19 Thread Jason Merrill

On 09/22/2015 06:03 AM, Jason Merrill wrote:

A simple fix would be to just disable the reference games when we're
looking at a hard register variable.  That would break decltype(auto)
for hard register variables, but since they are a GNU extension that
isn't a big deal.


Like so.

Tested x86_64-pc-linux-gnu, applying to trunk.


commit a5e9d513231728c3c52d956311fb9e5f06097184
Author: Jason Merrill 
Date:   Thu Jul 30 14:55:57 2015 -0400

	PR c++/67064

	* semantics.c (force_paren_expr): Don't mess with hard register vars.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 8796b17..c0a8b32 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -1660,6 +1660,8 @@ force_paren_expr (tree expr)
 REF_PARENTHESIZED_P (expr) = true;
   else if (type_dependent_expression_p (expr))
 expr = build1 (PAREN_EXPR, TREE_TYPE (expr), expr);
+  else if (VAR_P (expr) && DECL_HARD_REGISTER (expr))
+/* We can't bind a hard register variable to a reference.  */;
   else
 {
   cp_lvalue_kind kind = lvalue_kind (expr);
diff --git a/gcc/testsuite/g++.dg/parse/parens3.C b/gcc/testsuite/g++.dg/parse/parens3.C
new file mode 100644
index 000..afb392b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/parens3.C
@@ -0,0 +1,18 @@
+// PR c++/67064
+// { dg-options "-w" }
+
+struct s {
+  int i;
+};
+
+register struct s *reg __asm__( "1" );
+
+int f(void)
+{
+  int i;
+
+  i = reg->i;
+  i = (reg)->i;
+
+  return i;
+}


Re: [PATCH] Fix 67064 - Register asm variable broken

2015-09-22 Thread Jason Merrill

On 09/22/2015 11:49 AM, Jason Merrill wrote:

On 09/16/2015 10:24 AM, Andres Tiraboschi wrote:

Hi, this patch fix the following bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67064 for gcc 5.2

It passes all the gcc tests except for this:
FAIL: g++.dg/cpp1y/auto-fn15.C  -std=gnu++14 (test for excess errors)


Yep.  The test is verifying that decltype(auto) functions handle
parentheses properly, and the patch disables the code for that handling.


but this also happens without the patch.


The test passes for me without this patch.


A simple fix would be to just disable the reference games when we're 
looking at a hard register variable.  That would break decltype(auto) 
for hard register variables, but since they are a GNU extension that 
isn't a big deal.


Jason



Re: [PATCH] Fix 67064 - Register asm variable broken

2015-09-22 Thread Jason Merrill

On 09/16/2015 10:24 AM, Andres Tiraboschi wrote:

Hi, this patch fix the following bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67064 for gcc 5.2

It passes all the gcc tests except for this:
FAIL: g++.dg/cpp1y/auto-fn15.C  -std=gnu++14 (test for excess errors)


Yep.  The test is verifying that decltype(auto) functions handle 
parentheses properly, and the patch disables the code for that handling.



but this also happens without the patch.


The test passes for me without this patch.

Jason



[PATCH] Fix 67064 - Register asm variable broken

2015-09-16 Thread Andres Tiraboschi
Hi, this patch fix the following bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67064 for gcc 5.2

It passes all the gcc tests except for this:
FAIL: g++.dg/cpp1y/auto-fn15.C  -std=gnu++14 (test for excess errors)

but this also happens without the patch.

This patch was implemented for gcc 5.2

changelog:


diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 949225b..62b8c2a 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -5131,8 +5131,6 @@ build_conditional_expr_1 (location_t loc, tree
arg1, tree arg2, tree arg3,
  lvalue, we must add a NON_LVALUE_EXPR.  */
   result = rvalue (result);
 }
-  else
-result = force_paren_expr (result);

   return result;
 }
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 4e525e0..1f802b0 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5933,7 +5933,6 @@ extern tree finish_asm_stmt(int,
tree, tree, tree, tree,
 extern tree finish_label_stmt(tree);
 extern void finish_label_decl(tree);
 extern tree finish_parenthesized_expr(tree);
-extern tree force_paren_expr(tree);
 extern tree finish_non_static_data_member   (tree, tree, tree);
 extern tree begin_stmt_expr(void);
 extern tree finish_stmt_expr_expr(tree, tree);
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 82ef642..005262d 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -1642,26 +1642,9 @@ finish_mem_initializers (tree mem_inits)
 emit_mem_initializers (mem_inits);
 }

-/* Obfuscate EXPR if it looks like an id-expression or member access so
-   that the call to finish_decltype in do_auto_deduction will give the
-   right result.  */
-
-tree
-force_paren_expr (tree expr)
+static void
+check_paren_expr(tree expr)
 {
-  /* This is only needed for decltype(auto) in C++14.  */
-  if (cxx_dialect < cxx14)
-return expr;
-
-  /* If we're in unevaluated context, we can't be deducing a
- return/initializer type, so we don't need to mess with this.  */
-  if (cp_unevaluated_operand)
-return expr;
-
-  if (!DECL_P (expr) && TREE_CODE (expr) != COMPONENT_REF
-  && TREE_CODE (expr) != SCOPE_REF)
-return expr;
-
   if (TREE_CODE (expr) == COMPONENT_REF)
 REF_PARENTHESIZED_P (expr) = true;
   else if (type_dependent_expression_p (expr))
@@ -1672,7 +1655,7 @@ force_paren_expr (tree expr)
   if ((kind & ~clk_class) != clk_none)
 {
   tree type = unlowered_expr_type (expr);
-  bool rval = !!(kind & clk_rvalueref);
+  bool rval = (kind & clk_rvalueref);
   type = cp_build_reference_type (type, rval);
   /* This inhibits warnings in, eg, cxx_mark_addressable
  (c++/60955).  */
@@ -1682,10 +1665,7 @@ force_paren_expr (tree expr)
 REF_PARENTHESIZED_P (expr) = true;
 }
 }
-
-  return expr;
 }
-
 /* Finish a parenthesized expression EXPR.  */

 tree
@@ -1704,8 +1684,6 @@ finish_parenthesized_expr (tree expr)
   if (TREE_CODE (expr) == STRING_CST)
 PAREN_STRING_LITERAL_P (expr) = 1;

-  expr = force_paren_expr (expr);
-
   return expr;
 }

@@ -7369,7 +7347,10 @@ finish_decltype_type (tree expr, bool
id_expression_or_member_access_p,
 type = strip_typedefs (type);

   if (clk != clk_none && !(clk & clk_class))
+  {
+check_paren_expr(expr);
 type = cp_build_reference_type (type, (clk & clk_rvalueref));
+  }
 }
 }