re PR c++/83059 (ICE on invalid C++ code: in tree_to_uhwi, at tree.c:6633)
[gcc.git] / gcc / c-family / c-common.c
index dfcfb1960285d0f9afd2d5313bbbe804ce4286a2..969f41bdd8cabc406b432c36efba7af73f857311 100644 (file)
@@ -376,6 +376,7 @@ const struct c_common_resword c_common_reswords[] =
   { "__builtin_complex", RID_BUILTIN_COMPLEX, D_CONLY },
   { "__builtin_launder", RID_BUILTIN_LAUNDER, D_CXXONLY },
   { "__builtin_shuffle", RID_BUILTIN_SHUFFLE, 0 },
+  { "__builtin_tgmath", RID_BUILTIN_TGMATH, D_CONLY },
   { "__builtin_offsetof", RID_OFFSETOF, 0 },
   { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, D_CONLY },
   { "__builtin_va_arg",        RID_VA_ARG,     0 },
@@ -2694,9 +2695,9 @@ binary_op_error (rich_location *richloc, enum tree_code code,
     default:
       gcc_unreachable ();
     }
-  error_at_rich_loc (richloc,
-                    "invalid operands to binary %s (have %qT and %qT)",
-                    opname, type0, type1);
+  error_at (richloc,
+           "invalid operands to binary %s (have %qT and %qT)",
+           opname, type0, type1);
 }
 \f
 /* Given an expression as a tree, return its original type.  Do this
@@ -5695,6 +5696,16 @@ check_builtin_function_arguments (location_t loc, vec<location_t> arg_loc,
 
   switch (DECL_FUNCTION_CODE (fndecl))
     {
+    case BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX:
+      if (!tree_fits_uhwi_p (args[2]))
+       {
+         error_at (ARG_LOCATION (2),
+                   "third argument to function %qE must be a constant integer",
+                   fndecl);
+         return false;
+       }
+      /* fall through */
+
     case BUILT_IN_ALLOCA_WITH_ALIGN:
       {
        /* Get the requested alignment (in bits) if it's a constant
@@ -5880,10 +5891,10 @@ check_builtin_function_arguments (location_t loc, vec<location_t> arg_loc,
 static char *
 catenate_strings (const char *lhs, const char *rhs_start, int rhs_size)
 {
-  const int lhs_size = strlen (lhs);
+  const size_t lhs_size = strlen (lhs);
   char *result = XNEWVEC (char, lhs_size + rhs_size);
-  strncpy (result, lhs, lhs_size);
-  strncpy (result + lhs_size, rhs_start, rhs_size);
+  memcpy (result, lhs, lhs_size);
+  memcpy (result + lhs_size, rhs_start, rhs_size);
   return result;
 }
 
@@ -5934,7 +5945,7 @@ c_parse_error (const char *gmsgid, enum cpp_ttype token_type,
       else
        message = catenate_messages (gmsgid, " before %s'\\x%x'");
 
-      error_at_rich_loc (richloc, message, prefix, val);
+      error_at (richloc, message, prefix, val);
       free (message);
       message = NULL;
     }
@@ -5962,7 +5973,7 @@ c_parse_error (const char *gmsgid, enum cpp_ttype token_type,
   else if (token_type == CPP_NAME)
     {
       message = catenate_messages (gmsgid, " before %qE");
-      error_at_rich_loc (richloc, message, value);
+      error_at (richloc, message, value);
       free (message);
       message = NULL;
     }
@@ -5975,16 +5986,16 @@ c_parse_error (const char *gmsgid, enum cpp_ttype token_type,
   else if (token_type < N_TTYPES)
     {
       message = catenate_messages (gmsgid, " before %qs token");
-      error_at_rich_loc (richloc, message, cpp_type2name (token_type, token_flags));
+      error_at (richloc, message, cpp_type2name (token_type, token_flags));
       free (message);
       message = NULL;
     }
   else
-    error_at_rich_loc (richloc, gmsgid);
+    error_at (richloc, gmsgid);
 
   if (message)
     {
-      error_at_rich_loc (richloc, message);
+      error_at (richloc, message);
       free (message);
     }
 #undef catenate_messages
@@ -6660,13 +6671,14 @@ get_atomic_generic_size (location_t loc, tree function,
       tree p = (*params)[x];
       if (TREE_CODE (p) == INTEGER_CST)
         {
-         int i = tree_to_uhwi (p);
-         if (i < 0 || (memmodel_base (i) >= MEMMODEL_LAST))
-           {
-             warning_at (loc, OPT_Winvalid_memory_model,
-                         "invalid memory model argument %d of %qE", x + 1,
-                         function);
-           }
+         /* memmodel_base masks the low 16 bits, thus ignore any bits above
+            it by using TREE_INT_CST_LOW instead of tree_to_*hwi.  Those high
+            bits will be checked later during expansion in target specific
+            way.  */
+         if (memmodel_base (TREE_INT_CST_LOW (p)) >= MEMMODEL_LAST)
+           warning_at (loc, OPT_Winvalid_memory_model,
+                       "invalid memory model argument %d of %qE", x + 1,
+                       function);
        }
       else
        if (!INTEGRAL_TYPE_P (TREE_TYPE (p)))