[clang] nolock/noalloc attributes (PR #84983)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 13 08:25:31 PDT 2024
================
@@ -4912,3 +4922,279 @@ void AutoType::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
Profile(ID, Context, getDeducedType(), getKeyword(), isDependentType(),
getTypeConstraintConcept(), getTypeConstraintArguments());
}
+
+FunctionEffect::~FunctionEffect() = default;
+
+bool FunctionEffect::diagnoseConversion(bool Adding, QualType OldType,
+ FunctionEffectSet OldFX,
+ QualType NewType,
+ FunctionEffectSet NewFX) const {
+ return false;
+}
+
+bool FunctionEffect::diagnoseRedeclaration(bool Adding,
+ const FunctionDecl &OldFunction,
+ FunctionEffectSet OldFX,
+ const FunctionDecl &NewFunction,
+ FunctionEffectSet NewFX) const {
+ return false;
+}
+
+bool FunctionEffect::diagnoseMethodOverride(bool Adding,
+ const CXXMethodDecl &OldMethod,
+ FunctionEffectSet OldFX,
+ const CXXMethodDecl &NewMethod,
+ FunctionEffectSet NewFX) const {
+ return false;
+}
+
+bool FunctionEffect::canInferOnDecl(const Decl *Caller,
+ FunctionEffectSet CallerFX) const {
+ return false;
+}
+
+bool FunctionEffect::diagnoseFunctionCall(bool Direct, const Decl *Caller,
+ FunctionEffectSet CallerFX,
+ CalleeDeclOrType Callee,
+ FunctionEffectSet CalleeFX) const {
+ return false;
+}
+
+const NoLockNoAllocEffect &NoLockNoAllocEffect::nolock_instance() {
+ static NoLockNoAllocEffect global(kNoLockTrue, "nolock");
+ return global;
+}
----------------
Sirraide wrote:
With the `[[]]` syntax, attributes that appertain to a function declaration come before the return type, and attributes that appertain to the function type come after the parameter list, yeah.
Looking at this again, `AttributedType` makes sense for this, I’d say. `DeclOrTypeAttr` is probably fine for this, because I don’t think you can put a `TypeAttr` *before* a function if you want to be able to do that, but if you don’t care about that being possible, then a `TypeAttr` is probably simpler.
So, to get back to what this comment was originally about, if I understand the situation correctly, you can attach `nolock`/`noalloc` (optionally w/ an expression argument) to function types. This is done using `AttributedType`s, which makes sense. The presence/absence of these attributes may affect how effects are inferred.
At the same time, we would also like to track effects on the `FunctionProtoType`, so what I’m thinking is, it may it be possible to use only the attributes for inference, and track effects as a bitmask on the `FunctionProtoType` (see also the comment I made about this further down wrt one of the questions in your initial pr comment). With all of that in mind, it’s not quite clear to me what purpose the `nolock_instance()` serves in all of this?
https://github.com/llvm/llvm-project/pull/84983
More information about the cfe-commits
mailing list