aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/Function.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2007-11-27 13:23:08 +0000
committerDuncan Sands <baldrick@free.fr>2007-11-27 13:23:08 +0000
commitdc024674ff96820d6020757b48d47f46d4c07db2 (patch)
tree843dfcaeb8f6c99de930a32020148b563005c2fd /lib/VMCore/Function.cpp
parentf19341dec7361451f100a882a023b14583454d7e (diff)
downloadexternal_llvm-dc024674ff96820d6020757b48d47f46d4c07db2.zip
external_llvm-dc024674ff96820d6020757b48d47f46d4c07db2.tar.gz
external_llvm-dc024674ff96820d6020757b48d47f46d4c07db2.tar.bz2
Fix PR1146: parameter attributes are longer part of
the function type, instead they belong to functions and function calls. This is an updated and slightly corrected version of Reid Spencer's original patch. The only known problem is that auto-upgrading of bitcode files doesn't seem to work properly (see test/Bitcode/AutoUpgradeIntrinsics.ll). Hopefully a bitcode guru (who might that be? :) ) will fix it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44359 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Function.cpp')
-rw-r--r--lib/VMCore/Function.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 2b83e6b..023cb55 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -161,7 +161,7 @@ ParamAttrsList::areCompatible(const ParamAttrsList *A, const ParamAttrsList *B){
void
ParamAttrsList::Profile(FoldingSetNodeID &ID) const {
for (unsigned i = 0; i < attrs.size(); ++i) {
- unsigned val = attrs[i].attrs << 16 | attrs[i].index;
+ uint32_t val = uint32_t(attrs[i].attrs) << 16 | attrs[i].index;
ID.AddInteger(val);
}
}
@@ -170,7 +170,10 @@ static ManagedStatic<FoldingSet<ParamAttrsList> > ParamAttrsLists;
ParamAttrsList *
ParamAttrsList::get(const ParamAttrsVector &attrVec) {
- assert(!attrVec.empty() && "Illegal to create empty ParamAttrsList");
+ // If there are no attributes then return a null ParamAttrsList pointer.
+ if (attrVec.empty())
+ return 0;
+
#ifndef NDEBUG
for (unsigned i = 0, e = attrVec.size(); i < e; ++i) {
assert(attrVec[i].attrs != ParamAttr::None
@@ -179,15 +182,22 @@ ParamAttrsList::get(const ParamAttrsVector &attrVec) {
&& "Misordered ParamAttrsList!");
}
#endif
+
+ // Otherwise, build a key to look up the existing attributes.
ParamAttrsList key(attrVec);
FoldingSetNodeID ID;
key.Profile(ID);
void *InsertPos;
ParamAttrsList* PAL = ParamAttrsLists->FindNodeOrInsertPos(ID, InsertPos);
+
+ // If we didn't find any existing attributes of the same shape then
+ // create a new one and insert it.
if (!PAL) {
PAL = new ParamAttrsList(attrVec);
ParamAttrsLists->InsertNode(PAL, InsertPos);
}
+
+ // Return the ParamAttrsList that we found or created.
return PAL;
}
@@ -201,8 +211,8 @@ ParamAttrsList::~ParamAttrsList() {
Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
const std::string &name, Module *ParentModule)
- : GlobalValue(PointerType::get(Ty), Value::FunctionVal, 0, 0, Linkage, name) {
- ParamAttrs = 0;
+ : GlobalValue(PointerType::get(Ty), Value::FunctionVal, 0, 0, Linkage, name),
+ ParamAttrs(0) {
SymTab = new ValueSymbolTable();
assert((getReturnType()->isFirstClassType() ||getReturnType() == Type::VoidTy)
@@ -259,16 +269,30 @@ void Function::setParent(Module *parent) {
LeakDetector::removeGarbageObject(this);
}
-void Function::setParamAttrs(ParamAttrsList *attrs) {
+void Function::setParamAttrs(const ParamAttrsList *attrs) {
+ // Avoid deleting the ParamAttrsList if they are setting the
+ // attributes to the same list.
+ if (ParamAttrs == attrs)
+ return;
+
+ // Drop reference on the old ParamAttrsList
if (ParamAttrs)
ParamAttrs->dropRef();
+ // Add reference to the new ParamAttrsList
if (attrs)
attrs->addRef();
+ // Set the new ParamAttrsList.
ParamAttrs = attrs;
}
+bool Function::isStructReturn() const {
+ if (ParamAttrs)
+ return ParamAttrs->paramHasAttr(1, ParamAttr::StructRet);
+ return false;
+}
+
const FunctionType *Function::getFunctionType() const {
return cast<FunctionType>(getType()->getElementType());
}