Re: Nested-Functions

2018-01-04 Thread Jonathan Wakely
On 4 January 2018 at 00:44, nick wrote:
>
>
> On 2018-01-03 06:05 PM, Jonathan Wakely wrote:
>> On 3 January 2018 at 21:13, Alexsandr Yvarov wrote:
>>> Why would dont add it at GNU G++?
>>
>> Aren't C++ lambda expressions more powerful and flexible?
>>
>
> It depends actually, lambdas are consider the  C++ standard of this. I am 
> wondering what
> you mean Alexsandir and what is your use case as lambdas tryto solve this for 
> most use
> cases of antonymous and nested functions. What are the requirements if any 
> that lambdas
> don't meant and have you looked at the C++14/17 standard for them if your 
> compiler
> supports it.

This is the gcc-help list, so compilers that don't support C++14 are off topic.

> What do you mean by nested functions actually as that means a lot
> of things in compiler or language development.

This is the gcc-help list, so obviously it refers to the GCC extension:
https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html


Re: Nested-Functions

2018-01-04 Thread Jonathan Wakely
On 4 January 2018 at 00:54, nick wrote:
>
>
> On 2018-01-03 07:52 PM, Austin T wrote:
>>  By nested functions, I'm assuming that means raw function definitions that 
>> are valid inside a temporary scope of a function. If I'm not mistaken, 
>> they're equivalent to C++ lambda expressions but just written in a syntactic 
>> sugar syntax.
>>
>> Austin
>>
>
> That's the same thing actually if your going to name your lambda. What are 
> the advantages
> of this newer syntax or feature. Do you have any examples?

Read the docs. It's not newer, it's much older than C++ lambdas, but
is only supported in GNU C.


Build Ada compiler for nios2?

2018-01-04 Thread Sebastian Huber

Hello,

I tried to build an Ada compiler for nios2-rtems5 and ended up with this:

/run/user/10351/b-gcc-nios2/./gcc/xgcc 
-B/run/user/10351/b-gcc-nios2/./gcc/ -nostdinc 
-B/run/user/10351/b-gcc-nios2/nios2-rtems5/newlib/ -isystem 
/run/user/10351/b-gcc-nios2/nios2-rtems5/newlib/targ-include -isystem 
/home/sh/src/gcc/newlib/libc/include 
-B/home/sh/install/nios2-rtems5/bin/ 
-B/home/sh/install/nios2-rtems5/lib/ -isystem 
/home/sh/install/nios2-rtems5/include -isystem 
/home/sh/install/nios2-rtems5/sys-include    -c 
-DCROSS_DIRECTORY_STRUCTURE -DIN_GCC  -W -Wall -g -O2 -g -O2 
-fexceptions -DIN_RTS -DHAVE_GETIPINFO    \

    -iquote /home/sh/src/gcc/gcc \
 -iquote . -iquote .. -iquote ../.. -iquote 
/home/sh/src/gcc/gcc/ada -iquote /home/sh/src/gcc/gcc 
-I/home/sh/src/gcc/include  \

    targext.c -o targext.o
In file included from ../../tm.h:19,
 from targext.c:46:
/home/sh/src/gcc/gcc/config/nios2/nios2.h:436:31: error: expected '=', 
',', ';', 'asm' or '__attribute__' before 'nios2_section_threshold'

 extern unsigned HOST_WIDE_INT nios2_section_threshold;

This HOST_WIDE_INT is defined in gcc/hwint.h. Who is supposed to include 
this file? Is this done via an #include or via a tm_file (gcc/config.gcc)?


--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail  : sebastian.hu...@embedded-brains.de
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.



Re: Build Ada compiler for nios2?

2018-01-04 Thread Eric Botcazou
> This HOST_WIDE_INT is defined in gcc/hwint.h. Who is supposed to include
> this file? Is this done via an #include or via a tm_file (gcc/config.gcc)?

Nobody I'd say, the declaration shouldn't be compiled for the target.

-- 
Eric Botcazou


Re: Nested-Functions

2018-01-04 Thread Nathan Sidwell

On 01/03/2018 07:52 PM, Austin T wrote:

  By nested functions, I'm assuming that means raw function definitions that
are valid inside a temporary scope of a function. If I'm not mistaken,
they're equivalent to C++ lambda expressions but just written in a
syntactic sugar syntax.


GNU-C nested functions are less powerful than lambdas, but there's a 
performance tradeoff, that it is not clear to me which wins.


lambdas: the lambda gets hold of values and objects in the containing 
function's scope by means of captures.  These are members of a 
constructed object type (the closure type).  The capture may be by 
reference, or value.  Constructing the closure object involves 
initializing pointers and/or invoking copy ctors.  It happens once.  You 
can pass a functor which essentially decays to a plain pointer-to-fn if 
there are no captures.  You get a compile error if you ask not to 
capture things, but do.  You cannot convert a capturing lambda to a 
pointer-to-regular-function (but you don't need to do that in C++ code).


nested fns: a hidden 'static chain' parameter is passed to them via a 
spare register.  They know the layout of their ancestors' stack frames 
and directly access it to get outer scope entities.  To create a 
pointer-to-fn from one of these, the compiler constructs a 
stack-resident trampoline, to initialize the static chain pointer.  You 
silently get such a thing, if you 'accidentally' capture an outer scope 
object.


lambdas can be templates.

nathan

--
Nathan Sidwell


Re: Build Ada compiler for nios2?

2018-01-04 Thread Andreas Schwab
On Jan 04 2018, Sebastian Huber  wrote:

> /home/sh/src/gcc/gcc/config/nios2/nios2.h:436:31: error: expected '=',
> ',', ';', 'asm' or '__attribute__' before 'nios2_section_threshold'
>  extern unsigned HOST_WIDE_INT nios2_section_threshold;

Change the preprocessor conditional to check USED_FOR_TARGET instead of
IN_LIBGCC2.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


gcc diagnostic bug ?

2018-01-04 Thread François Dumont

On 15/12/2017 03:20, Jonathan Wakely wrote:

FAIL: 23_containers/vector/cons/destructible_neg.cc  (test for errors, line 35)
FAIL: 23_containers/vector/cons/destructible_neg.cc  (test for errors, line 41)


I had a look at this remaining issue. The compilation result is:

In file included from 
/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_tempbuf.h:60,
 from 
/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_algo.h:62,
 from 
/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/algorithm:62,
 from 
/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu/bits/stdc++.h:65,

 from :0:
/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_construct.h: 
In instantiation of 'void std::_Destroy(_ForwardIterator, 
_ForwardIterator) [with _ForwardIterator = DeletedDtor*]':
/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_construct.h:206: 
required from 'void std::_Destroy(_ForwardIterator, _ForwardIterator, 
std::allocator<_T2>&) [with _ForwardIterator = DeletedDtor*; _Tp = 
DeletedDtor]'
/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_vector.h:612: 
required from 'std::__cxx1998::vector<_Tp, _Alloc>::~vector() [with _Tp 
= DeletedDtor; _Alloc = std::allocator]'
/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/debug/vector:155: 
required from here


The code at debug/vector:155 is:

  vector() = default;

So no trace of a call to the ~std::__cxx1998::vector<> at that point.

I guess gcc tries to instantiate the destructor when generating the 
default vector constructor but IMO it shouldn't be visible in the 
compilation error message.


Should we report this as a gcc bug ?

François



gcc-7-20180104 is now available

2018-01-04 Thread gccadmin
Snapshot gcc-7-20180104 is now available on
  ftp://gcc.gnu.org/pub/gcc/snapshots/7-20180104/
and on various mirrors, see http://gcc.gnu.org/mirrors.html for details.

This snapshot has been generated from the GCC 7 SVN branch
with the following options: svn://gcc.gnu.org/svn/gcc/branches/gcc-7-branch 
revision 256268

You'll find:

 gcc-7-20180104.tar.xzComplete GCC

  SHA256=e92a7180ca19f74da329e6afc4de36e6a172a3f98d42baffc2dbb8c8817e1582
  SHA1=c82385d4c8043fdc2006f6b49de07cfc7665759c

Diffs from 7-20171228 are available in the diffs/ subdirectory.

When a particular snapshot is ready for public consumption the LATEST-7
link is updated and a message is sent to the gcc list.  Please do not use
a snapshot before it has been announced that way.


GCC and Meltdown and Spectre vulnerabilities

2018-01-04 Thread Eric Gallager
Is there anything GCC could be doing at the compiler level to mitigate
the recently-announced Meltdown and Spectre vulnerabilities? From
reading about them, it seems like they involve speculative execution
and indirect branch prediction, and those are the domain of things the
compiler deals with, right? (For reference, Meltdown is CVE-2017-5754,
and Spectre is CVE-2017-5753 and CVE-2017-5715)

Just wondering,
Eric


Re: GCC and Meltdown and Spectre vulnerabilities

2018-01-04 Thread Will Hawkins
On Thu, Jan 4, 2018 at 10:10 PM, Eric Gallager  wrote:
> Is there anything GCC could be doing at the compiler level to mitigate
> the recently-announced Meltdown and Spectre vulnerabilities? From
> reading about them, it seems like they involve speculative execution
> and indirect branch prediction, and those are the domain of things the
> compiler deals with, right? (For reference, Meltdown is CVE-2017-5754,
> and Spectre is CVE-2017-5753 and CVE-2017-5715)
>
> Just wondering,
> Eric

Check out

https://support.google.com/faqs/answer/7625886

and especially

http://git.infradead.org/users/dwmw2/gcc-retpoline.git/shortlog/refs/heads/gcc-7_2_0-retpoline-20171219

I'd love to hear what other people have heard!

Will


Re: GCC and Meltdown and Spectre vulnerabilities

2018-01-04 Thread Zan Lynx
On January 4, 2018 8:10:14 PM MST, Eric Gallager  wrote:
>Is there anything GCC could be doing at the compiler level to mitigate
>the recently-announced Meltdown and Spectre vulnerabilities? From
>reading about them, it seems like they involve speculative execution
>and indirect branch prediction, and those are the domain of things the
>compiler deals with, right? (For reference, Meltdown is CVE-2017-5754,
>and Spectre is CVE-2017-5753 and CVE-2017-5715)
>
>Just wondering,
>Eric

If you're allowing people to run untrustworthy machine code on your hardware 
there's nothing a compiler can do to help. You'd need to make them use your 
compiler, and why would they?

So anyone offering shell accounts or virtual machines is out of luck.

Re: GCC and Meltdown and Spectre vulnerabilities

2018-01-04 Thread Ian Lance Taylor via gcc
On Thu, Jan 4, 2018 at 7:14 PM, Zan Lynx  wrote:
>
> On January 4, 2018 8:10:14 PM MST, Eric Gallager  wrote:
>>Is there anything GCC could be doing at the compiler level to mitigate
>>the recently-announced Meltdown and Spectre vulnerabilities? From
>>reading about them, it seems like they involve speculative execution
>>and indirect branch prediction, and those are the domain of things the
>>compiler deals with, right? (For reference, Meltdown is CVE-2017-5754,
>>and Spectre is CVE-2017-5753 and CVE-2017-5715)
>>
>>Just wondering,
>>Eric
>
> If you're allowing people to run untrustworthy machine code on your hardware 
> there's nothing a compiler can do to help. You'd need to make them use your 
> compiler, and why would they?
>
> So anyone offering shell accounts or virtual machines is out of luck.

For the Spectre attack, a compiler can help by using it to compile
accessible programs in such a way that they are not vulnerable to the
attack.

Ian


[question] replacing called function by gimple_call_set_fndecl doesn't actually take effect

2018-01-04 Thread Tong Zhou
Hi,

I am new to gcc and was trying to implement a gimple pass today. One thing
I tried to do was to make a call_stat that originally calls malloc call
another function like new_malloc. I used gimple_call_set_fndecl and also
did update_stmt (although I don't know exactly what it does). But the final
assembly code still calls the old function. The relevant code is as follows:


  tree malloc_fn_type
  = build_function_type_list (void_type_node, size_type_node,
NULL_TREE);
  tree new_malloc = build_fn_decl("new_malloc", malloc_fn_type);

  struct cgraph_node *alloc_node = my_get_malloc_node();
  struct cgraph_edge *edge = NULL;
  struct cgraph_node *caller = NULL;

  for (edge = alloc_node->callers; edge; edge = edge->next_caller)
  {
gimple callStmt = edge->call_stmt;
gimple_call_set_fndecl(callStmt, new_malloc);
update_stmt (callStmt);
  }


The callee was indeed the new_malloc when I use debug_gimple_stmt to print
the call_stmt out, but the generated assembly code or dumped gimble file
still use the old malloc. Thanks in advance!

Thanks,
Tong


Re: Nested-Functions

2018-01-04 Thread Alexsandr Yvarov
Thanks Jonathan! 
Hm... why would don't add it for portability? Of course, i don't see codes with 
Nested-Functions so much, but... 
I think that better would delete it, or add full support?
And, it's contradicts to standart of C, nope?:)
~~~
About lambda:
Yeah is very pooowerful, of course. Is true.

#include

void fcn(int n=100){
int i;
auto f = [&i,n]{ i=n; };
f();
std::cout << i << ":" << n << std::endl;
}
int main(void){
fcn();
}
||
#include
void fcn(void){
int i;

void ofcn(void){
i=100;
}

ofcn();
printf("%d\n",i);

}

int main(void){
fcn();
}


04.01.2018, 06:05, "Jonathan Wakely" :
> On 3 January 2018 at 21:13, Alexsandr Yvarov wrote:
>>  Why would dont add it at GNU G++?
>
> Aren't C++ lambda expressions more powerful and flexible?


Re: Build Ada compiler for nios2?

2018-01-04 Thread Sebastian Huber

On 04/01/18 16:03, Andreas Schwab wrote:

On Jan 04 2018, Sebastian Huber  wrote:


/home/sh/src/gcc/gcc/config/nios2/nios2.h:436:31: error: expected '=',
',', ';', 'asm' or '__attribute__' before 'nios2_section_threshold'
  extern unsigned HOST_WIDE_INT nios2_section_threshold;

Change the preprocessor conditional to check USED_FOR_TARGET instead of
IN_LIBGCC2.


Thanks, this worked:

nios2-rtems5-gnat --version
GNAT 8.0.0 20180105 (experimental) [master revision 
9b012eb:c9100e4:1c579c0e17cba22beb7bd87244d1148784c52dab]

Copyright (C) 1996-2018, Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A 
PARTICULAR PURPOSE.


--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail  : sebastian.hu...@embedded-brains.de
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.



Can GCC generate totally native Microsoft Windows binaries as Visual Studio?

2018-01-04 Thread timofonic timofonic
Hello.

Excuse me my ignorance, but that's what people say me.

GCC can compile to Microsoft Windows platforms, I understand it. But
people say me it uses a "shim" between *nix and native Microsoft
Windows API.

Some developers said me GCC on Windows is a "toy compiler".

Is this right?

Kind regards.


Re: GCC and Meltdown and Spectre vulnerabilities

2018-01-04 Thread timofonic timofonic
Paranoid jails/sandboxes inside a virtual machine may mitigate a lot
the risk for those untrusted binaries, right? Plus using a debugger
and maybe an antivirus (I don't trust them so much and prefer to
isolate them too)?

What about already built software? Can those be "fixed"? What about
GLibC? What about some kind of patching or conversion?

2018-01-04 23:04 GMT-05:00 Ian Lance Taylor via gcc :
> On Thu, Jan 4, 2018 at 7:14 PM, Zan Lynx  wrote:
>>
>> On January 4, 2018 8:10:14 PM MST, Eric Gallager  
>> wrote:
>>>Is there anything GCC could be doing at the compiler level to mitigate
>>>the recently-announced Meltdown and Spectre vulnerabilities? From
>>>reading about them, it seems like they involve speculative execution
>>>and indirect branch prediction, and those are the domain of things the
>>>compiler deals with, right? (For reference, Meltdown is CVE-2017-5754,
>>>and Spectre is CVE-2017-5753 and CVE-2017-5715)
>>>
>>>Just wondering,
>>>Eric
>>
>> If you're allowing people to run untrustworthy machine code on your hardware 
>> there's nothing a compiler can do to help. You'd need to make them use your 
>> compiler, and why would they?
>>
>> So anyone offering shell accounts or virtual machines is out of luck.
>
> For the Spectre attack, a compiler can help by using it to compile
> accessible programs in such a way that they are not vulnerable to the
> attack.
>
> Ian