aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2012-01-20 17:56:17 +0000
committerKostya Serebryany <kcc@google.com>2012-01-20 17:56:17 +0000
commit164b86b4399559e45fab7846f1e3e09119cab4e2 (patch)
treeb3d1c01f3d4cc2c23f2f7f826f14afd69311edb9 /lib/VMCore
parent3feccbaaee2fe639fd089cdb78ad623f662a5796 (diff)
downloadexternal_llvm-164b86b4399559e45fab7846f1e3e09119cab4e2.zip
external_llvm-164b86b4399559e45fab7846f1e3e09119cab4e2.tar.gz
external_llvm-164b86b4399559e45fab7846f1e3e09119cab4e2.tar.bz2
Extend Attributes to 64 bits
Problem: LLVM needs more function attributes than currently available (32 bits). One such proposed attribute is "address_safety", which shows that a function is being checked for address safety (by AddressSanitizer, SAFECode, etc). Solution: - extend the Attributes from 32 bits to 64-bits - wrap the object into a class so that unsigned is never erroneously used instead - change "unsigned" to "Attributes" throughout the code, including one place in clang. - the class has no "operator uint64 ()", but it has "uint64_t Raw() " to support packing/unpacking. - the class has "safe operator bool()" to support the common idiom: if (Attributes attr = getAttrs()) useAttrs(attr); - The CTOR from uint64_t is marked explicit, so I had to add a few explicit CTOR calls - Add the new attribute "address_safety". Doing it in the same commit to check that attributes beyond first 32 bits actually work. - Some of the functions from the Attribute namespace are worth moving inside the class, but I'd prefer to have it as a separate commit. Tested: "make check" on Linux (32-bit and 64-bit) and Mac (10.6) built/run spec CPU 2006 on Linux with clang -O2. This change will break clang build in lib/CodeGen/CGCall.cpp. The following patch will fix it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148553 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Attributes.cpp8
-rw-r--r--lib/VMCore/Core.cpp17
-rw-r--r--lib/VMCore/Verifier.cpp4
3 files changed, 17 insertions, 12 deletions
diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp
index 485be75..c05132b 100644
--- a/lib/VMCore/Attributes.cpp
+++ b/lib/VMCore/Attributes.cpp
@@ -76,6 +76,8 @@ std::string Attribute::getAsString(Attributes Attrs) {
Result += "naked ";
if (Attrs & Attribute::NonLazyBind)
Result += "nonlazybind ";
+ if (Attrs & Attribute::AddressSafety)
+ Result += "address_safety ";
if (Attrs & Attribute::StackAlignment) {
Result += "alignstack(";
Result += utostr(Attribute::getStackAlignmentFromAttrs(Attrs));
@@ -152,8 +154,10 @@ public:
}
static void Profile(FoldingSetNodeID &ID, const AttributeWithIndex *Attr,
unsigned NumAttrs) {
- for (unsigned i = 0; i != NumAttrs; ++i)
- ID.AddInteger(uint64_t(Attr[i].Attrs) << 32 | unsigned(Attr[i].Index));
+ for (unsigned i = 0; i != NumAttrs; ++i) {
+ ID.AddInteger(Attr[i].Attrs.Raw());
+ ID.AddInteger(Attr[i].Index);
+ }
}
};
}
diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp
index 7f86baa..ddc2604 100644
--- a/lib/VMCore/Core.cpp
+++ b/lib/VMCore/Core.cpp
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "llvm-c/Core.h"
+#include "llvm/Attributes.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
@@ -1350,14 +1351,14 @@ void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
Function *Func = unwrap<Function>(Fn);
const AttrListPtr PAL = Func->getAttributes();
- const AttrListPtr PALnew = PAL.addAttr(~0U, PA);
+ const AttrListPtr PALnew = PAL.addAttr(~0U, Attributes(PA));
Func->setAttributes(PALnew);
}
void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
Function *Func = unwrap<Function>(Fn);
const AttrListPtr PAL = Func->getAttributes();
- const AttrListPtr PALnew = PAL.removeAttr(~0U, PA);
+ const AttrListPtr PALnew = PAL.removeAttr(~0U, Attributes(PA));
Func->setAttributes(PALnew);
}
@@ -1365,7 +1366,7 @@ LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn) {
Function *Func = unwrap<Function>(Fn);
const AttrListPtr PAL = Func->getAttributes();
Attributes attr = PAL.getFnAttributes();
- return (LLVMAttribute)attr;
+ return (LLVMAttribute)attr.Raw();
}
/*--.. Operations on parameters ............................................--*/
@@ -1427,18 +1428,18 @@ LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) {
}
void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
- unwrap<Argument>(Arg)->addAttr(PA);
+ unwrap<Argument>(Arg)->addAttr(Attributes(PA));
}
void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
- unwrap<Argument>(Arg)->removeAttr(PA);
+ unwrap<Argument>(Arg)->removeAttr(Attributes(PA));
}
LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg) {
Argument *A = unwrap<Argument>(Arg);
Attributes attr = A->getParent()->getAttributes().getParamAttributes(
A->getArgNo()+1);
- return (LLVMAttribute)attr;
+ return (LLVMAttribute)attr.Raw();
}
@@ -1635,14 +1636,14 @@ void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index,
LLVMAttribute PA) {
CallSite Call = CallSite(unwrap<Instruction>(Instr));
Call.setAttributes(
- Call.getAttributes().addAttr(index, PA));
+ Call.getAttributes().addAttr(index, Attributes(PA)));
}
void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
LLVMAttribute PA) {
CallSite Call = CallSite(unwrap<Instruction>(Instr));
Call.setAttributes(
- Call.getAttributes().removeAttr(index, PA));
+ Call.getAttributes().removeAttr(index, Attributes(PA)));
}
void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index ea773b3..b678f25 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -547,7 +547,7 @@ void Verifier::VerifyParameterAttrs(Attributes Attrs, Type *Ty,
for (unsigned i = 0;
i < array_lengthof(Attribute::MutuallyIncompatible); ++i) {
Attributes MutI = Attrs & Attribute::MutuallyIncompatible[i];
- Assert1(!(MutI & (MutI - 1)), "Attributes " +
+ Assert1(MutI.isEmptyOrSingleton(), "Attributes " +
Attribute::getAsString(MutI) + " are incompatible!", V);
}
@@ -607,7 +607,7 @@ void Verifier::VerifyFunctionAttrs(FunctionType *FT,
for (unsigned i = 0;
i < array_lengthof(Attribute::MutuallyIncompatible); ++i) {
Attributes MutI = FAttrs & Attribute::MutuallyIncompatible[i];
- Assert1(!(MutI & (MutI - 1)), "Attributes " +
+ Assert1(MutI.isEmptyOrSingleton(), "Attributes " +
Attribute::getAsString(MutI) + " are incompatible!", V);
}
}