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


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.

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. And when I try to
debug gcc with gdb, it always fails.
Any thoughts? Maybe I am missing something related to garbage
collection or so... Not a clue.

Rodolfo Guilherme Wottrich
Universidade Estadual de Campinas - Unicamp

2013/7/22 Martin Jambor <>:
> Hi,
> On Wed, Jul 17, 2013 at 04:52:30PM -0300, Rodolfo Guilherme Wottrich wrote:
>> Hello there,
>> Please disregard this message in case it doesn't fit here.
>> During compilation of a C file, I need to be able to create a global
>> function definition, with whatever a body I may have forged. I mean,
>> the function is not going to be present in the source file and I got
>> to create the respective tree structure so it can be later gimplified
>> and further compiled like any other function present in the source. I
>> would only need to create that function in case some OpenMP directive
>> is encountered, so my latest and unsuccessful try to do so was to
>> create the tree structures for a FUNCTION_DECL and, say, a variable
>> declared inside the scope of that function, after the parsing of a
>> #pragma omp parallel in c_parser_omp_parallel() in file c-parser.c. I
>> followed and tried to re-create the steps I found in the function
>> create_omp_child_function(), in file omp-low.c, and
>> I think maybe the problem is that my new function doesn't go under
>> rest_of_compilation, therefore it is not gimplified and obviously no
>> code for it is generated.
> it's a bit difficult to say without knowing what you are doing and at
> what compilation stage you are doing it but perhaps you could try
> calling cgraph_add_new_function on the new decl?  Also try reading the
> comment at the beginning of cgraphunit.c.
> Hope it helps,
> Martin
>> Summarizing: I tried to forge a function in parsing time, but
>> couldn't. What am I doing wrong, and how can one do such a thing?
>> Maybe the problem is that I create no calls to that new function, what
>> do you think? Anyway, I'm compiling with -O0, so I guess no
>> optimization pass would remove my function just because it is not
>> being used.
>> Thanks in advance,
>> ---
>> Rodolfo Guilherme Wottrich
>> Universidade Estadual de Campinas - Unicamp

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