On 10/20/2015 12:07 AM, H.J. Lu wrote:
On Thu, Jul 09, 2015 at 03:57:31PM +0200, Richard Biener wrote:
I don't see why the C FE would need to invoke finish_decl twice here.
[...]
So I'd rather
have the C frontend not invoke rest_of_decl_compilation on this in the
first place.

Your patch still feels like a hack in the wrong place.

I've debugged this a bit and it looks like HJ gave a somewhat confused account of what actually happens. The frontend never calls rest_of_decl_compilation for the decl in question. It only calls finish_decl, which detects the problem and sets the type to error_mark. That function calls rest_of_decl_compilation, but only for things at file scope (the problematic decl is in a function scope).

diff --git a/gcc/cgraphbuild.c b/gcc/cgraphbuild.c
index 7d2d096..4d679d9 100644
--- a/gcc/cgraphbuild.c
+++ b/gcc/cgraphbuild.c
@@ -381,7 +381,8 @@ pass_build_cgraph_edges::execute (function *fun)
    FOR_EACH_LOCAL_DECL (fun, ix, decl)
      if (TREE_CODE (decl) == VAR_DECL
         && (TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
-       && !DECL_HAS_VALUE_EXPR_P (decl))
+       && !DECL_HAS_VALUE_EXPR_P (decl)
+       && TREE_TYPE (decl) != error_mark_node)
        varpool_node::finalize_decl (decl);

This is where we call finalize_decl. I've tried a few things to stop the C frontend from letting the erroneous decl escape, but couldn't really make it work, so this looks like an adequate fix. The patch is OK IMO.


Bernd

Reply via email to