All of lore.kernel.org
 help / color / mirror / Atom feed
* Question about Sparse parsing - return statement
@ 2017-08-21 21:53 Dibyendu Majumdar
  2017-08-21 23:40 ` Linus Torvalds
  0 siblings, 1 reply; 4+ messages in thread
From: Dibyendu Majumdar @ 2017-08-21 21:53 UTC (permalink / raw)
  To: Linux-Sparse

Hi,

I notice that the return statement has a symbol associated with - the
ret_target. What is the meaning of this symbol?

Thanks and Regards
Dibyendu

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

* Re: Question about Sparse parsing - return statement
  2017-08-21 21:53 Question about Sparse parsing - return statement Dibyendu Majumdar
@ 2017-08-21 23:40 ` Linus Torvalds
  2017-08-21 23:42   ` Linus Torvalds
  2017-08-21 23:53   ` Dibyendu Majumdar
  0 siblings, 2 replies; 4+ messages in thread
From: Linus Torvalds @ 2017-08-21 23:40 UTC (permalink / raw)
  To: Dibyendu Majumdar; +Cc: Linux-Sparse

On Mon, Aug 21, 2017 at 2:53 PM, Dibyendu Majumdar
<mobile@majumdar.org.uk> wrote:
>
> I notice that the return statement has a symbol associated with - the
> ret_target. What is the meaning of this symbol?

Sparse uses symbols for branch targets too.

There's several special target symbols - the return target, the
break/continue targets for loops and switch statements etc.

For example, a regular label (ie a target of a "goto") is a symbol
with the identifier being the label.  Amd the return point is
basically just another label that has the identifier "return".

So a "return statement" is basically the same as "goto return-label"
(plus the expression handling if there is one, of course).

Note that there can be *many* such return points as a function is
generated, since each inlined function will have its return point
pointing to the place in the calling function where it will return.
The same way each 'switch' statement will have its "break" label, and
each "for/.while/do" loop will have it's own "continue" and "break"
labels.

Note how each label is always described by a symbol, and how you can
look up what "break" means (regardless of whether you're in a switch
or a loop context) by just looking up the "break" label in the
NS_ITERATOR namespace.

In fact, it should be noted that the code to handle "break" and
"continue" is *EXACTLY*THE*SAME*. That should blow your mind. They
both use exactly the same logic, and they just do exactly the same
thing: look up the symbol associated with that ident, and "goto" it.

(I may be off in some of the details, it's way too long since I looked
at this code).

The return symbol is also the exit point of a compound statement, so
there's a lot of just commonalities here: any branch target always is
a symbol that is associated with the basic block that is the target.

         Linus

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

* Re: Question about Sparse parsing - return statement
  2017-08-21 23:40 ` Linus Torvalds
@ 2017-08-21 23:42   ` Linus Torvalds
  2017-08-21 23:53   ` Dibyendu Majumdar
  1 sibling, 0 replies; 4+ messages in thread
From: Linus Torvalds @ 2017-08-21 23:42 UTC (permalink / raw)
  To: Dibyendu Majumdar; +Cc: Linux-Sparse

On Mon, Aug 21, 2017 at 4:40 PM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> Sparse uses symbols for branch targets too.

Side note: when you work with the linearized representation, I don't
think you should really need to care. You should be able to just work
with the basic block information, and the symbols that are used to
generate the branches between the basic blocks should be pretty much a
non-issue by the time it's all been linearized.

But maybe I'm missing or have forgotten something.

            Linus

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

* Re: Question about Sparse parsing - return statement
  2017-08-21 23:40 ` Linus Torvalds
  2017-08-21 23:42   ` Linus Torvalds
@ 2017-08-21 23:53   ` Dibyendu Majumdar
  1 sibling, 0 replies; 4+ messages in thread
From: Dibyendu Majumdar @ 2017-08-21 23:53 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Linux-Sparse

Hi Linus,

On 22 August 2017 at 00:40, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
> On Mon, Aug 21, 2017 at 2:53 PM, Dibyendu Majumdar
> <mobile@majumdar.org.uk> wrote:
>>
>> I notice that the return statement has a symbol associated with - the
>> ret_target. What is the meaning of this symbol?
>
> Sparse uses symbols for branch targets too.
>
> There's several special target symbols - the return target, the
> break/continue targets for loops and switch statements etc.
>
> For example, a regular label (ie a target of a "goto") is a symbol
> with the identifier being the label.  Amd the return point is
> basically just another label that has the identifier "return".
>
> So a "return statement" is basically the same as "goto return-label"
> (plus the expression handling if there is one, of course).
>

Okay thanks.

> Note that there can be *many* such return points as a function is
> generated, since each inlined function will have its return point
> pointing to the place in the calling function where it will return.
> The same way each 'switch' statement will have its "break" label, and
> each "for/.while/do" loop will have it's own "continue" and "break"
> labels.
>
> Note how each label is always described by a symbol, and how you can
> look up what "break" means (regardless of whether you're in a switch
> or a loop context) by just looking up the "break" label in the
> NS_ITERATOR namespace.
>
> In fact, it should be noted that the code to handle "break" and
> "continue" is *EXACTLY*THE*SAME*. That should blow your mind. They
> both use exactly the same logic, and they just do exactly the same
> thing: look up the symbol associated with that ident, and "goto" it.
>

Cool. I haven't got around to breaks and continues yet.

> (I may be off in some of the details, it's way too long since I looked
> at this code).
>
> The return symbol is also the exit point of a compound statement, so
> there's a lot of just commonalities here: any branch target always is
> a symbol that is associated with the basic block that is the target.
>

Okay makes sense.

Regards
Dibyendu

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

end of thread, other threads:[~2017-08-21 23:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-21 21:53 Question about Sparse parsing - return statement Dibyendu Majumdar
2017-08-21 23:40 ` Linus Torvalds
2017-08-21 23:42   ` Linus Torvalds
2017-08-21 23:53   ` Dibyendu Majumdar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.