aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2008-01-06 18:27:01 +0000
committerDuncan Sands <baldrick@free.fr>2008-01-06 18:27:01 +0000
commitc849e66c0ae3520c6e89499ccd81f4fc00ea198f (patch)
tree1ff466f71bdde8cc209d51f581e13dc1654c7b10 /lib/VMCore
parent5c4895800ed40a173c862004eed2d79e18fc6471 (diff)
downloadexternal_llvm-c849e66c0ae3520c6e89499ccd81f4fc00ea198f.zip
external_llvm-c849e66c0ae3520c6e89499ccd81f4fc00ea198f.tar.gz
external_llvm-c849e66c0ae3520c6e89499ccd81f4fc00ea198f.tar.bz2
The transform that tries to turn calls to bitcast functions into
direct calls bails out unless caller and callee have essentially equivalent parameter attributes. This is illogical - the callee's attributes should be of no relevance here. Rework the logic, which incidentally fixes a crash when removed arguments have attributes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45658 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/ParameterAttributes.cpp63
-rw-r--r--lib/VMCore/Verifier.cpp20
2 files changed, 22 insertions, 61 deletions
diff --git a/lib/VMCore/ParameterAttributes.cpp b/lib/VMCore/ParameterAttributes.cpp
index a95e663..840d54b 100644
--- a/lib/VMCore/ParameterAttributes.cpp
+++ b/lib/VMCore/ParameterAttributes.cpp
@@ -7,11 +7,12 @@
//
//===----------------------------------------------------------------------===//
//
-// This file implements the ParamAttrsList class.
+// This file implements the ParamAttrsList class and ParamAttr utilities.
//
//===----------------------------------------------------------------------===//
#include "llvm/ParameterAttributes.h"
+#include "llvm/DerivedTypes.h"
#include "llvm/Support/ManagedStatic.h"
using namespace llvm;
@@ -63,50 +64,6 @@ ParamAttrsList::getParamAttrsText(uint16_t Attrs) {
return Result;
}
-/// onlyInformative - Returns whether only informative attributes are set.
-static inline bool onlyInformative(uint16_t attrs) {
- return !(attrs & ~ParamAttr::Informative);
-}
-
-bool
-ParamAttrsList::areCompatible(const ParamAttrsList *A, const ParamAttrsList *B){
- if (A == B)
- return true;
- unsigned ASize = A ? A->size() : 0;
- unsigned BSize = B ? B->size() : 0;
- unsigned AIndex = 0;
- unsigned BIndex = 0;
-
- while (AIndex < ASize && BIndex < BSize) {
- uint16_t AIdx = A->getParamIndex(AIndex);
- uint16_t BIdx = B->getParamIndex(BIndex);
- uint16_t AAttrs = A->getParamAttrsAtIndex(AIndex);
- uint16_t BAttrs = B->getParamAttrsAtIndex(AIndex);
-
- if (AIdx < BIdx) {
- if (!onlyInformative(AAttrs))
- return false;
- ++AIndex;
- } else if (BIdx < AIdx) {
- if (!onlyInformative(BAttrs))
- return false;
- ++BIndex;
- } else {
- if (!onlyInformative(AAttrs ^ BAttrs))
- return false;
- ++AIndex;
- ++BIndex;
- }
- }
- for (; AIndex < ASize; ++AIndex)
- if (!onlyInformative(A->getParamAttrsAtIndex(AIndex)))
- return false;
- for (; BIndex < BSize; ++BIndex)
- if (!onlyInformative(B->getParamAttrsAtIndex(AIndex)))
- return false;
- return true;
-}
-
void ParamAttrsList::Profile(FoldingSetNodeID &ID,
const ParamAttrsVector &Attrs) {
for (unsigned i = 0; i < Attrs.size(); ++i)
@@ -229,3 +186,19 @@ ParamAttrsList::excludeAttrs(const ParamAttrsList *PAL,
return getModified(PAL, modVec);
}
+uint16_t ParamAttr::incompatibleWithType (const Type *Ty, uint16_t attrs) {
+ uint16_t Incompatible = None;
+
+ if (!Ty->isInteger())
+ Incompatible |= IntegerTypeOnly;
+
+ if (!isa<PointerType>(Ty))
+ Incompatible |= PointerTypeOnly;
+ else if (attrs & ParamAttr::ByVal) {
+ const PointerType *PTy = cast<PointerType>(Ty);
+ if (!isa<StructType>(PTy->getElementType()))
+ Incompatible |= ParamAttr::ByVal;
+ }
+
+ return attrs & Incompatible;
+}
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index d305855..95f871b 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -418,22 +418,10 @@ void Verifier::VerifyParamAttrs(const FunctionType *FT,
Attrs->getParamAttrsText(MutI) + "are incompatible!", V);
}
- uint16_t IType = Attr & ParamAttr::IntegerTypeOnly;
- Assert1(!IType || FT->getParamType(Idx-1)->isInteger(),
- "Attribute " + Attrs->getParamAttrsText(IType) +
- "should only apply to Integer type!", V);
-
- uint16_t PType = Attr & ParamAttr::PointerTypeOnly;
- Assert1(!PType || isa<PointerType>(FT->getParamType(Idx-1)),
- "Attribute " + Attrs->getParamAttrsText(PType) +
- "should only apply to Pointer type!", V);
-
- if (Attr & ParamAttr::ByVal) {
- const PointerType *Ty =
- dyn_cast<PointerType>(FT->getParamType(Idx-1));
- Assert1(!Ty || isa<StructType>(Ty->getElementType()),
- "Attribute byval should only apply to pointer to structs!", V);
- }
+ uint16_t IType = ParamAttr::incompatibleWithType(FT->getParamType(Idx-1),
+ Attr);
+ Assert1(!IType, "Wrong type for attribute " +
+ Attrs->getParamAttrsText(IType), V);
if (Attr & ParamAttr::Nest) {
Assert1(!SawNest, "More than one parameter has attribute nest!", V);