[plugin] Issue with life cycle of attributes argument when passed to new function calls

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

     I've been working on a custom attribute that when use with a,
in-function, variable, builds a function call using the first
argument as the name of the function and the other as the arguments of the
function.

     All is well when the arguments are the name of already present
variables, but if it's anything else (ex : string literal,
function call, ...) either my test project will segfault during the
compilation (for expression, function calls, etc...) or segfault
during the project run (string literals).

    From what I understand the argument given to my attribute are parsed
correctly but either a transformation of the node
is required before inserting it in the function call or they have to be
added in some list. 

    Does anyone has an idea on how I could fix this ? I've been searching
for weeks now and didn't find anything useful.


Thanks, Bastien Penavayre

PS: here is the problematic section of my project

static
vec<tree>               argsToVec(tree var, tree type, tree args)
{
  vec<tree>             tmp;
  unsigned              nb(1);
  tree                     it;

  for (it = args; it; it = TREE_CHAIN(args))
    nb++;
  tmp.create(nb);
  tmp.quick_push(build1(ADDR_EXPR, build_pointer_type(type), var));
  for (it = args; it; it = TREE_CHAIN(it))
    {                     
      tmp.quick_push(TREE_VALUE(it));
    }
  return tmp;
}

static void     call_object_ctor(tree node, tree type_tree,
                                 tree attribute, gimple_stmt_iterator *gsi)
{
  const char    *funcName;
  tree          args = TREE_VALUE(attribute);
  tree          func, type_f;
  gimple        call;
  vec<tree>     true_args;

  if (!args || (funcName = TREE_STRING_POINTER(TREE_VALUE(args)))[0] == 0)
    return ;
  args = TREE_CHAIN(args);
  if (!arg)
    return ;  
  type_f = build_varargs_function_type_list(void_type_node, ptr_type_node,
NULL_TREE); // void(*)(void *,...); 
  func = build_fn_decl(funcName, type_f);
  true_args = argsToVec(node, type_tree, args);                           
  call = gimple_build_call_vec(func, true_args);
  true_args.release();
  gsi_insert_after(gsi, call, GSI_NEW_STMT);
}



--
View this message in context: http://gcc.1065356.n5.nabble.com/plugin-Issue-with-life-cycle-of-attributes-argument-when-passed-to-new-function-calls-tp1228205.html
Sent from the gcc - Help mailing list archive at Nabble.com.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux