Dehydra warnings / errors don't provide function information

RESOLVED FIXED

Status

()

Core
Rewriting and Analysis
RESOLVED FIXED
9 years ago
9 years ago

People

(Reporter: Brad Hards, Assigned: (dormant account))

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

9 years ago
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
(Reporter)

Comment 1

9 years ago
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.
(Assignee)

Comment 2

9 years ago
Created attachment 381611 [details] [diff] [review]
set current function 

If your diagnostics are right, then this should help
Assignee: nobody → tglek
(Reporter)

Comment 3

9 years ago
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.
(Assignee)

Comment 4

9 years ago
http://hg.mozilla.org/users/tglek_mozilla.com/dehydra-gcc/rev/2c8a52735374
Status: UNCONFIRMED → RESOLVED
Last Resolved: 9 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.