public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [lambda] Segmentation fault in simple lambda program
@ 2009-08-06 13:52 John Freeman
  0 siblings, 0 replies; 24+ messages in thread
From: John Freeman @ 2009-08-06 13:52 UTC (permalink / raw)
  To: gcc

On Thu, Aug 6, 2009 at 6:27 AM, Adam Butcher <adam@jessamine.co.uk 
<mailto:adam@jessamine.co.uk>> wrote:

    I take you're point on [finish_struct_1] potentially being overkill
    but at least it means that user programs
    that copy can work.


Right.  I only added that comment so that other developers who come 
along and want to optimize it won't fall into the same trap I did.
 

    I've attached my two diffs made against the latest lambda head.
     First is explicit polymorphic lambda support via the
    additional template parameter syntax, second is the very hacky
    'for-discovery-purposes-only' prototype for typename
    inference.


I was hesitant to add the first patch alone, but now that you've got the 
second, I'm eager to take another look. 
 

    Currently for auto typename inference, cv-qualifiers (and other bits
    like attributes) are lost

    One thing I'm worried about is that I'm using make_tree_vec() with a
    length one greater than that of the previous
    vector in order to grow the template parameter list whilst parsing
    function arguments.


I'll be sure to look at these issues.
 

    There's a number of things I'm not sure about regarding location of
    the implementation (parser.c, semantics.c, decl.c
    etc).


The general guideline I followed was to put as much non-parsing logic 
into semantics.c as possible, and call into it from parser.c when 
needed.  I'm not sure what needs to go into decl.c either.


I will try to take this opportunity of renewed interest in the lambdas 
branch to look at dependent type support and name mangling.  When I say 
dependent type support, I mean using lambdas that capture or declare 
variables of dependent type from a surrounding template context.  Many 
people won't be able to effectively use lambdas until these features are 
added.

- John

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: [lambda] Segmentation fault in simple lambda program
@ 2009-04-30 19:43 Smith-Rowland, Edward M
  2009-04-30 21:57 ` Esben Mose Hansen
  0 siblings, 1 reply; 24+ messages in thread
From: Smith-Rowland, Edward M @ 2009-04-30 19:43 UTC (permalink / raw)
  To: kde, gcc


Esben Mose Hansen <kde@mosehansen.dk> writes:

> this program SEGFAULTs
>
> #include <algorithm>
>
> int main() {
>   int numbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
>   const std::size_t nn = sizeof(numbers)/sizeof(int);
>   int sum = 0;
>   int f = 5;
>   std::for_each(&numbers[0], &numbers[nn],  [&]  (int n)  { 
>     sum += n * f; 
>   });
>
> }
>
> Now, my assembly days are some 15 years past, but the disassembly is
>
> 0x08048424 <_ZZ4mainENK9__lambda0clEiz+0>:      push   %ebp
> 0x08048425 <_ZZ4mainENK9__lambda0clEiz+1>:      mov    %esp,%ebp
> 0x08048427 <_ZZ4mainENK9__lambda0clEiz+3>:      mov    0x8(%ebp),%eax
> 0x0804842a <_ZZ4mainENK9__lambda0clEiz+6>:      mov    0x4(%eax),%eax
> 0x0804842d <_ZZ4mainENK9__lambda0clEiz+9>:      mov    0x8(%ebp),%edx
> 0x08048430 <_ZZ4mainENK9__lambda0clEiz+12>:     mov    0x4(%edx),%edx
> 0x08048433 <_ZZ4mainENK9__lambda0clEiz+15>:     mov    (%edx),%ecx
> 0x08048435 <_ZZ4mainENK9__lambda0clEiz+17>:     mov    0x8(%ebp),%edx
> 0x08048438 <_ZZ4mainENK9__lambda0clEiz+20>:     mov    (%edx),%edx
> 0x0804843a <_ZZ4mainENK9__lambda0clEiz+22>:     mov    (%edx),%edx
> 0x0804843c <_ZZ4mainENK9__lambda0clEiz+24>:     imul   0xc(%ebp),%edx
> 0x08048440 <_ZZ4mainENK9__lambda0clEiz+28>:     lea    (%ecx,%edx,1),%edx
> => SEGFAULT 0x08048443 <_ZZ4mainENK9__lambda0clEiz+31>:     mov    %edx,(%eax)
> 0x08048445 <_ZZ4mainENK9__lambda0clEiz+33>:     pop    %ebp
> 0x08048446 <_ZZ4mainENK9__lambda0clEiz+34>:     ret
>
> I have marked the segfault spot. I also find 0x0804843a suspicious, but then I 
> don't even know how to print register values in gcc. 
>
> Any pointers to where I should dig? I am completely new to gcc hacking, just 
> dying to get lambda into gcc 4.5 :)
>
> P.S: Shouldn't gcc show the actual lambda function code ( sum+= f*c; ) instead 
> of the assembly code in any case?

When I try to specify the capture it works ((&sum, &f) works too but f is const):

#include <algorithm>

int
main(void)
{
  int numbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  const std::size_t nn = sizeof(numbers)/sizeof(int);
  int sum = 0;
  int f = 5;

  //std::for_each(&numbers[0], &numbers[nn], [&](int n) { sum += n * f; });

  std::for_each(&numbers[0], &numbers[nn], [&sum, f](int n) { sum += n * f; });

  return 0;
}

^ permalink raw reply	[flat|nested] 24+ messages in thread
* [lambda] Segmentation fault in simple lambda program
@ 2009-04-29 22:07 Esben Mose Hansen
  2009-04-30 11:54 ` Ian Lance Taylor
  0 siblings, 1 reply; 24+ messages in thread
From: Esben Mose Hansen @ 2009-04-29 22:07 UTC (permalink / raw)
  To: gcc

Hi,

this program SEGFAULTs

#include <algorithm>

int main() {
  int numbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  const std::size_t nn = sizeof(numbers)/sizeof(int);
  int sum = 0;
  int f = 5;
  std::for_each(&numbers[0], &numbers[nn],  [&]  (int n)  { 
    sum += n * f; 
  });

}

Now, my assembly days are some 15 years past, but the disassembly is

0x08048424 <_ZZ4mainENK9__lambda0clEiz+0>:      push   %ebp
0x08048425 <_ZZ4mainENK9__lambda0clEiz+1>:      mov    %esp,%ebp
0x08048427 <_ZZ4mainENK9__lambda0clEiz+3>:      mov    0x8(%ebp),%eax
0x0804842a <_ZZ4mainENK9__lambda0clEiz+6>:      mov    0x4(%eax),%eax
0x0804842d <_ZZ4mainENK9__lambda0clEiz+9>:      mov    0x8(%ebp),%edx
0x08048430 <_ZZ4mainENK9__lambda0clEiz+12>:     mov    0x4(%edx),%edx
0x08048433 <_ZZ4mainENK9__lambda0clEiz+15>:     mov    (%edx),%ecx
0x08048435 <_ZZ4mainENK9__lambda0clEiz+17>:     mov    0x8(%ebp),%edx
0x08048438 <_ZZ4mainENK9__lambda0clEiz+20>:     mov    (%edx),%edx
0x0804843a <_ZZ4mainENK9__lambda0clEiz+22>:     mov    (%edx),%edx
0x0804843c <_ZZ4mainENK9__lambda0clEiz+24>:     imul   0xc(%ebp),%edx
0x08048440 <_ZZ4mainENK9__lambda0clEiz+28>:     lea    (%ecx,%edx,1),%edx
=> SEGFAULT 0x08048443 <_ZZ4mainENK9__lambda0clEiz+31>:     mov    %edx,(%eax)
0x08048445 <_ZZ4mainENK9__lambda0clEiz+33>:     pop    %ebp
0x08048446 <_ZZ4mainENK9__lambda0clEiz+34>:     ret

I have marked the segfault spot. I also find 0x0804843a suspicious, but then I 
don't even know how to print register values in gcc. 

Any pointers to where I should dig? I am completely new to gcc hacking, just 
dying to get lambda into gcc 4.5 :)

P.S: Shouldn't gcc show the actual lambda function code ( sum+= f*c; ) instead 
of the assembly code in any case?

Thanks for your help!

-- 
Kind regards, Esben

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

end of thread, other threads:[~2009-08-06 13:50 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1248855585.29221.ezmlm@gcc.gnu.org>
2009-07-29 10:27 ` [lambda] Segmentation fault in simple lambda program Adam Butcher
2009-07-29 14:17   ` Ed Smith-Rowland
2009-08-03 18:31   ` Jason Merrill
2009-08-04  2:25     ` Adam Butcher
2009-08-04  4:11       ` Jason Merrill
2009-08-04  4:39         ` John Freeman
2009-08-04  5:39         ` John Freeman
2009-08-04 15:33           ` Richard Henderson
2009-08-04 22:45           ` John Freeman
2009-08-06 12:40             ` Adam Butcher
2009-08-04  9:07         ` Adam Butcher
2009-08-04 13:35           ` Adam Butcher
2009-08-04 13:44           ` John Freeman
2009-08-04 14:18             ` Jason Merrill
2009-08-04 14:46               ` John Freeman
2009-08-04 14:57                 ` Jason Merrill
2009-08-04 16:14                   ` John Freeman
2009-08-04 14:49           ` Jason Merrill
2009-08-04 16:17             ` John Freeman
2009-08-06 13:52 John Freeman
  -- strict thread matches above, loose matches on Subject: below --
2009-04-30 19:43 Smith-Rowland, Edward M
2009-04-30 21:57 ` Esben Mose Hansen
2009-04-29 22:07 Esben Mose Hansen
2009-04-30 11:54 ` Ian Lance Taylor

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).