public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* conditional LABEL_EXPR
@ 2012-10-09 11:47 Philip Herron
  2012-10-09 14:01 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Philip Herron @ 2012-10-09 11:47 UTC (permalink / raw)
  To: GCC

Hey

I have been on and off trying to figure out in my front-end how to use
labels. Never seem to get them to work say i have the code:

bool x;
...

if (x == true)
{
  do more stuff here
}

How do i create this so far i have:

  tree label_decl = create_artificial_label (UNKNOWN_LOCATION);
  tree label_expr = fold_build1_loc (UNKNOWN_LOCATION, LABEL_EXPR,
				     void_type_node, label_decl);
 tree label_exit_decl  = ...
 tree label_exit_expr

  tree conditional = fold_build2_loc (UNKNOWN_LOCATION, EQ_EXPR,
boolean_type_node,
				      if_cond_tree, boolean_true_node);
  tree if_cond = build3_loc (UNKNOWN_LOCATION, COND_EXPR, void_type_node,
			     if_cond_tree,
			     build1 (GOTO_EXPR, void_type_node, label_expr),
			     build1 (GOTO_EXPR, void_type_node, label_exit_expr));

  append_to_statement_list (if_cond, stmts);
  append_to_statement_list (label_expr, stmts);
  gpy_dot_pass_genericify_suite (ifblock_suite, stmts, context);
  appent_to_statement_list (labe_exit_expr, stmts);

But i get:

<built-in>: In function ‘decr.py.test’:
<built-in>:0:0: internal compiler error: in gimplify_expr, at gimplify.c:7157
Please submit a full bug report,

And the asset is:

case LABEL_EXPR:
	  ret = GS_ALL_DONE;
	  gcc_assert (decl_function_context (LABEL_EXPR_LABEL (*expr_p))
		      == current_function_decl);
	  gimplify_seq_add_stmt (pre_p,
			  gimple_build_label (LABEL_EXPR_LABEL (*expr_p)));
	  break;

I can't see a good example on how to make an if statement hard to dig
through front-end specifics. I wonder does this mean for every
LABEL_EXPR it was DECL_CONTEXT(label) = current_fndecl?

--Phil

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: conditional LABEL_EXPR
  2012-10-09 11:47 conditional LABEL_EXPR Philip Herron
@ 2012-10-09 14:01 ` Ian Lance Taylor
  2012-10-09 14:58   ` Philip Herron
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2012-10-09 14:01 UTC (permalink / raw)
  To: Philip Herron; +Cc: GCC

On Tue, Oct 9, 2012 at 4:47 AM, Philip Herron <redbrain@gcc.gnu.org> wrote:
>
>   tree label_decl = create_artificial_label (UNKNOWN_LOCATION);

>
> I can't see a good example on how to make an if statement hard to dig
> through front-end specifics. I wonder does this mean for every
> LABEL_EXPR it was DECL_CONTEXT(label) = current_fndecl?

When you call create_artificial_label, it will set DECL_CONTEXT of the
new label to point to current_function_decl.  So the simplest way to
get the right thing is to ensure that current_function_decl is correct
whenever you call create_artificial_label.

Ian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: conditional LABEL_EXPR
  2012-10-09 14:01 ` Ian Lance Taylor
@ 2012-10-09 14:58   ` Philip Herron
  0 siblings, 0 replies; 3+ messages in thread
From: Philip Herron @ 2012-10-09 14:58 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: GCC

On 9 October 2012 15:01, Ian Lance Taylor <iant@google.com> wrote:
> On Tue, Oct 9, 2012 at 4:47 AM, Philip Herron <redbrain@gcc.gnu.org> wrote:
>>
>>   tree label_decl = create_artificial_label (UNKNOWN_LOCATION);
>
>>
>> I can't see a good example on how to make an if statement hard to dig
>> through front-end specifics. I wonder does this mean for every
>> LABEL_EXPR it was DECL_CONTEXT(label) = current_fndecl?
>
> When you call create_artificial_label, it will set DECL_CONTEXT of the
> new label to point to current_function_decl.  So the simplest way to
> get the right thing is to ensure that current_function_decl is correct
> whenever you call create_artificial_label.
>
> Ian

Think i might be getting i just tried:

DECL_CONTEXT(label_entry_expr) = current_function_decl;
DECL_CONTEXT(label_exit_expr) = current_function_decl;

But i get:

Program received signal SIGSEGV, Segmentation fault.
0x0848524c in var_map_base_init ()

I dont think i have debugging all turned on so i cant see whats going on yet.

--Phil

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-10-09 14:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-09 11:47 conditional LABEL_EXPR Philip Herron
2012-10-09 14:01 ` Ian Lance Taylor
2012-10-09 14:58   ` Philip Herron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).