Closed Bug 496055 Opened 15 years ago Closed 15 years ago

Dehydra warnings / errors don't provide function information

Categories

(Developer Infrastructure :: Source Code Analysis, defect)

x86
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: bradh, Assigned: taras.mozilla)

Details

Attachments

(1 file)

User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.10) Gecko/2009042708 Fedora/3.0.10-1.fc9 Firefox/3.0.10
Build Identifier: 

Here is an example I've been working with
[bradh@conferta tutorial1]$ cat error_strcpy_process.js
function process(statement_items) {
  for each (var statement in statement_items) {
    if (statement.shortName == "strcpy" && statement.isFunction) {
      error("Use of strcpy()");
    }
  }
}
[bradh@conferta tutorial1]$
[bradh@conferta tutorial1]$ cat tutorial1.h
char *strcpy(char *dest, const char *src);
char *xstrcpy(char *dest, const char *src);
[bradh@conferta tutorial1]$
[bradh@conferta tutorial1]$ cat tutorial1.cc
#include "tutorial1.h"

char* do_something(bool useFirst, char* first, char* second)
{
    char* my_copy;
    if (useFirst) {
        xstrcpy(my_copy, first);
    } else {
        strcpy ( my_copy, second);
    }
    return my_copy;
}
[bradh@conferta tutorial1]$
[bradh@conferta tutorial1]$ ~/devel/installed/bin/g++ -Wall -fplugin=../../gcc_dehydra.so -fplugin-arg-gcc_dehydra-=error_strcpy_process.js -c tutorial1.cc -o /dev/null
tutorial1.cc: In function ‘char* do_something(bool, char*, char*)’:
tutorial1.cc:7: warning: ‘my_copy’ may be used uninitialized in this function
tutorial1.cc: At global scope:
tutorial1.cc:9: error: Use of strcpy()

Note that the second last line of the output (produced by dehydra) is 
"tutorial1.cc: At global scope:" while normal gcc warnings have "tutorial1.cc: In function ‘char* do_something(bool, char*, char*)’:"

It would be better if we provided the function details.

Reproducible: Always
I did some investigation into gcc, and the applicable code is in gcc/cp/error.c
It looks like:
     if (current_function_decl == NULL)
        pp_base_string (context->printer, _("At global scope:"));
      else

Now current_function_decl is a tree, so presumably we'd need to copy the structure, and put it back just prior to calling error() or warning().

The only other thing I can think of is to generate our own output code, but that seems worse.
If your diagnostics are right, then this should help
Assignee: nobody → tglek
Works well for me. It shows the correct location and function, and merges errors/warnings from gcc with dehydra.

I request that this patch be applied.
http://hg.mozilla.org/users/tglek_mozilla.com/dehydra-gcc/rev/2c8a52735374
Status: UNCONFIRMED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Product: Core → Firefox Build System
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: