[Bug tree-optimization/100417] False positive -Wmaybe-uninitalized with malloc.

2021-05-04 Thread jmarshall at hey dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100417

--- Comment #2 from John Marshall  ---
See also https://github.com/samtools/htslib/pull/1275#issuecomment-831799708
(onwards) and https://github.com/samtools/htslib/pull/1280 for the initial
observation of this in James's original code. The diagnostic message was

cram/cram_codecs.c: In function 'cram_xdelta_encode_char':
cram/cram_codecs.c:1916:19: error: 'cp_end' may be used uninitialized
[-Werror=maybe-uninitialized]
 1916 | cp += c->vv->varint_put32(cp, cp_end,
zigzag16(c->u.e_xdelta.last));

which initially misled us into investigating the cp_end pointer itself's
initialisation. IMHO the diagnostic would be more accurate as something like
"data pointed to by 'cp_end' may be used uninitialized".

For code like James's example,

extern void fill(char *start, const char *end);
...
char *dat = malloc(10);
...
fill(dat, dat+10);

in which the 'end' value is demonstrably one-past-the-end-of the malloced
array, it should be clear that the pointed-to data is not going to be read (or
if it was read, the warning should be something more severe!). It seems to me
that in this case the warning is always going to be a false positive so should
be suppressed.

> I've become convinced that attribute access none with no size argument should 
> not expect the pointer points to an object of nonzero size.

+1 to this; we also observed that adding access(none, end) caused other
spurious error messages.

I suppose there is no real need for the end parameter to be const char *, and
making it char * like the other pointer parameter into the same buffer does
prevent the warning. So in general that may be the best way to avoid this issue
without resorting to attributes. Unfortunately in the case of varint_put32()
making that change would require making similar changes to a surprisingly large
number of sibling functions across the project's (and a submodule's) source
files.

[Bug c++/99981] New: Misleading "conflicting declaration" error message

2021-04-08 Thread jmarshall at hey dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99981

Bug ID: 99981
   Summary: Misleading "conflicting declaration" error message
   Product: gcc
   Version: 11.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: jmarshall at hey dot com
  Target Milestone: ---

For the following C++ snippet,

 forward.cpp
struct foo;

typedef struct {
int i;
} foo;



both GCC 10.2.0 and current trunk (according to godbolt.org) produce

forward.cpp:5:3: error: conflicting declaration 'typedef struct foo foo'
5 | } foo;
  |   ^~~
forward.cpp:1:8: note: previous declaration as 'struct foo'
1 | struct foo;
  |^~~

It is a relatively minor issue, but "typedef struct foo foo" in the first
diagnostic is misleading. I would have expected to see "typedef struct ... foo"
or similar.

(If the code had indeed been "typedef struct foo { /*...*/ } foo", there would
be no error.)