void operator=(const AttributeImpl &) LLVM_DELETED_FUNCTION;
AttributeImpl(const AttributeImpl &) LLVM_DELETED_FUNCTION;
public:
- AttributeImpl(LLVMContext &C, Constant *Kind)
- : Context(C), Kind(Kind) {}
- AttributeImpl(LLVMContext &C, Constant *Kind, ArrayRef<Constant*> Vals)
+ AttributeImpl(LLVMContext &C, Constant *Kind,
+ ArrayRef<Constant*> Vals = ArrayRef<Constant*>())
: Context(C), Kind(Kind), Vals(Vals.begin(), Vals.end()) {}
- explicit AttributeImpl(LLVMContext &C, Attribute::AttrKind data);
- AttributeImpl(LLVMContext &C, Attribute::AttrKind data,
- ArrayRef<Constant*> values);
- AttributeImpl(LLVMContext &C, StringRef data);
LLVMContext &getContext() { return Context; }
/// This returns the alignment field of an attribute as a byte alignment value.
unsigned Attribute::getAlignment() const {
- if (!hasAttribute(Attribute::Alignment))
- return 0;
+ assert(hasAttribute(Attribute::Alignment) &&
+ "Trying to get alignment from non-alignment attribute!");
return pImpl->getAlignment();
}
/// This returns the stack alignment field of an attribute as a byte alignment
/// value.
unsigned Attribute::getStackAlignment() const {
- if (!hasAttribute(Attribute::StackAlignment))
- return 0;
+ assert(hasAttribute(Attribute::StackAlignment) &&
+ "Trying to get alignment from non-alignment attribute!");
return pImpl->getStackAlignment();
}
if (I != E) Result += ' ';
}
if (Vals.size() > 1) Result += ')';
+ return Result;
}
llvm_unreachable("Unknown attribute");
// AttributeImpl Definition
//===----------------------------------------------------------------------===//
-AttributeImpl::AttributeImpl(LLVMContext &C, Attribute::AttrKind kind)
- : Context(C) {
- Kind = ConstantInt::get(Type::getInt64Ty(C), kind);
-}
-AttributeImpl::AttributeImpl(LLVMContext &C, Attribute::AttrKind kind,
- ArrayRef<Constant*> values)
- : Context(C) {
- Kind = ConstantInt::get(Type::getInt64Ty(C), kind);
- Vals.reserve(values.size());
- Vals.append(values.begin(), values.end());
-}
-AttributeImpl::AttributeImpl(LLVMContext &C, StringRef kind)
- : Context(C) {
- Kind = ConstantDataArray::getString(C, kind);
-}
-
bool AttributeImpl::hasAttribute(Attribute::AttrKind A) const {
if (ConstantInt *CI = dyn_cast<ConstantInt>(Kind))
return CI->getZExtValue() == A;
}
bool AttributeImpl::operator<(const AttributeImpl &AI) const {
+ // This sorts the attributes with Attribute::AttrKinds coming first (sorted
+ // relative to their enum value) and then strings.
+
if (!Kind && !AI.Kind) return false;
if (!Kind && AI.Kind) return true;
if (Kind && !AI.Kind) return false;
std::string AttributeSetNode::getAsString() const {
std::string Str = "";
for (SmallVectorImpl<Attribute>::const_iterator I = AttrList.begin(),
- E = AttrList.end(); I != E; ++I) {
- if (I != AttrList.begin()) Str += " ";
+ E = AttrList.end(); I != E; ) {
Str += I->getAsString();
+ if (++I != E) Str += " ";
}
return Str;
}
// AttributeFuncs Function Defintions
//===----------------------------------------------------------------------===//
+/// \brief Which attributes cannot be applied to a type.
AttributeSet AttributeFuncs::typeIncompatible(Type *Ty, uint64_t Index) {
AttrBuilder Incompatible;