I have a Function* to a function that has a signature like: void foo(double*, double*); I need to write the address of this function into a global variable initializer (really, into the initializer of a particular structure field). The structure field type is void*, and must be. Because of type constraints, doing something like: Function* foo = ...; std::vector<const Type*> fields; ... fields.push_back(ConstantPointerRef::get(foo)); will yield a type error because the type of the function foo ("void (*) (double*, double*)") does not match the structure field type. How might I go about making the necessary cast-like step at the GlobalValue/Function level? I want to do something like: Function* quasiCastThinger = foo->getAsType(myDesiredFunctionType); TIA. -j -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20030509/c00d4acb/attachment.html>
As I thought about this more, I realized that the problem is not as easy as just transmuting the FunctionType from one FunctionType to another, since void* is not a FunctionType. If the strict type-checking that is happening (the assert on Constants.cpp:233 in the ConstantStruct constructor) is the only problem here, and nothing more severe, perhaps the client should be able to set a flag that forces a the type of a ConstantPointerRef of a Function equal to what is returned by PointerType::get(Type::VoidTy), or some such thing. :) Thanks again, -j -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20030509/6b822bd6/attachment.html>
> Function* foo = ...; > std::vector<const Type*> fields; > ... > fields.push_back(ConstantPointerRef::get(foo)); > > will yield a type error because the type of the function foo ("void (*) > (double*, double*)") does not match the structure field type. > How might I go about making the necessary cast-like step at the > GlobalValue/Function level? I want to do something like:ConstantExpr::getCast will return a constant cast from one constant to a different type. -Chris -- http://llvm.cs.uiuc.edu/ http://www.nondot.org/~sabre/Projects/
> As I thought about this more, I realized that the problem is not as easy > as just transmuting the FunctionType from one FunctionType to another, > since void* is not a FunctionType.Sure, and the real type of the function is actual a pointer_to(function_type) anyway.> If the strict type-checking that is happening (the assert on > Constants.cpp:233 in the ConstantStruct constructor) is the only problem > here, and nothing more severe, perhaps the client should be able to set > a flag that forces a the type of a ConstantPointerRef of a Function > equal to what is returned by PointerType::get(Type::VoidTy), or some > such thing. :)Ick ick ick. :) No, just use the constant expr cast. You can see an example if you do something like this with the C front-end: void foo(); void *Ptr = &foo; You generate ConstantExpr's programatically with the ConstantExpr::get* methods. -Chris -- http://llvm.cs.uiuc.edu/ http://www.nondot.org/~sabre/Projects/
Seemingly Similar Threads
- [LLVMdev] ConstantPointerRef and void*'s to functions
- [LLVMdev] ConstantPointerRef Changes
- [LLVMdev] generating instructions with embedded ConstantExprs from within LLVM
- [LLVMdev] generating instructions with embedded ConstantExprs from within LLVM
- [LLVMdev] Discussion of eliminating the void type