Skip to content

Commit

Permalink
cswrap: handle <scratch space> placeholder for path in Clang's note msgs
Browse files Browse the repository at this point in the history
Reported-by: Tomas Popela
  • Loading branch information
kdudka committed Jul 25, 2018
1 parent f5c3284 commit 7704be3
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cswrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ static int suppress_plain_lines;

static struct strlist *file_list;

static volatile sig_atomic_t use_pg;

/* print a warning/error message */
static void print_msg(const char *what, const char *fmt, va_list ap)
{
Expand Down Expand Up @@ -587,14 +589,20 @@ bool translate_line(char *buf, const char *tool)
return false;
}

if (-1 == access(buf, R_OK)) {
char *abs_path = NULL;
if (/* clang */ use_pg && STREQ(buf, "<scratch space>"))
/* clang uses <scratch space> as a placeholder for path in note msgs */
abs_path = strdup(buf);

if (!abs_path && (-1 == access(buf, R_OK))) {
/* the part up to the colon does not specify a file we can access */
*colon = ':';
return false;
}

/* canonicalize the file name and restore the previously replaced colon */
char *abs_path = canonicalize_file_name(buf);
if (!abs_path)
abs_path = canonicalize_file_name(buf);
if (!abs_path && (ENOENT == errno) && (0 == access(buf, R_OK)))
/* work around glibc/valgrind bug that causes realpath() to occasionally
* fail with ENOENT for no reason */
Expand Down Expand Up @@ -651,7 +659,6 @@ void trans_paths_to_abs(const char *tool)
}

static volatile pid_t tool_pid;
static volatile sig_atomic_t use_pg;
static volatile sig_atomic_t timed_out;

void signal_handler(int signum)
Expand Down
4 changes: 4 additions & 0 deletions tests/0007-clang-notes-filtering/clang++--analyze-stderr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ src/browser.c:269:20: warning: comparison between signed and unsigned integer ex
src/files.c:499:2: warning: Function call argument is an uninitialized value <--[clang++]
# read_file(f, rc, realname, undoable, new_buffer);
# ^ ~

src/files.c:427:37: warning: The left operand of '+' is a garbage value <--[clang++]
float min_cost = (posdata->cost + ZopfliCostModelGetMinCostCmd(model) +
^
19 changes: 19 additions & 0 deletions tests/0007-clang-notes-filtering/clang++-c-cswrap.out
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,22 @@ src/files.c:498:5: note: Taking true branch <--[clang++]
src/files.c:499:2: note: Function call argument is an uninitialized value <--[clang++]
# read_file(f, rc, realname, undoable, new_buffer);
# ^ ~

src/files.c:427:37: warning: The left operand of '+' is a garbage value <--[clang++]
float min_cost = (posdata->cost + ZopfliCostModelGetMinCostCmd(model) +
^
src/files.c:458:30: note: expanded from macro 'BROTLI_MIN' <--[clang++]
#define BROTLI_MIN(T, A, B) (brotli_min_ ## T((A), (B)))
^~~~~~~~~~~~~~~~~~~~~~~~~~
<scratch space>:188:1: note: expanded from here <--[clang++]
brotli_min_size_t
^
src/files.c:415:33: note: Calling 'MaxZopfliLen' <--[clang++]
const size_t max_zopfli_len = MaxZopfliLen(params);
^~~~~~~~~~~~~~~~~~~~
src/files.c:48:10: note: '?' condition is false <--[clang++]
return params->quality <= 10 ?
^
src/files.c:415:33: note: Returning from 'MaxZopfliLen' <--[clang++]
const size_t max_zopfli_len = MaxZopfliLen(params);
^~~~~~~~~~~~~~~~~~~~
4 changes: 4 additions & 0 deletions tests/0007-clang-notes-filtering/clang--analyze-stderr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ src/browser.c:269:20: warning: comparison between signed and unsigned integer ex
src/files.c:499:2: warning: Function call argument is an uninitialized value <--[clang]
# read_file(f, rc, realname, undoable, new_buffer);
# ^ ~

src/files.c:427:37: warning: The left operand of '+' is a garbage value <--[clang]
float min_cost = (posdata->cost + ZopfliCostModelGetMinCostCmd(model) +
^
19 changes: 19 additions & 0 deletions tests/0007-clang-notes-filtering/clang-c-cswrap.out
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,22 @@ src/files.c:498:5: note: Taking true branch <--[clang]
src/files.c:499:2: note: Function call argument is an uninitialized value <--[clang]
# read_file(f, rc, realname, undoable, new_buffer);
# ^ ~

src/files.c:427:37: warning: The left operand of '+' is a garbage value <--[clang]
float min_cost = (posdata->cost + ZopfliCostModelGetMinCostCmd(model) +
^
src/files.c:458:30: note: expanded from macro 'BROTLI_MIN' <--[clang]
#define BROTLI_MIN(T, A, B) (brotli_min_ ## T((A), (B)))
^~~~~~~~~~~~~~~~~~~~~~~~~~
<scratch space>:188:1: note: expanded from here <--[clang]
brotli_min_size_t
^
src/files.c:415:33: note: Calling 'MaxZopfliLen' <--[clang]
const size_t max_zopfli_len = MaxZopfliLen(params);
^~~~~~~~~~~~~~~~~~~~
src/files.c:48:10: note: '?' condition is false <--[clang]
return params->quality <= 10 ?
^
src/files.c:415:33: note: Returning from 'MaxZopfliLen' <--[clang]
const size_t max_zopfli_len = MaxZopfliLen(params);
^~~~~~~~~~~~~~~~~~~~
19 changes: 19 additions & 0 deletions tests/0007-clang-notes-filtering/gcc-c-cswrap.out
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,22 @@ src/files.c:498:5: note: Taking true branch <--[gcc]
src/files.c:499:2: note: Function call argument is an uninitialized value <--[gcc]
# read_file(f, rc, realname, undoable, new_buffer);
# ^ ~

src/files.c:427:37: warning: The left operand of '+' is a garbage value <--[gcc]
float min_cost = (posdata->cost + ZopfliCostModelGetMinCostCmd(model) +
^
src/files.c:458:30: note: expanded from macro 'BROTLI_MIN' <--[gcc]
#define BROTLI_MIN(T, A, B) (brotli_min_ ## T((A), (B)))
^~~~~~~~~~~~~~~~~~~~~~~~~~
<scratch space>:188:1: note: expanded from here
brotli_min_size_t
^
src/files.c:415:33: note: Calling 'MaxZopfliLen' <--[gcc]
const size_t max_zopfli_len = MaxZopfliLen(params);
^~~~~~~~~~~~~~~~~~~~
src/files.c:48:10: note: '?' condition is false <--[gcc]
return params->quality <= 10 ?
^
src/files.c:415:33: note: Returning from 'MaxZopfliLen' <--[gcc]
const size_t max_zopfli_len = MaxZopfliLen(params);
^~~~~~~~~~~~~~~~~~~~
19 changes: 19 additions & 0 deletions tests/0007-clang-notes-filtering/input.err
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,22 @@ src/files.c:498:5: note: Taking true branch
src/files.c:499:2: note: Function call argument is an uninitialized value
# read_file(f, rc, realname, undoable, new_buffer);
# ^ ~

src/files.c:427:37: warning: The left operand of '+' is a garbage value
float min_cost = (posdata->cost + ZopfliCostModelGetMinCostCmd(model) +
^
src/files.c:458:30: note: expanded from macro 'BROTLI_MIN'
#define BROTLI_MIN(T, A, B) (brotli_min_ ## T((A), (B)))
^~~~~~~~~~~~~~~~~~~~~~~~~~
<scratch space>:188:1: note: expanded from here
brotli_min_size_t
^
src/files.c:415:33: note: Calling 'MaxZopfliLen'
const size_t max_zopfli_len = MaxZopfliLen(params);
^~~~~~~~~~~~~~~~~~~~
src/files.c:48:10: note: '?' condition is false
return params->quality <= 10 ?
^
src/files.c:415:33: note: Returning from 'MaxZopfliLen'
const size_t max_zopfli_len = MaxZopfliLen(params);
^~~~~~~~~~~~~~~~~~~~

0 comments on commit 7704be3

Please sign in to comment.