The following implements a special-case for LTO when doing %K
formatting.  LTO currently only keeps FUNCTION_DECL abstract
origins (for BLOCKs satisfying inlined_function_outer_scope_p)
which means the existing %K formatting usually bails out immediately.
This severely complicates the search for warnings like

/usr/include/bits/stdio2.h: In function ‘main’:
/usr/include/bits/stdio2.h:293:2: warning: call to ‘__fread_chk_warn’ 
declared with attribute warning: fread called with bigger size * nmemb 
than length of destination buffer
  return __fread_chk_warn (__ptr, __bos0 (__ptr), __size, __n, __stream);
  ^

because you only have an outermost function context to work on
and the inline stack can include functions from any translation
unit with LTO.  The following patch improves this to

In function 'fread',
    inlined from 'main' at t.c:7:10:
/usr/include/bits/stdio2.h:293:2: warning: call to '__fread_chk_warn' 
declared with attribute warning: fread called with bigger size * nmemb 
than length of destination buffer
  return __fread_chk_warn (__ptr, __bos0 (__ptr), __size, __n, __stream);
  ^

which matches non-LTO behavior.

Bootstrap/regtest pending on x86_64-unknown-linux-gnu, ok for trunk?

(unfortunately I can't make a testcase working, I have no idea why
dejagnu thinks that dg-message is not supported with lto.exp - it
does include gcc-dg.exp)

Thanks,
Richard.

2014-03-25  Richard Biener  <rguent...@suse.de>

        * tree-pretty-print.c (percent_K_format): Implement special
        case for LTO and its stripped down BLOCK tree.

Index: gcc/tree-pretty-print.c
===================================================================
*** gcc/tree-pretty-print.c     (revision 208812)
--- gcc/tree-pretty-print.c     (working copy)
*************** percent_K_format (text_info *text)
*** 3365,3370 ****
--- 3367,3391 ----
    gcc_assert (pp_ti_abstract_origin (text) != NULL);
    block = TREE_BLOCK (t);
    *pp_ti_abstract_origin (text) = NULL;
+ 
+   if (in_lto_p)
+     {
+       /* ???  LTO drops all BLOCK_ABSTRACT_ORIGINs apart from those
+          representing the outermost block of an inlined function.
+        So walk the BLOCK tree until we hit such a scope.  */
+       while (block
+            && TREE_CODE (block) == BLOCK)
+       {
+         if (inlined_function_outer_scope_p (block))
+           {
+             *pp_ti_abstract_origin (text) = block;
+             break;
+           }
+         block = BLOCK_SUPERCONTEXT (block);
+       }
+       return;
+     }
+ 
    while (block
         && TREE_CODE (block) == BLOCK
         && BLOCK_ABSTRACT_ORIGIN (block))

Reply via email to