Dehydra warnings / errors don't provide function information




Rewriting and Analysis
9 years ago
9 years ago


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


Firefox Tracking Flags

(Not tracked)



(1 attachment)



9 years ago
User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: 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
#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=../../ -fplugin-arg-gcc_dehydra-=error_strcpy_process.js -c -o /dev/null In function ‘char* do_something(bool, char*, char*)’: warning: ‘my_copy’ may be used uninitialized in this function At global scope: error: Use of strcpy()

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

It would be better if we provided the function details.

Reproducible: Always

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:"));

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.

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

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.

Comment 4

9 years ago
Last Resolved: 9 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.