public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre Vittet <piervit@pvittet.com>
To: gcc@gcc.gnu.org, Basile Starynkevitch <basile@starynkevitch.net>,
	 Alexandre Lissy <alissy@mandriva.com>,
	patrick.martineau@univ-tours.fr
Subject: [GSOC] Customizable warnings with a GCC plugin
Date: Fri, 12 Aug 2011 14:55:00 -0000	[thread overview]
Message-ID: <4E453EC2.1030600@pvittet.com> (raw)

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

             reply	other threads:[~2011-08-12 14:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-12 14:55 Pierre Vittet [this message]
2011-08-12 16:00 ` Jonathan Wakely
2011-08-13 11:09   ` Pierre Vittet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E453EC2.1030600@pvittet.com \
    --to=piervit@pvittet.com \
    --cc=alissy@mandriva.com \
    --cc=basile@starynkevitch.net \
    --cc=gcc@gcc.gnu.org \
    --cc=patrick.martineau@univ-tours.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).