https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111253
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2023-08-31 Keywords| |diagnostic CC| |msebor at gcc dot gnu.org, | |rguenth at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> --- We use 2034 if (!warning_at (loc, OPT_Wfree_nonheap_object, 2035 "%qD called on pointer %qE with nonzero offset%s", 2036 dealloc_decl, aref.ref, offstr)) so this is %qE handling where in c_pretty_printer::primary_expression for an SSA name we do if (SSA_NAME_VAR (e)) ... else { /* Print only the right side of the GIMPLE assignment. */ gimple *def_stmt = SSA_NAME_DEF_STMT (e); pp_gimple_stmt_1 (this, def_stmt, 0, TDF_RHS_ONLY); } this regressed with r11-6508-gabb1b6058c09a7 which of course was supposed to be an improvement. But I'm not sure in which cases it actually is? Possibly when the definition is a memory read (but then this can also appear to falsely re-order loads across stores). Fixing this gets us again t.i:21:5: warning: 'realloc' called on pointer '*<unknown>.t_mem_caches' with nonzero offset 40 [-Wfree-nonheap-object] 21 | realloc(__trans_tmp_1.t_mem_caches, sizeof(int)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ the idea of expanding GIMPLE stmts until we hit a named one might be appealing but then we need to do so recursively and for example expand PHIs as <condition> ? A : B (or even more complex for PHIs with more than one argument). The following still passes the three testcases adjusted/added with the original change. diff --git a/gcc/c-family/c-pretty-print.cc b/gcc/c-family/c-pretty-print.cc index 7536a7c471f..679aa766fe0 100644 --- a/gcc/c-family/c-pretty-print.cc +++ b/gcc/c-family/c-pretty-print.cc @@ -33,6 +33,9 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" #include "options.h" #include "internal-fn.h" +#include "function.h" +#include "basic-block.h" +#include "gimple.h" /* The pretty-printer code is primarily designed to closely follow (GNU) C and C++ grammars. That is to be contrasted with spaghetti @@ -1380,12 +1383,14 @@ c_pretty_printer::primary_expression (tree e) else primary_expression (var); } - else + else if (gimple_assign_single_p (SSA_NAME_DEF_STMT (e))) { /* Print only the right side of the GIMPLE assignment. */ gimple *def_stmt = SSA_NAME_DEF_STMT (e); pp_gimple_stmt_1 (this, def_stmt, 0, TDF_RHS_ONLY); } + else + expression (e); break; default: