improve syntax errors

2019-01-03 Thread Daniel Marjamäki
Hello!

I have used GCC for decades and would like to contribute a little. :-)

I would like to see if I can improve the syntax errors.

Here is one example code:

int x = 3) + 0;

I have created this ugly experimental patch:

--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -2228,7 +2228,10 @@ c_parser_declaration_or_fndef (c_parser
*parser, bool fndef_ok,
}
  else
{
- c_parser_error (parser, "expected %<,%> or %<;%>");
+ if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
+   c_parser_error (parser, "extraneous )");
+ else
+   c_parser_error (parser, "expected %<,%> or %<;%>");
  c_parser_skip_to_end_of_block_or_statement (parser);
  return;
}

Before my patch:
test1.c:3:12: error: expected ‘,’ or ‘;’ before ‘)’ token

After my patch:
test1.c:3:12: error: extraneous ) before ‘)’ token

That is not perfect neither.

I have 2 questions..
 * can somebody give me a hint how I improve the error message so it
does not say "before ) token"?
 * how do I run the tests?

Basically I want that when there is a unmatched extra ) or } or ] then
it should just say "extraneous .." instead of "expected ',' or ';'.
Adding a ',' or ';' in the example code will not fix the syntax error.

Best regards,
Daniel Marjamäki


Re: improve syntax errors

2019-01-03 Thread David Malcolm
On Thu, 2019-01-03 at 15:59 +0100, Daniel Marjamäki wrote:
> Hello!
> 
> I have used GCC for decades and would like to contribute a little. :-
> )

Hi, and welcome!

> I would like to see if I can improve the syntax errors.
> 
> Here is one example code:
> 
> int x = 3) + 0;
> 
> I have created this ugly experimental patch:
> 
> --- a/gcc/c/c-parser.c
> +++ b/gcc/c/c-parser.c
> @@ -2228,7 +2228,10 @@ c_parser_declaration_or_fndef (c_parser
> *parser, bool fndef_ok,
> }
>   else
> {
> - c_parser_error (parser, "expected %<,%> or %<;%>");
> + if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
> +   c_parser_error (parser, "extraneous )");
> + else
> +   c_parser_error (parser, "expected %<,%> or %<;%>");
>   c_parser_skip_to_end_of_block_or_statement (parser);
>   return;
> }
> 
> Before my patch:
> test1.c:3:12: error: expected ‘,’ or ‘;’ before ‘)’ token
> 
> After my patch:
> test1.c:3:12: error: extraneous ) before ‘)’ token

> That is not perfect neither.

Thanks for trying it out.

A minor nit: the ")" is a source code construct and thus should be
quoted in the message, by wrapping it in %< and %> like in the existing
code:

  c_parser_error (parser, "extraneous %<)%>");

or by using %qs to quote a const const *:

  c_parser_error (parser, "extraneous %qs", ")");


(FWIW, the word "extraneous" seems a bit "jargony" to me, how about
"stray %qs token"?  (giving: "error: stray ')' token")   I'm not sure
though)

> I have 2 questions..
>  * can somebody give me a hint how I improve the error message so it
> does not say "before ) token"?

The before ')' token is being supplied due to the use of
c_parser_error, which calls c_parse_error, which adds a
  "before SOMETHING"
suffix to the message before calling into the diagnostic subsystem. 
You could use:

  error_at (token->location, "some message");

to go directly to the underlying diagnostic API to avoid getting the
"before SOMETHING" suffix.

>  * how do I run the tests?

You might want to look at this guide I put together:
  https://dmalcolm.fedorapeople.org/gcc/newbies-guide/index.html
which among other things has some notes on running tests (and writing
new ones), and on stepping through gcc in a debugger.

> Basically I want that when there is a unmatched extra ) or } or ]
> then
> it should just say "extraneous .." instead of "expected ',' or ';'.
> Adding a ',' or ';' in the example code will not fix the syntax
> error.

I wonder how much we want to special-case this.  Are you thinking about
the case where there's a stray symbol in the code (perhaps due to a
stray keypress, or unfinished manual edits)?   Perhaps we could have a
predicate for determining if a token can never make sense in the given
context, and have something like:

if (c_parser_next_token_is_meaningless_p (parser))
  complain_about_stray_token (parser);
else
  ...

or somesuch (we use a "_p" suffix for predicates).

It might make sense to emit a fix-it hint suggesting the removal of the
stray token.

Much of these ideas could probably apply to the C++ frontend as well
(annoyingly, not much of this code is shared between C and C++).

> Best regards,
> Daniel Marjamäki

Hope this is helpful, and welcome again.

Dave


Re: improve syntax errors

2019-01-03 Thread Jonathan Wakely
On Thu, 3 Jan 2019 at 15:40, David Malcolm wrote:
>
> On Thu, 2019-01-03 at 15:59 +0100, Daniel Marjamäki wrote:
> > Hello!
> >
> > I have used GCC for decades and would like to contribute a little. :-
> > )
>
> Hi, and welcome!
>
> > I would like to see if I can improve the syntax errors.
> >
> > Here is one example code:
> >
> > int x = 3) + 0;
> >
> > I have created this ugly experimental patch:
> >
> > --- a/gcc/c/c-parser.c
> > +++ b/gcc/c/c-parser.c
> > @@ -2228,7 +2228,10 @@ c_parser_declaration_or_fndef (c_parser
> > *parser, bool fndef_ok,
> > }
> >   else
> > {
> > - c_parser_error (parser, "expected %<,%> or %<;%>");
> > + if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
> > +   c_parser_error (parser, "extraneous )");
> > + else
> > +   c_parser_error (parser, "expected %<,%> or %<;%>");
> >   c_parser_skip_to_end_of_block_or_statement (parser);
> >   return;
> > }
> >
> > Before my patch:
> > test1.c:3:12: error: expected ‘,’ or ‘;’ before ‘)’ token
> >
> > After my patch:
> > test1.c:3:12: error: extraneous ) before ‘)’ token
>
> > That is not perfect neither.
>
> Thanks for trying it out.
>
> A minor nit: the ")" is a source code construct and thus should be
> quoted in the message, by wrapping it in %< and %> like in the existing
> code:
>
>   c_parser_error (parser, "extraneous %<)%>");
>
> or by using %qs to quote a const const *:
>
>   c_parser_error (parser, "extraneous %qs", ")");
>
>
> (FWIW, the word "extraneous" seems a bit "jargony" to me, how about
> "stray %qs token"?  (giving: "error: stray ')' token")   I'm not sure
> though)

Maybe "unmatched"?

> > I have 2 questions..
> >  * can somebody give me a hint how I improve the error message so it
> > does not say "before ) token"?
>
> The before ')' token is being supplied due to the use of
> c_parser_error, which calls c_parse_error, which adds a
>   "before SOMETHING"
> suffix to the message before calling into the diagnostic subsystem.
> You could use:
>
>   error_at (token->location, "some message");
>
> to go directly to the underlying diagnostic API to avoid getting the
> "before SOMETHING" suffix.
>
> >  * how do I run the tests?
>
> You might want to look at this guide I put together:
>   https://dmalcolm.fedorapeople.org/gcc/newbies-guide/index.html
> which among other things has some notes on running tests (and writing
> new ones), and on stepping through gcc in a debugger.
>
> > Basically I want that when there is a unmatched extra ) or } or ]
> > then
> > it should just say "extraneous .." instead of "expected ',' or ';'.
> > Adding a ',' or ';' in the example code will not fix the syntax
> > error.
>
> I wonder how much we want to special-case this.  Are you thinking about
> the case where there's a stray symbol in the code (perhaps due to a
> stray keypress, or unfinished manual edits)?   Perhaps we could have a
> predicate for determining if a token can never make sense in the given
> context, and have something like:
>
> if (c_parser_next_token_is_meaningless_p (parser))
>   complain_about_stray_token (parser);
> else
>   ...
>
> or somesuch (we use a "_p" suffix for predicates).

Right, why emit a special diagnostic for 3) but not 3]?


Re: syntax errors

2019-01-03 Thread Daniel Marjamäki
Thank you for the quick reply.

> how about "stray %qs token"?

I will change.

> I wonder how much we want to special-case this. Are you thinking about
> the case where there's a stray symbol in the code (perhaps due to a
> stray keypress, or unfinished manual edits)?

At the moment I only think about ) } ]

I would like to focus on only those 3 to start with. but it sounds
good to prepare for more stray tokens later.

> if (c_parser_next_token_is_meaningless_p (parser))
>   complain_about_stray_token (parser);
> else
>   ...

sure!

> It might make sense to emit a fix-it hint suggesting the removal of the
> stray token.

It is 50% chance that the closing paranthesis should be removed. Maybe
there is a missing "(".

Maybe the error message should indicate that.. something like "either
there is missing "(" or this ")" is a stray token".

Best regards,
Daniel Marjamäki


Mais praticidade para suas compras online.

2019-01-03 Thread Santander
http://tr.santander.com.br/f/a/PPmjU4rVj0zTRnyGYvUq3A~~/AQA~/RgReEMorP0Q4aHR0cDovL3d3dy53My5vcmcvVFIveGh0bWwxL0RURC94aHRtbDEtdHJhbnNpdGlvbmFsLmR0ZCJXBXVuZWFyQgoAAitFLlxZy7umUgtnY2NAZ251Lm9yZ1gEAA~~>
http://tr.santander.com.br/f/a/bMOvSvHWQ1mS1duk35pSMw~~/AQA~/RgReEMorP0QdaHR0cDovL3d3dy53My5vcmcvMTk5OS94aHRtbCJXBXVuZWFyQgoAAitFLlxZy7umUgtnY2NAZ251Lm9yZ1gEAA~~>


Mais praticidade para suas compras online. 





Mais praticidade para suas compras 
online.



  
http://tr.santander.com.br/f/a/qOPX2TC57dysBXs2ymna7A~~/AQA~/RgReEMorP0Q4aHR0cHM6Ly93d3cuc2FudGFuZGVyLmNvbS5ici9uZXdzbGV0dGVyLzEwNjM3OGIvaW1nLmpwZyJXBXVuZWFyQgoAAitFLlxZy7umUgtnY2NAZ251Lm9yZ1gEAA~~
 width="117" height="72" border="0" style="display:block; border:0;" 
/>
  
  

  
 
ROSA,


  
  
http://tr.santander.com.br/f/a/cMMr3-h53Cb6kyDNSapR6g~~/AQA~/RgReEMorP0Q6aHR0cHM6Ly93d3cuc2FudGFuZGVyLmNvbS5ici9uZXdzbGV0dGVyLzEwNjM3OGIvaW1nMDIuanBnIlcFdW5lYXJCCgACK0UuXFnLu6ZSC2djY0BnbnUub3JnWAQA
 width="596" height="168" border="0" style="display:block; border:0;" />
  
  
http://tr.santander.com.br/f/a/FcovhG5MZd9yYxkJ4VUOMA~~/AQA~/RgReEMorP0Q6aHR0cHM6Ly93d3cuc2FudGFuZGVyLmNvbS5ici9uZXdzbGV0dGVyLzEwNjM3OGIvaW1nMDMuanBnIlcFdW5lYXJCCgACK0UuXFnLu6ZSC2djY0BnbnUub3JnWAQA
 alt="" width="596" height="307" style="display:block; border:0;" border="0" 
/>
  
  

  
http://tr.santander.com.br/f/a/7TOYWXg2ORAZ_qegKdhgcA~~/AQA~/RgReEMorP0Q4aHR0cHM6Ly93d3cuc2FudGFuZGVyLmNvbS5ici9uZXdzbGV0dGVyLzEwNjM3OGIvdHh0LmpwZyJXBXVuZWFyQgoAAitFLlxZy7umUgtnY2NAZ251Lm9yZ1gEAA~~
 alt="" width="596" height="280" style="display:block; border:0;" border="0" 
/>
  
  
 
  
  
http://tr.santander.com.br/f/a/1VlJSmg6wql_-lvuDklHoA~~/AQA~/RgReEMorP0Q6aHR0cHM6Ly93d3cuc2FudGFuZGVyLmNvbS5ici9uZXdzbGV0dGVyLzEwNjM3OGIvaW1nMDQuanBnIlcFdW5lYXJCCgACK0UuXFnLu6ZSC2djY0BnbnUub3JnWAQA
 alt="" width="596" height="100" style="display:block; border:0;" border="0" 
/>

  
 
  

  
  
  
  
  
  
  
  
  
  
  
  
http://tr.santander.com.br/f/a/VZlkt9NOyFHlKVkCEmHG1w~~/AQA~/RgReEMorP0Q6aHR0cHM6Ly93d3cuc2FudGFuZGVyLmNvbS5ici9uZXdzbGV0dGVyLzEwNjM3OGIvaW1nMDUuanBnIlcFdW5lYXJCCgACK0UuXFnLu6ZSC2djY0BnbnUub3JnWAQA
 width="596" height="317" border="0" style="display:block; border:0;" />
  
  
19530898
  
  
 
  
  
http://tr.santander.com.br/f/a/b6PM0HXEU1d30u_PHUrRKQ~~/AQA~/RgReEMorP0Q6aHR0cHM6Ly93d3cuc2FudGFuZGVyLmNvbS5ici9uZXdzbGV0dGVyLzEwNjM3OGIvaW1nMDYuanBnIlcFdW5lYXJCCgACK0UuXFnLu6ZSC2djY0BnbnUub3JnWAQA
 alt="" width="596" height="100" style="display:block; border:0;" border="0" 
/>
  

http://tr.santander.com.br/f/a/tgwtFNzhUPNo4BtXf6fv0g~~/AQA~/RgReEMorP0R6aHR0cHM6Ly93ZWJzZXJ2aWNlLnVjYW1wYWlnbi51bmVhci5uZXQvVW1haWxUcmFja2luZy90LmFzcHg_cD03NzYyMjMwNTkmYz1NVEEwTkRjMU1RPT0mdXA9NTcxNzA3NzAyJmU9Z2NjQGdudS5vcmcmbD1NREU9JiJXBXVuZWFyQgoAAitFLlxZy7umUgtnY2NAZ251Lm9yZ1gEAA~~
 />



Re: syntax errors

2019-01-03 Thread Jonathan Wakely
On Thu, 3 Jan 2019 at 17:03, Daniel Marjamäki
 wrote:
>
> Thank you for the quick reply.
>
> > how about "stray %qs token"?
>
> I will change.
>
> > I wonder how much we want to special-case this. Are you thinking about
> > the case where there's a stray symbol in the code (perhaps due to a
> > stray keypress, or unfinished manual edits)?
>
> At the moment I only think about ) } ]
>
> I would like to focus on only those 3 to start with. but it sounds
> good to prepare for more stray tokens later.

It doesn't scale to write a custom diagnostic for every invalid input
character in every context.


Mtrace with no environment MALLOC_TRACE feature request mtrace_setpath.

2019-01-03 Thread Joseph Howard
Request for mtrace_setpath


In debugging and profiling PAM (Pluggable Authentication Modules) modules for 
memory leaks in linux, mtrace cannot access environment variables as these do 
not exist until the authentication completes (e.g. /etc/environment . The 
MALLOC_TRACE path can only be supplied as an environment variable. Please add a 
feature to allow the passing of a trace path to mtrace. The module workaround 
is to add putenv("MALLOC_TRACE=/var/log/mypammemleak.log");


Globally changing the linux environment values to trace a security module 
should not be an answer.


Please consider adding a mtrace_setpath(const char* path);


Note : pam_env.so creates environment variables afterward. I've checked 
everything other than rebuilding PAM.

Module order does not matter.



Joe


Re: Mtrace with no environment MALLOC_TRACE feature request mtrace_setpath.

2019-01-03 Thread Jonathan Wakely
On Thu, 3 Jan 2019 at 21:18, Joseph Howard wrote:
>
> Request for mtrace_setpath

I think you should have sent this to glibc, which is a completely
separate project to GCC.

See https://www.gnu.org/software/libc/libc.html


gcc-7-20190103 is now available

2019-01-03 Thread gccadmin
Snapshot gcc-7-20190103 is now available on
  ftp://gcc.gnu.org/pub/gcc/snapshots/7-20190103/
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 267565

You'll find:

 gcc-7-20190103.tar.xzComplete GCC

  SHA256=9f8043c1ba5923ebbbf0a5ae1ab854aceed26232ed19a16920b554d283928327
  SHA1=c2776c7a476936c348a52fbe8172c15407c7cad8

Diffs from 7-20181227 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.


Re: improve syntax errors

2019-01-03 Thread Martin Sebor

On 1/3/19 8:40 AM, David Malcolm wrote:

On Thu, 2019-01-03 at 15:59 +0100, Daniel Marjamäki wrote:

Hello!

I have used GCC for decades and would like to contribute a little. :-
)


Hi, and welcome!


I would like to see if I can improve the syntax errors.

Here is one example code:

 int x = 3) + 0;

I have created this ugly experimental patch:

--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -2228,7 +2228,10 @@ c_parser_declaration_or_fndef (c_parser
*parser, bool fndef_ok,
 }
   else
 {
- c_parser_error (parser, "expected %<,%> or %<;%>");
+ if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
+   c_parser_error (parser, "extraneous )");
+ else
+   c_parser_error (parser, "expected %<,%> or %<;%>");
   c_parser_skip_to_end_of_block_or_statement (parser);
   return;
 }

Before my patch:
test1.c:3:12: error: expected ‘,’ or ‘;’ before ‘)’ token

After my patch:
test1.c:3:12: error: extraneous ) before ‘)’ token



That is not perfect neither.


Thanks for trying it out.

A minor nit: the ")" is a source code construct and thus should be
quoted in the message, by wrapping it in %< and %> like in the existing
code:

   c_parser_error (parser, "extraneous %<)%>");

or by using %qs to quote a const const *:

   c_parser_error (parser, "extraneous %qs", ")");


I would suggest the quoted form since it means less work for message
translantors.  (Both forms are used in GCC messages but I think it
would be worth adopting the quoted form.)


(FWIW, the word "extraneous" seems a bit "jargony" to me, how about
"stray %qs token"?  (giving: "error: stray ')' token")   I'm not sure
though)


A helpful rule of thumb I like to use is checking which form is
prevalent in gcc/po/gcc.pot.  In this case, there's just one
message with the word "extraneous" in all of GCC and 7 that
use "stray."  There are also three messages that use the word
"unmatched", and for variety, five that use "unterminated" (not
all of them are interchangeable).

Martin


I have 2 questions..
  * can somebody give me a hint how I improve the error message so it
does not say "before ) token"?


The before ')' token is being supplied due to the use of
c_parser_error, which calls c_parse_error, which adds a
   "before SOMETHING"
suffix to the message before calling into the diagnostic subsystem.
You could use:

   error_at (token->location, "some message");

to go directly to the underlying diagnostic API to avoid getting the
"before SOMETHING" suffix.


  * how do I run the tests?


You might want to look at this guide I put together:
   https://dmalcolm.fedorapeople.org/gcc/newbies-guide/index.html
which among other things has some notes on running tests (and writing
new ones), and on stepping through gcc in a debugger.


Basically I want that when there is a unmatched extra ) or } or ]
then
it should just say "extraneous .." instead of "expected ',' or ';'.
Adding a ',' or ';' in the example code will not fix the syntax
error.


I wonder how much we want to special-case this.  Are you thinking about
the case where there's a stray symbol in the code (perhaps due to a
stray keypress, or unfinished manual edits)?   Perhaps we could have a
predicate for determining if a token can never make sense in the given
context, and have something like:

if (c_parser_next_token_is_meaningless_p (parser))
   complain_about_stray_token (parser);
else
   ...

or somesuch (we use a "_p" suffix for predicates).

It might make sense to emit a fix-it hint suggesting the removal of the
stray token.

Much of these ideas could probably apply to the C++ frontend as well
(annoyingly, not much of this code is shared between C and C++).


Best regards,
Daniel Marjamäki


Hope this is helpful, and welcome again.

Dave