diff mbox

C++ PATCH for c++/70584 (parenthesized argument to x86 builtin)

Message ID 1d5430ea-4d5d-0fb1-aa11-695af802c472@redhat.com
State New
Headers show

Commit Message

Jason Merrill May 23, 2016, 6:58 p.m. UTC
The C++14 decltype(auto) obfuscation was confusing the x86 builtin; it's 
a simple matter to undo it during delayed folding, thanks to the 
maybe_undo_parenthesized_ref function that Patrick recently introduced.

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

Comments

Jason Merrill May 24, 2016, 8:54 p.m. UTC | #1
On 05/23/2016 02:58 PM, Jason Merrill wrote:
> The C++14 decltype(auto) obfuscation was confusing the x86 builtin; it's
> a simple matter to undo it during delayed folding, thanks to the
> maybe_undo_parenthesized_ref function that Patrick recently introduced.

But using cp_fold_maybe_rvalue here is wrong, as it will mean 
unconditionally replacing a variable with its initializer.  Better to 
use plain cp_fold and improve cp_fold_maybe_rvalue to handle getting a 
decl back from cp_fold.

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

Patch

commit d8cfb8653df9583386a9825809dfdfa5e8d99759
Author: Jason Merrill <jason@redhat.com>
Date:   Fri May 20 17:21:51 2016 -0400

    	PR c++/70584 - error with parenthesized builtin arg
    
    	* cp-gimplify.c (cp_fold) [INDIRECT_REF]: Call
    	maybe_undo_parenthesized_ref.

diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index aaa2db2..57f5d35 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -1996,6 +1996,15 @@  cp_fold (tree x)
 
       break;
 
+    case INDIRECT_REF:
+      /* We don't need the decltype(auto) obfuscation anymore.  */
+      if (REF_PARENTHESIZED_P (x))
+	{
+	  tree p = maybe_undo_parenthesized_ref (x);
+	  return cp_fold_maybe_rvalue (p, rval_ops);
+	}
+      goto unary;
+
     case ADDR_EXPR:
     case REALPART_EXPR:
     case IMAGPART_EXPR:
@@ -2008,7 +2017,7 @@  cp_fold (tree x)
     case BIT_NOT_EXPR:
     case TRUTH_NOT_EXPR:
     case FIXED_CONVERT_EXPR:
-    case INDIRECT_REF:
+    unary:
 
       loc = EXPR_LOCATION (x);
       op0 = cp_fold_maybe_rvalue (TREE_OPERAND (x, 0), rval_ops);
diff --git a/gcc/testsuite/g++.dg/other/i386-10.C b/gcc/testsuite/g++.dg/other/i386-10.C
new file mode 100644
index 0000000..96def72
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/i386-10.C
@@ -0,0 +1,12 @@ 
+// { dg-do compile { target i?86-*-* x86_64-*-* } }
+// { dg-options -maes }
+
+typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));
+
+int main()
+{
+    const char index = 1;
+    __m128i r = { };
+
+    r = __builtin_ia32_aeskeygenassist128 (r, (int)(index));
+}