* Re: [PATCH v2] Fix dereference of possible nullptr in -O3
2022-05-11 11:55 ` Pedro Alves
@ 2022-05-11 14:57 ` Simon Farre
0 siblings, 0 replies; 3+ messages in thread
From: Simon Farre @ 2022-05-11 14:57 UTC (permalink / raw)
To: Pedro Alves; +Cc: Simon Farre via Gdb-patches
> Needs more detail. What is the compiler in question? What does the
warning look like?
The compiler in question is GCC (11.2.0-19ubuntu1) and the "error" is due
to inlining of virtual functions. Output from the compiler can be found at
the bottom.
-O2 do not perform as aggressive optimizations as -O3 and thus do not "hit"
this error.
I tried to compile it with clang-13, but it instead generates other errors,
so I'm not able to test -O3 using clang unfortunately.
> I only see two calls to transfer_regset (which forwards arguments to
transfer_regset_register):
> #1 - transfer_regset (regset, this, regnum, (const gdb_byte *) buf,
nullptr, size);
> #2 - transfer_regset (regset, nullptr, regnum, nullptr, (gdb_byte *) buf,
size);
Yes, there's only two calls to transfer_regset, I was looking further up
the call chain, but you're right those are the only two places
that directly call that method, my mistake.
> The right assert is probably this at the top of the function:
> gdb_assert ((out_regcache != nullptr) != (out_buf != nullptr));
> ... meaning, you must pass either a non-NULL out_regcache or a non-NULL
out_buf,
> but never both NULL, and never both non-NULL. This should quiet the
compiler
> warning too, hopefully.
If you think that adding an assert here is the right approach, I'll add it
in v.3.
Thanks!
Simon
In member function ‘virtual void reg_buffer::raw_supply(int, const void*)’,
inlined from ‘void regcache::transfer_regset_register(regcache*, int,
const gdb_byte*, gdb_byte*, int, int) const’ at
.../binutils-gdb/gdb/regcache.c:1176:32,
inlined from ‘void regcache::transfer_regset(const regset*, regcache*,
int, const gdb_byte*, gdb_byte*, size_t) const’ at
.../binutils-gdb/gdb/regcache.c:1212:31:
/.../binutils-gdb/gdb/regcache.c:1053:17: error: ‘this’ pointer is null
[-Werror=nonnull]
1053 | assert_regnum (regnum);
| ~~~~~~~~~~~~~~^~~~~~~~
.../binutils-gdb/gdb/regcache.c: In function ‘void
regcache::transfer_regset(const regset*, regcache*, int, const gdb_byte*,
gdb_byte*, size_t) const’:
.../binutils-gdb/gdb/regcache.c:311:1: note: in a call to non-static member
function ‘void reg_buffer::assert_regnum(int) const’
311 | reg_buffer::assert_regnum (int regnum) const
| ^~~~~~~~~~
In member function ‘void regcache::transfer_regset_register(regcache*, int,
const gdb_byte*, gdb_byte*, int, int) const’,
inlined from ‘void regcache::transfer_regset(const regset*, regcache*,
int, const gdb_byte*, gdb_byte*, size_t) const’ at
.../binutils-gdb/gdb/regcache.c:1212:31:
.../binutils-gdb/gdb/regcache.c:1176:32: error: ‘this’ pointer is null
[-Werror=nonnull]
1176 | out_regcache->raw_supply (regnum, nullptr);
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In member function ‘void regcache::transfer_regset_register(regcache*, int,
const gdb_byte*, gdb_byte*, int, int) const’,
inlined from ‘void regcache::transfer_regset(const regset*, regcache*,
int, const gdb_byte*, gdb_byte*, size_t) const’ at
.../binutils-gdb/gdb/regcache.c:1222:29:
.../binutils-gdb/gdb/regcache.c:1176:32: error: ‘this’ pointer is null
[-Werror=nonnull]
1176 | out_regcache->raw_supply (regnum, nullptr);
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
^ permalink raw reply [flat|nested] 3+ messages in thread