diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 54c736b340be07cd070256abdcdc5001df1d4636..788ce54da7f982678e6829c1195760ff6c0b274f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,9 @@
 2019-03-05  Jakub Jelinek  <jakub@redhat.com>
 
+	PR bootstrap/89560
+	* fold-const.c (fold_checksum_tree): Don't use fixed size buffer,
+	instead alloca it only when needed with the needed size.
+
 	PR tree-optimization/89570
 	* match.pd (vec_cond into cond_op simplification): Guard with
 	vectorized_internal_fn_supported_p test and #if GIMPLE.
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 8989fc7827e7108b704e1749fc2736d6b0baa091..571566aa6bca91e20153d7bfa4d6cfcd897cd97b 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -12112,7 +12112,7 @@ fold_checksum_tree (const_tree expr, struct md5_ctx *ctx,
 {
   const tree_node **slot;
   enum tree_code code;
-  union tree_node buf;
+  union tree_node *buf;
   int i, len;
 
  recursive_label:
@@ -12127,11 +12127,13 @@ fold_checksum_tree (const_tree expr, struct md5_ctx *ctx,
       && HAS_DECL_ASSEMBLER_NAME_P (expr))
     {
       /* Allow DECL_ASSEMBLER_NAME and symtab_node to be modified.  */
-      memcpy ((char *) &buf, expr, tree_size (expr));
-      SET_DECL_ASSEMBLER_NAME ((tree)&buf, NULL);
-      buf.decl_with_vis.symtab_node = NULL;
-      buf.base.nowarning_flag = 0;
-      expr = (tree) &buf;
+      size_t sz = tree_size (expr);
+      buf = XALLOCAVAR (union tree_node, sz);
+      memcpy ((char *) buf, expr, sz);
+      SET_DECL_ASSEMBLER_NAME ((tree) buf, NULL);
+      buf->decl_with_vis.symtab_node = NULL;
+      buf->base.nowarning_flag = 0;
+      expr = (tree) buf;
     }
   else if (TREE_CODE_CLASS (code) == tcc_type
 	   && (TYPE_POINTER_TO (expr)
@@ -12143,8 +12145,10 @@ fold_checksum_tree (const_tree expr, struct md5_ctx *ctx,
     {
       /* Allow these fields to be modified.  */
       tree tmp;
-      memcpy ((char *) &buf, expr, tree_size (expr));
-      expr = tmp = (tree) &buf;
+      size_t sz = tree_size (expr);
+      buf = XALLOCAVAR (union tree_node, sz);
+      memcpy ((char *) buf, expr, sz);
+      expr = tmp = (tree) buf;
       TYPE_CONTAINS_PLACEHOLDER_INTERNAL (tmp) = 0;
       TYPE_POINTER_TO (tmp) = NULL;
       TYPE_REFERENCE_TO (tmp) = NULL;
@@ -12160,9 +12164,11 @@ fold_checksum_tree (const_tree expr, struct md5_ctx *ctx,
     {
       /* Allow TREE_NO_WARNING to be set.  Perhaps we shouldn't allow that
 	 and change builtins.c etc. instead - see PR89543.  */
-      memcpy ((char *) &buf, expr, tree_size (expr));
-      buf.base.nowarning_flag = 0;
-      expr = (tree) &buf;
+      size_t sz = tree_size (expr);
+      buf = XALLOCAVAR (union tree_node, sz);
+      memcpy ((char *) buf, expr, sz);
+      buf->base.nowarning_flag = 0;
+      expr = (tree) buf;
     }
   md5_process_bytes (expr, tree_size (expr), ctx);
   if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f9d770c96f15a811adac1e981078ed2add2984d8..b9bfeced886778c40e05942fcdc94a8b620462dd 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
 2019-03-05  Jakub Jelinek  <jakub@redhat.com>
 
+	PR bootstrap/89560
+	* g++.dg/other/pr89560.C: New test.
+
 	PR tree-optimization/89570
 	* gcc.dg/pr89570.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/other/pr89560.C b/gcc/testsuite/g++.dg/other/pr89560.C
new file mode 100644
index 0000000000000000000000000000000000000000..deb983969d75a1fdac95ce30fbeb6224ecbc7208
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/pr89560.C
@@ -0,0 +1,13 @@
+// PR bootstrap/89560
+// { dg-do compile }
+
+#define TEN(x) x##0, x##1, x##2, x##3, x##4, x##5, x##6, x##7, x##8, x##9,
+#define HUNDRED(x) TEN(x##0) TEN(x##1) TEN(x##2) TEN(x##3) TEN(x##4) \
+		   TEN(x##5) TEN(x##6) TEN(x##7) TEN(x##8) TEN(x##9)
+int foo (int, ...);
+
+int
+bar ()
+{
+  return (foo (HUNDRED (1) 0));
+}