This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Help forging a function_decl


On Mon, Jul 22, 2013 at 03:17:08PM -0300, Rodolfo Guilherme Wottrich wrote:
> Hello,
> Thanks! I had solved the problem some days ago, and it was actually
> related to your answer.
> First, I hadn't used push_struct_function() to allocate storage for my
> new function.
> Second, I wasn't calling finish_function() after setting my tree, so
> it would not be further compiled (just like your suggestion, since
> cgraph_add_new_function is called inside it). As I was inside the
> scope of main(), I also needed to save the function context with
> push_function_context(), call finish_function() and then pop the
> context back.
> Third, the flag DECL_EXTERNAL for my function was being set, so even
> though my tree was going to be further compiled, the definition for my
> function_decl was to be found outside file scope.

But you do call cgraph_add_new_function on it as well, right?  If not,
how is its symbol table node (also called and serving as the call
graph node) created?

(And BTW, you are hacking on trunk, right?  Older versions can be
quite a bit different here.)

> Now the problem is solved, but I still face an odd behavior: sometimes
> my function is output, sometimes not. Basically 50% of the times I
> compile my code, my function is simply not output.

What do you mean by "50% of the time?"  That you get different results
even when you do not change your compiler?  That should not happen and
means you invoke undefined behavior, most likely depending on some
uninitialized stuff (assuming your HW is OK) so you are probably not
clearing some allocated structure or something.  (Do you know why
DECL_EXTERNAL was set?  That looks weird).

Anyway, my best guess is that your function is removed by
symtab_remove_unreachable_nodes in ipa.c.  (And now I also see that
analyze_functions in cgraphunit.c is also doing its own unreachable
node removal, but hopefully runs early enough this should not be your
problem.)  If your function is static and is not called or referenced
from anywhere else, gcc will try to get rid of it.

Try setting DECL_PRESERVE_P of your decl (or calling
cgraph_mark_force_output_node on its call graph node which is cleaner
but should be equivalent for debugging, I suppose).  If that helps,
this is most likely your problem.

> And when I try to
> debug gcc with gdb, it always fails.

What do you mean?  That your function is not output or that you cannot
use gdb at all?

On Mon, Jul 22, 2013 at 10:27:51PM -0300, Rodolfo Guilherme Wottrich wrote:
> I run gcc with -fdump-tree-all-raw and found out that all dumps until
> filename.c.013t.cfg are fine, but every time it fails, my function
> disappears from filename.c.016t.ompexp onwards. Remembering: I want it
> to happen every time there's a #pragma omp parallel in the source, so
> I put my implementation right after the end of
> c_parser_omp_parallel(), in file c-parser.c.

Add -fdump-ipa-all switch and look whether the function appears
there.  Especially the cgraph dump can usually tell you that a
function was removed as unreachable.  Grep all dumps for "Reclaiming
functions:" and see whether your function is listed.

> Again, thank you for the help.

No worries.  And good luck,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]