generating function declarations in c frontend

I'm trying to generate the declarations for function intrinsics, and I
must be misunderstanding how to create new functions - I saw that a
function with no basic blocks is treated as a declaration, so I tried
to just create one and add it to the globals list:

  llvm_type *structTy, *ptrToStructTy;

  structTy = llvm_type_create_struct(0, 0);
  structTy = llvm_type_get_cannonical_struct(structTy);
  ptrToStructTy = llvm_type_get_pointer(structTy);

  llvm_function *dbg_stoppoint_fn = llvm_function_new(ptrToStructTy,
"llvm.dbg.stoppoint");
  llvm_argument *arg = llvm_argument_new(structTy, "foo");
  llvm_ilist_push_back(llvm_value, dbg_stoppoint_fn->Arguments, arg);
/* line # 548 */

  llvm_ilist_push_back(llvm_global, TheProgram.Globals, dbg_stoppoint_fn);
  
This doesn't compile, but at first glance I'm not sure why, since I
see in other places an llvm_argument being created then added to the
Arguments list in the exact same way.

../../src/gcc/llvm-expand.c:548: warning: initialization from
incompatible pointer type
../../src/gcc/llvm-expand.c:548: warning: initialization from
incompatible pointer type
../../src/gcc/llvm-expand.c:548: error: structure has no member named `Next'
../../src/gcc/llvm-expand.c:548: error: structure has no member named `Next'
../../src/gcc/llvm-expand.c:548: error: structure has no member named `Prev'
../../src/gcc/llvm-expand.c:548: error: structure has no member named `Prev'
../../src/gcc/llvm-expand.c:548: error: structure has no member named `Prev'
../../src/gcc/llvm-expand.c:548: error: structure has no member named `Prev'
../../src/gcc/llvm-expand.c:548: error: structure has no member named `Prev'
../../src/gcc/llvm-expand.c:550: warning: initialization from
incompatible pointer type

What am I missing?

Thanks,
-mike

I'm trying to generate the declarations for function intrinsics, and I
must be misunderstanding how to create new functions - I saw that a
function with no basic blocks is treated as a declaration, so I tried
to just create one and add it to the globals list:

  llvm_type *structTy, *ptrToStructTy;

  structTy = llvm_type_create_struct(0, 0);
  structTy = llvm_type_get_cannonical_struct(structTy);
  ptrToStructTy = llvm_type_get_pointer(structTy);

  llvm_function *dbg_stoppoint_fn = llvm_function_new(ptrToStructTy,
"llvm.dbg.stoppoint");

This is the problem right here. In particular, the type for the function
needs to be the type of the *function* itself, not the type of the return
value or the type of the argument. For llvm.dbg.stoppoint, this should be
the "{}* ({}*, uint, uint, %lldb.compile_unit*)" type. This is a function
type returning a "{}*", taking four arguments.

  llvm_argument *arg = llvm_argument_new(structTy, "foo");
  llvm_ilist_push_back(llvm_value, dbg_stoppoint_fn->Arguments, arg);

You don't need to do this.

  llvm_ilist_push_back(llvm_global, TheProgram.Globals, dbg_stoppoint_fn);

Also, I suggest calling CreateIntrinsicFnWithType instead of
llvm_function_new, as it does the llvm_ilist_push_back for you.

-Chris