diff options
author | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-12-04 22:55:40 +0000 |
---|---|---|
committer | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-12-04 22:55:40 +0000 |
commit | ec11e38eda98d7259002eebd58291990beacda84 (patch) | |
tree | 47e4fa29a6462438cb5aea8ae3e2c690243e3f52 /gcc/c-decl.c | |
parent | f1833f1bf639955df2ff48caa738ed0cffb0af8d (diff) | |
download | gcc-ec11e38eda98d7259002eebd58291990beacda84.tar.gz |
* c-common.def (COMPOUND_LITERAL_EXPR): New.
* c-common.c (c_expand_expr): Handle COMPOUND_LITERAL_EXPR.
(c_staticp): New function.
* c-common.h (COMPOUND_LITERAL_EXPR_DECL): New.
(c_staticp): Declare.
* c-typeck.c (default_function_array_conversion, build_unary_op):
Don't handle CONSTRUCTOR specially.
(lvalue_p, mark_addressable): Handle COMPOUND_LITERAL_EXPR.
* c-decl.c (build_compound_literal): New function.
* c-tree.h (build_compound_literal): Declare.
* c-parse.in (primary): Use build_compound_literal.
* c-lang.c (LANG_HOOKS_STATICP): Define.
* objc/objc-lang.c (LANG_HOOKS_STATICP): Likewise.
* doc/c-tree.texi: Document COMPOUND_LITERAL_EXPR.
* doc/extend.texi: Update documentation of compound literals.
Fixes PR c/4787.
testsuite:
* gcc.c-torture/execute/20000722-1.x,
gcc.c-torture/execute/20010123-1.x: Remove.
* gcc.c-torture/compile/init-3.c: Don't use a compound literal.
* gcc.dg/c90-complit-1.c, gcc.dg/c99-complit-1.c,
gcc.dg/c99-complit-2.c: New tests.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@47629 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r-- | gcc/c-decl.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 34278546d97..b5597f98dad 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -3793,6 +3793,59 @@ clear_parm_order () current_binding_level->parm_order = NULL_TREE; } +/* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound + literal, which may be an incomplete array type completed by the + initializer; INIT is a CONSTRUCTOR that initializes the compound + literal. */ + +tree +build_compound_literal (type, init) + tree type; + tree init; +{ + /* We do not use start_decl here because we have a type, not a declarator; + and do not use finish_decl because the decl should be stored inside + the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_STMT. */ + tree decl = build_decl (VAR_DECL, NULL_TREE, type); + tree complit; + DECL_EXTERNAL (decl) = 0; + TREE_PUBLIC (decl) = 0; + TREE_STATIC (decl) = (current_binding_level == global_binding_level); + DECL_CONTEXT (decl) = current_function_decl; + TREE_USED (decl) = 1; + TREE_TYPE (decl) = type; + store_init_value (decl, init); + + if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) + { + int failure = complete_array_type (type, DECL_INITIAL (decl), 1); + if (failure) + abort (); + } + + type = TREE_TYPE (decl); + if (type == error_mark_node || !COMPLETE_TYPE_P (type)) + return error_mark_node; + + complit = build1 (COMPOUND_LITERAL_EXPR, TREE_TYPE (decl), decl); + TREE_SIDE_EFFECTS (complit) = 1; + + layout_decl (decl, 0); + + if (TREE_STATIC (decl)) + { + /* This decl needs a name for the assembler output. We also need + a unique suffix to be added to the name, for which DECL_CONTEXT + must be set. */ + DECL_NAME (decl) = get_identifier ("__compound_literal"); + DECL_CONTEXT (decl) = complit; + rest_of_decl_compilation (decl, NULL, 1, 0); + DECL_CONTEXT (decl) = NULL_TREE; + } + + return complit; +} + /* Make TYPE a complete type based on INITIAL_VALUE. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered, 2 if there was no information (in which case assume 1 if DO_DEFAULT). */ |