I implemented a custom attribute in clang as described in the official manual:
How to add an attribute in Clang
I added a definition to include/clang/Basic/Attr.td
def attr : InheritableAttr {
let Spellings = [GCC<"attr">, Declspec<"attr">];
// FIXME: Does GCC allow this on the function instead?
let Documentation = [Undocumented];
}
and implement the semantic processing of the attribute in SemaDeclAttr.cpp
by adding a new case.
case AttributeList::AT_MyAttr:
handleSimpleAttribute<MyAttrAttr>(S, D, Attr);
break;
After rebuilding clang, it obviously knows the attribute because i don't get an unknown attribute warning when using it.
But I can't get this attribute in LLVM Pass by function hasFnAttribute()
bool runOnFunction(Function &F) override {
// it didn't work
if (F.hasFnAttribute("attr")){
return false;
}
return false;
}
Attribute::AttrKind
doesn't have Attribute::attr
. I try to change /llvm/include/llvm/IR/Attributes.td
and some code to make clang run. But it didn't work.
Is there something else i need to consider or what could be the problem?