[Bug middle-end/88518] Function call defeats -Wuninitialized
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88518 Martin Sebor changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Last reconfirmed||2021-4-6 Resolution|--- |DUPLICATE CC||msebor at gcc dot gnu.org --- Comment #6 from Martin Sebor --- Confirmed as a duplicate of pr60488 (which itself is likely a duplicate of some older bug). A variable whose address escapes is not considered by the warning. It sees the following IL: ;; Function f (f, funcdef_no=0, decl_uid=1947, cgraph_uid=1, symbol_order=0) void f () { long unsigned int i; long unsigned int i.0_1; long unsigned int _2; [local count: 1073741824]: # .MEM_4 = VDEF <.MEM_3(D)> h (); # VUSE <.MEM_4> i.0_1 = i;<<< i loaded from memory and not considered _2 = i.0_1 + 1; <<< missing -Wuninitialized # .MEM_5 = VDEF <.MEM_4> i = _2; # .MEM_6 = VDEF <.MEM_5> g (); # .MEM_7 = VDEF <.MEM_6> i ={v} {CLOBBER}; # VUSE <.MEM_7> return; } The pointless load persists until the assembly: f: .LFB0: .cfi_startproc subq$24, %rsp .cfi_def_cfa_offset 32 callh leaq8(%rsp), %rdi <<< i loaded from memory addq$1, 8(%rsp) <<< i++ callg addq$24, %rsp .cfi_def_cfa_offset 8 ret .cfi_endproc *** This bug has been marked as a duplicate of bug 60488 ***
[Bug middle-end/88518] Function call defeats -Wuninitialized
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88518 --- Comment #5 from Eric Gallager --- (In reply to Matthew Wilcox from comment #2) > Thanks! What I actually want to do is annotate g() to the effect that it > reads the pointed-to variable before it writes it. IOW, I want to write > something like: > > void g(unsigned long __attribute__((read_before_write)) *p); > void h(void); > > void f(void) > { > unsigned long i; > > h(); > g(); > } > > and have gcc emit a warning that i is used uninitialised. I tried adding i > = i prior to the call of g() through macro trickery, but was surprised that > it didn't trigger, and simplified down to this test-case. > > Any chance I could get that attribute or something like it? The object access attributes that Martin Sebor added recently might work somewhat along these lines, but I haven't actually tested yet...
[Bug middle-end/88518] Function call defeats -Wuninitialized
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88518 --- Comment #4 from Eric Gallager --- Note that if h() has __attribute__((pure)) or __attribute__((const)) on it, you then get the -Wuninitialized warning as expected. Of course, then you also get a warning from -Wattributes about pure or const being used on a function returning void, too...
[Bug middle-end/88518] Function call defeats -Wuninitialized
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88518 Richard Biener changed: What|Removed |Added Severity|normal |enhancement --- Comment #3 from Richard Biener --- Not so easy.
[Bug middle-end/88518] Function call defeats -Wuninitialized
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88518 --- Comment #2 from Matthew Wilcox --- Thanks! What I actually want to do is annotate g() to the effect that it reads the pointed-to variable before it writes it. IOW, I want to write something like: void g(unsigned long __attribute__((read_before_write)) *p); void h(void); void f(void) { unsigned long i; h(); g(); } and have gcc emit a warning that i is used uninitialised. I tried adding i = i prior to the call of g() through macro trickery, but was surprised that it didn't trigger, and simplified down to this test-case. Any chance I could get that attribute or something like it?
[Bug middle-end/88518] Function call defeats -Wuninitialized
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88518 Andrew Pinski changed: What|Removed |Added Keywords||diagnostic --- Comment #1 from Andrew Pinski --- I think there is a dup of this bug already and one which descibes what need to be done. Basically escape analysis is not flow sensative. That means GCC is currently assuming that i escapes at the very first function call, h, rather later on when g is called.