[Bug tree-optimization/108416] False negative -Wdangling-pointer
rguenth at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Jan 16 10:32:24 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108416
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|False positive |False negative
|-Wdangling-pointer |-Wdangling-pointer
Ever confirmed|0 |1
CC| |msebor at gcc dot gnu.org
Status|UNCONFIRMED |NEW
Last reconfirmed| |2023-01-16
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed, this is a false negative. Simpler testcase follows
class HoldsNonOwning {
public:
void reset(int* nonOwning) { mNonOwning = nonOwning; }
int compute(int input)
{
if (!mNonOwning)
return -1;
return input * *mNonOwning;
}
int* mNonOwning;
};
class HolderTest {
public:
HoldsNonOwning holder;
int compute();
};
void foo(int *);
int __attribute__((noipa)) HolderTest::compute() {
int nonOwning = 2;
holder.reset(&nonOwning);
int i = holder.compute(42);
// If we uncomment this we don't get the warning
// foo(&i);
return i;
}
int main(int, char**)
{
HolderTest ht;
int i = ht.compute();
foo (&i);
return 0;
}
Uncommenting the call to 'foo' likely makes us believe the reference in
the global object might be pruned by it?
More information about the Gcc-bugs
mailing list