public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [GSOC] Customizable warnings with a GCC plugin
@ 2011-08-12 14:55 Pierre Vittet
  2011-08-12 16:00 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Pierre Vittet @ 2011-08-12 14:55 UTC (permalink / raw)
  To: gcc, Basile Starynkevitch, Alexandre Lissy, patrick.martineau

Hello,

As the GSOC ending is approching, I tried on a real project (GNU Grub)
the plugin that I am developping.

This plugin allows the user to add warnings when compiling, depending of
rules that he has previously written. Here is an exemple of possible rules :

(testNull "grub_malloc")
	This means that when there is a call to function "grub_malloc", we will
check that it is immediately followed by a condition, testing that what
was returned by grub_malloc was (not) null.

(testNull "grub_malloc")

We also have operator testZero and test testNeg, allowing to work on
functions that return int.

We could also use such rule (event if it is quite unusual):
(testNull "function_that_modify_first_arg" 1)
It means that instead of testing that there is a condition on the result
of the function, we test that there is a test on the first argument of
the function.
Using this feature has more sense with the following type of test:

(testFollowedBy "grub_bufio_open" 0 "grub_bufio_close" 1)

This means that in a function body, if you have a call to the function
"grub_bufio_open", we will check that the returned variable (0) is later
tested to be first argument (1) of a call to grub_bufio_close.

There is also a testNotFollowedBy working the same way which emit a
warning if the first function is followed by the second one.

The last kind of test is "testImmediatlyFollowedBy" testing that a call
to a function is immediatly followed by a call to another one, for
exemple we might want to use :
(testImmediatlyFollowedBy "chroot" 1 "chdir" 1)

The plugin seems to return quite interesting warnings without to much
false positives. False positives comes from several particular
situations, for exemple for testFollowedBy, if you have someting like that:

int myFunction(void)
{
	void * myPtr = first_function_to_be_tested();
	if(something does not works)
	{
		return ERROR;	
	}
	second_function(myPtr);
	return 0;
}

It will return a warning as you can exit the function without running
second_function. The problem is that it is more a design problem than a
problem from the plugin.

If you want to see the detail of my result when running a few tests on
Grub, you can have a look on the grub mailing list :
https://lists.gnu.org/archive/html/grub-devel/2011-08/msg00009.html .

I would be glad to have your opinion on my plugin. Do you thing in can
be really useful in real project ? Would you use it ? Have you idea of
tests that we could run over GCC or another project ? I guess this can
be a pretty good tools, but it needs to have clear coding standard in
order to know what should be tested.

For the moment, the plugin has only be tested on C code, this might
works with only few changes for C++. It needed the following patchs
http://www.mail-archive.com/gcc-patches@gcc.gnu.org/msg13086.html which
had been commited yesterday + some changes in MELT (the plugin is
developped in MELT). Moreover as the plugin uses some newly added
functionalities of MELT, it might be quite hard to use until the release
of MELT 0.9 (which might be ready for the end of August). I have named
the plugin Talpo, it means mole in esperanto, the idea is that we dig
blindly into GCC finding the information we want, the project is
available here : https://gitorious.org/talpo. I will focus on
documentation and help next week.

Thanks for your interest!

Pierre Vittet

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

* Re: [GSOC] Customizable warnings with a GCC plugin
  2011-08-12 14:55 [GSOC] Customizable warnings with a GCC plugin Pierre Vittet
@ 2011-08-12 16:00 ` Jonathan Wakely
  2011-08-13 11:09   ` Pierre Vittet
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2011-08-12 16:00 UTC (permalink / raw)
  To: Pierre Vittet
  Cc: gcc, Basile Starynkevitch, Alexandre Lissy, patrick.martineau

On 12 August 2011 15:54, Pierre Vittet wrote:
>
> For the moment, the plugin has only be tested on C code, this might
> works with only few changes for C++.

Would your example tests for grub warn about the following C++ code?

struct Guard {
    Guard(void* p) : p(p) { if (!p) throw std::bad_alloc(); }
    ~Guard() { grub_free(p); }
    void* p;
};

void func(grub_size_t n)
{
    Guard g(grub_malloc(n));
    // do something with g.p
}

For it to be useful for C++ it would be necessary to not warn about that code.

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

* Re: [GSOC] Customizable warnings with a GCC plugin
  2011-08-12 16:00 ` Jonathan Wakely
@ 2011-08-13 11:09   ` Pierre Vittet
  0 siblings, 0 replies; 3+ messages in thread
From: Pierre Vittet @ 2011-08-13 11:09 UTC (permalink / raw)
  To: Jonathan Wakely
  Cc: gcc, Basile Starynkevitch, Alexandre Lissy, patrick.martineau

Hello,

thanks for you mail. You are right my plugin returns a 'false' warning
on your case. That should be possible to handle this case but it needs
some search: when parsing func,we should request to look at the Guard
constructor (either by inserting a new pass or maybe by using LTO (but I
should look deeper at this)) to check if there is a test or no.

For the moment my plugin's 'view' is limited to a single function but
that should be something to improve.

Pierre Vittet

On 12/08/2011 18:00, Jonathan Wakely wrote:
> On 12 August 2011 15:54, Pierre Vittet wrote:
>>
>> For the moment, the plugin has only be tested on C code, this might
>> works with only few changes for C++.
> 
> Would your example tests for grub warn about the following C++ code?
> 
> struct Guard {
>     Guard(void* p) : p(p) { if (!p) throw std::bad_alloc(); }
>     ~Guard() { grub_free(p); }
>     void* p;
> };
> 
> void func(grub_size_t n)
> {
>     Guard g(grub_malloc(n));
>     // do something with g.p
> }
> 
> For it to be useful for C++ it would be necessary to not warn about that code.
> 

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

end of thread, other threads:[~2011-08-13 11:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-12 14:55 [GSOC] Customizable warnings with a GCC plugin Pierre Vittet
2011-08-12 16:00 ` Jonathan Wakely
2011-08-13 11:09   ` Pierre Vittet

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