diff options
author | James Y Knight <jyknight@google.com> | 2019-01-31 20:35:56 +0000 |
---|---|---|
committer | James Y Knight <jyknight@google.com> | 2019-01-31 20:35:56 +0000 |
commit | f47d6b38c7a61d50db4566b02719de05492dcef1 (patch) | |
tree | f5c99869bcceba2f8b973cdbcadf7d3db52660b9 /llvm/lib/IR/Module.cpp | |
parent | e1b332efba12ce1d5a482084a5182e0527e9c88d (diff) | |
download | bcm5719-llvm-f47d6b38c7a61d50db4566b02719de05492dcef1.tar.gz bcm5719-llvm-f47d6b38c7a61d50db4566b02719de05492dcef1.zip |
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352791
Diffstat (limited to 'llvm/lib/IR/Module.cpp')
-rw-r--r-- | llvm/lib/IR/Module.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index fd6495f4dbd..b6dd7ab70a8 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -140,8 +140,8 @@ void Module::getOperandBundleTags(SmallVectorImpl<StringRef> &Result) const { // it. This is nice because it allows most passes to get away with not handling // the symbol table directly for this common task. // -Constant *Module::getOrInsertFunction(StringRef Name, FunctionType *Ty, - AttributeList AttributeList) { +FunctionCallee Module::getOrInsertFunction(StringRef Name, FunctionType *Ty, + AttributeList AttributeList) { // See if we have a definition for the specified function already. GlobalValue *F = getNamedValue(Name); if (!F) { @@ -151,21 +151,20 @@ Constant *Module::getOrInsertFunction(StringRef Name, FunctionType *Ty, if (!New->isIntrinsic()) // Intrinsics get attrs set on construction New->setAttributes(AttributeList); FunctionList.push_back(New); - return New; // Return the new prototype. + return {Ty, New}; // Return the new prototype. } // If the function exists but has the wrong type, return a bitcast to the // right type. auto *PTy = PointerType::get(Ty, F->getAddressSpace()); if (F->getType() != PTy) - return ConstantExpr::getBitCast(F, PTy); + return {Ty, ConstantExpr::getBitCast(F, PTy)}; // Otherwise, we just found the existing function or a prototype. - return F; + return {Ty, F}; } -Constant *Module::getOrInsertFunction(StringRef Name, - FunctionType *Ty) { +FunctionCallee Module::getOrInsertFunction(StringRef Name, FunctionType *Ty) { return getOrInsertFunction(Name, Ty, AttributeList()); } |