diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2d3889700da3e9058fd3e1d0f6b02d946af37bec..e03f97a2e82e6600266e848bdcfd082f0bd954ec 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,20 @@
+2005-07-05  Joseph S. Myers  <joseph@codesourcery.com>
+
+	PR c/22013
+	PR c/22098
+	* langhooks.h (struct lang_hooks): Add expr_to_decl.
+	* langhooks.c (lhd_expr_to_decl): New.
+	* langhooks-def.h (lhd_expr_to_decl, LANG_HOOKS_EXPR_TO_DECL):
+	New.
+	(LANG_HOOKS_INITIALIZER): Update.
+	* tree.c (recompute_tree_invarant_for_addr_expr): Call
+	expr_to_decl langhook.
+	* c-tree.h (c_expr_to_decl): Declare.
+	* c-typeck.c (c_expr_to_decl): New.
+	(build_unary_op): Do not handle ADDR_EXPR of COMPOUND_LITERAL_EXPR
+	specially.
+	* c-objc-common.h (LANG_HOOKS_EXPR_TO_DECL): Define.
+
 2005-07-05  Joseph S. Myers  <joseph@codesourcery.com>
 
 	PR c/22308
diff --git a/gcc/c-objc-common.h b/gcc/c-objc-common.h
index d74273cf935ed47716b9130d24278734d7ef7319..69212599612a8faf1bb4bbf580882854e5583139 100644
--- a/gcc/c-objc-common.h
+++ b/gcc/c-objc-common.h
@@ -117,6 +117,8 @@ extern void c_initialize_diagnostics (diagnostic_context *);
 #define LANG_HOOKS_REGISTER_BUILTIN_TYPE c_register_builtin_type
 #undef LANG_HOOKS_TO_TARGET_CHARSET
 #define LANG_HOOKS_TO_TARGET_CHARSET c_common_to_target_charset
+#undef LANG_HOOKS_EXPR_TO_DECL
+#define LANG_HOOKS_EXPR_TO_DECL c_expr_to_decl
 
 /* The C front end's scoping structure is very different from
    that expected by the language-independent code; it is best
diff --git a/gcc/c-tree.h b/gcc/c-tree.h
index 4cf6fa7c3effedace12332ba15b95775b1fc2ed0..3266ceccbdf14e6e9b57162bf32991e85c76d917 100644
--- a/gcc/c-tree.h
+++ b/gcc/c-tree.h
@@ -573,6 +573,7 @@ extern tree c_finish_goto_label (tree);
 extern tree c_finish_goto_ptr (tree);
 extern void c_begin_vm_scope (unsigned int);
 extern void c_end_vm_scope (unsigned int);
+extern tree c_expr_to_decl (tree, bool *, bool *, bool *);
 
 /* Set to 0 at beginning of a function definition, set to 1 if
    a return statement that specifies a return value is seen.  */
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 64ec126b4bdbc145cb188e0564c94f4ff30c84aa..ab72ceea1200875985bfd9285fd82b6ad9dc67f4 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -2790,9 +2790,6 @@ build_unary_op (enum tree_code code, tree xarg, int flag)
 
       val = build1 (ADDR_EXPR, argtype, arg);
 
-      if (TREE_CODE (arg) == COMPOUND_LITERAL_EXPR)
-	TREE_INVARIANT (val) = TREE_CONSTANT (val) = 1;
-
       return val;
 
     default:
@@ -8142,3 +8139,24 @@ c_objc_common_truthvalue_conversion (tree expr)
      leaving those to give errors later?  */
   return c_common_truthvalue_conversion (expr);
 }
+
+
+/* Convert EXPR to a contained DECL, updating *TC, *TI and *SE as
+   required.  */
+
+tree
+c_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED,
+		bool *ti ATTRIBUTE_UNUSED, bool *se)
+{
+  if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
+    {
+      tree decl = COMPOUND_LITERAL_EXPR_DECL (expr);
+      /* Executing a compound literal inside a function reinitializes
+	 it.  */
+      if (!TREE_STATIC (decl))
+	*se = true;
+      return decl;
+    }
+  else
+    return expr;
+}
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index 2c8bb9631982460239f838cfdb7061e96a97647f..cd9a98e647989d88e6f16dfdf96f4c95f7138029 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -69,6 +69,7 @@ extern const char *lhd_comdat_group (tree);
 extern tree lhd_expr_size (tree);
 extern size_t lhd_tree_size (enum tree_code);
 extern HOST_WIDE_INT lhd_to_target_charset (HOST_WIDE_INT);
+extern tree lhd_expr_to_decl (tree, bool *, bool *, bool *);
 
 /* Declarations of default tree inlining hooks.  */
 extern tree lhd_tree_inlining_walk_subtrees (tree *, int *, walk_tree_fn,
@@ -123,6 +124,7 @@ extern int lhd_gimplify_expr (tree *, tree *, tree *);
 #define LANG_HOOKS_TREE_SIZE		lhd_tree_size
 #define LANG_HOOKS_TYPES_COMPATIBLE_P	lhd_types_compatible_p
 #define LANG_HOOKS_BUILTIN_FUNCTION	builtin_function
+#define LANG_HOOKS_EXPR_TO_DECL		lhd_expr_to_decl
 #define LANG_HOOKS_TO_TARGET_CHARSET	lhd_to_target_charset
 
 #define LANG_HOOKS_FUNCTION_INIT	lhd_do_nothing_f
@@ -299,6 +301,7 @@ extern tree lhd_make_node (enum tree_code);
   LANG_HOOKS_GIMPLIFY_EXPR, \
   LANG_HOOKS_FOLD_OBJ_TYPE_REF, \
   LANG_HOOKS_BUILTIN_FUNCTION, \
+  LANG_HOOKS_EXPR_TO_DECL, \
 }
 
 #endif /* GCC_LANG_HOOKS_DEF_H */
diff --git a/gcc/langhooks.c b/gcc/langhooks.c
index e2939f07bfcc81dbe4e428d18cb91ddb38ae4ced..5f3fb4be65ec4dac09b26a5cd41c9fb317433c6a 100644
--- a/gcc/langhooks.c
+++ b/gcc/langhooks.c
@@ -543,3 +543,10 @@ lhd_to_target_charset (HOST_WIDE_INT c)
 {
   return c;
 }
+
+tree
+lhd_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED,
+		  bool *ti ATTRIBUTE_UNUSED, bool *se ATTRIBUTE_UNUSED)
+{
+  return expr;
+}
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index a0c24fc4e2166351a37e036027f900bf71ef0a78..9ec07ad71f88b954af10812490cc5e413aa293c3 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -412,6 +412,12 @@ struct lang_hooks
 			    enum built_in_class bt_class,
 			    const char *library_name, tree attrs);
 
+  /* Called by recompute_tree_invarant_for_addr_expr to go from EXPR
+     to a contained expression or DECL, possibly updating *TC, *TI or
+     *SE if in the process TREE_CONSTANT, TREE_INVARIANT or
+     TREE_SIDE_EFFECTS need updating.  */
+  tree (*expr_to_decl) (tree expr, bool *tc, bool *ti, bool *se);
+
   /* Whenever you add entries here, make sure you adjust langhooks-def.h
      and langhooks.c accordingly.  */
 };
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7588b6669e72b8023fdafd38e2591648f4f29dde..e598f6e508869e2a81ac81d1e57138eab2eeb2ba 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2005-07-05  Joseph S. Myers  <joseph@codesourcery.com>
+
+	PR c/22013
+	PR c/22098
+	* gcc.c-torture/compile/pr22013-1.c,
+	gcc.c-torture/execute/pr22098-1.c,
+	gcc.c-torture/execute/pr22098-2.c,
+	gcc.c-torture/execute/pr22098-3.c: New tests.
+
 2005-07-05  Joseph S. Myers  <joseph@codesourcery.com>
 
 	PR c/22308
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr22013-1.c b/gcc/testsuite/gcc.c-torture/compile/pr22013-1.c
new file mode 100644
index 0000000000000000000000000000000000000000..1dd0adcffc6d249229e679435e7f635db5ee36b4
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr22013-1.c
@@ -0,0 +1,11 @@
+typedef unsigned short W;
+typedef const W *P;
+
+extern void g(P);
+
+void
+f ()
+{
+  const P s = (const W []){ 'R' };
+  g (s);
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr22098-1.c b/gcc/testsuite/gcc.c-torture/execute/pr22098-1.c
new file mode 100644
index 0000000000000000000000000000000000000000..142530f62c120a0b40ad119fa275fbbd94399e90
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr22098-1.c
@@ -0,0 +1,14 @@
+extern void abort (void);
+extern void exit (int);
+typedef __SIZE_TYPE__ size_t;
+int
+main (void)
+{
+  int a = 0;
+  int *p;
+  size_t b;
+  b = (size_t)(p = &(int []){0, 1, 2}[++a]);
+  if (a != 1 || *p != 1 || *(int *)b != 1)
+    abort ();
+  exit (0);
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr22098-2.c b/gcc/testsuite/gcc.c-torture/execute/pr22098-2.c
new file mode 100644
index 0000000000000000000000000000000000000000..249647dc5705d4841b83fab9ff0e9e6de24048ff
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr22098-2.c
@@ -0,0 +1,14 @@
+extern void abort (void);
+extern void exit (int);
+typedef __SIZE_TYPE__ size_t;
+int
+main (void)
+{
+  int a = 0;
+  int *p;
+  size_t b;
+  b = (size_t)(p = &(int []){0, 1, 2}[1]);
+  if (*p != 1 || *(int *)b != 1)
+    abort ();
+  exit (0);
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr22098-3.c b/gcc/testsuite/gcc.c-torture/execute/pr22098-3.c
new file mode 100644
index 0000000000000000000000000000000000000000..4c8a1c62ce05240dc089469bed23ecee905b2a07
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr22098-3.c
@@ -0,0 +1,16 @@
+extern void abort (void);
+extern void exit (int);
+typedef __SIZE_TYPE__ size_t;
+int n = 0;
+int f (void) { return ++n; }
+int
+main (void)
+{
+  int a = 0;
+  int *p;
+  size_t b;
+  b = (size_t)(p = &(int []){0, f(), 2}[1]);
+  if (*p != 1 || *(int *)b != 1 || n != 1)
+    abort ();
+  exit (0);
+}
diff --git a/gcc/tree.c b/gcc/tree.c
index 76f52cdcb6dc734e77f797e818c57761f82cc00e..606788148245ca6e8adcd5e62358514d2bdb56b3 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -2466,6 +2466,8 @@ do { tree _node = (NODE); \
 	UPDATE_TITCSE (TREE_OPERAND (node, 2));
     }
 
+  node = lang_hooks.expr_to_decl (node, &tc, &ti, &se);
+
   /* Now see what's inside.  If it's an INDIRECT_REF, copy our properties from
      the address, since &(*a)->b is a form of addition.  If it's a decl, it's
      invariant and constant if the decl is static.  It's also invariant if it's