如官方手册中所述,我在 clang 中实现了一个自定义属性:
我添加了一个定义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];
}
SemaDeclAttr.cpp
并通过增加一个新的case来实现属性in的语义处理。
case AttributeList::AT_MyAttr:
handleSimpleAttribute<MyAttrAttr>(S, D, Attr);
break;
重建clang后,它显然知道该属性,因为我在使用它时没有收到未知属性警告。
但我无法在 LLVM Pass by function 中获取此属性hasFnAttribute()
bool runOnFunction(Function &F) override {
// it didn't work
if (F.hasFnAttribute("attr")){
return false;
}
return false;
}
Attribute::AttrKind
没有Attribute::attr
。我尝试更改/llvm/include/llvm/IR/Attributes.td
和一些代码以使 clang 运行。但它没有用。
还有什么我需要考虑的或者可能是什么问题?