re PR target/82112 (internal compiler error: in fold_convert_loc, at fold-const.c...
[gcc.git] / gcc / config / rs6000 / rs6000-c.c
index fbab0a2543e2602d96f7242e0231df3bbb72fa08..d27f5635c82cd7c113fc5040a6c3a189cdd89773 100644 (file)
@@ -6489,7 +6489,13 @@ altivec_resolve_overloaded_builtin (location_t loc, tree fndecl,
 
       /* Strip qualifiers like "const" from the pointer arg.  */
       tree arg1_type = TREE_TYPE (arg1);
-      if (!POINTER_TYPE_P (arg1_type) && TREE_CODE (arg1_type) != ARRAY_TYPE)
+      if (TREE_CODE (arg1_type) == ARRAY_TYPE && c_dialect_cxx ())
+       {
+         /* Force array-to-pointer decay for C++.  */
+         arg1 = default_conversion (arg1);
+         arg1_type = TREE_TYPE (arg1);
+       }
+      if (!POINTER_TYPE_P (arg1_type))
        goto bad;
 
       tree inner_type = TREE_TYPE (arg1_type);
@@ -6509,15 +6515,6 @@ altivec_resolve_overloaded_builtin (location_t loc, tree fndecl,
          if (!ptrofftype_p (TREE_TYPE (arg0)))
            arg0 = build1 (NOP_EXPR, sizetype, arg0);
 
-         tree arg1_type = TREE_TYPE (arg1);
-         if (TREE_CODE (arg1_type) == ARRAY_TYPE)
-           {
-             arg1_type = TYPE_POINTER_TO (TREE_TYPE (arg1_type));
-             tree const0 = build_int_cstu (sizetype, 0);
-             tree arg1_elt0 = build_array_ref (loc, arg1, const0);
-             arg1 = build1 (ADDR_EXPR, arg1_type, arg1_elt0);
-           }
-
          tree addr = fold_build2_loc (loc, POINTER_PLUS_EXPR, arg1_type,
                                       arg1, arg0);
          tree aligned = fold_build2_loc (loc, BIT_AND_EXPR, arg1_type, addr,
@@ -6572,12 +6569,11 @@ altivec_resolve_overloaded_builtin (location_t loc, tree fndecl,
            arg1 = build1 (NOP_EXPR, sizetype, arg1);
 
          tree arg2_type = TREE_TYPE (arg2);
-         if (TREE_CODE (arg2_type) == ARRAY_TYPE)
+         if (TREE_CODE (arg2_type) == ARRAY_TYPE && c_dialect_cxx ())
            {
-             arg2_type = TYPE_POINTER_TO (TREE_TYPE (arg2_type));
-             tree const0 = build_int_cstu (sizetype, 0);
-             tree arg2_elt0 = build_array_ref (loc, arg2, const0);
-             arg2 = build1 (ADDR_EXPR, arg2_type, arg2_elt0);
+             /* Force array-to-pointer decay for C++.  */
+             arg2 = default_conversion (arg2);
+             arg2_type = TREE_TYPE (arg2);
            }
 
          /* Find the built-in to make sure a compatible one exists; if not