[clang] nolock/noalloc attributes (PR #84983)

via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 13 06:54:53 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:

I may still be misunderstanding something, but by ‘it only has meaning when attached to Decls’, do you mean that e.g.
```c++
using Foo = void () __attribute__((nolock(false)));
__attribute__((nolock)) void foo(Foo f) {
    f(); // Error/warning or sth?
}
```
is something you’re *not* planning to support? In that case, does it even need to appertain to types instead of just to declarations?

Also, the rules for where you can put `__attribute__` and `[[]]` are different in some cases, as I recall, but could you maybe give an example of what exactly you mean by ‘violates a hard rule about placement of square-bracket attributes’ wrt not being able to attach the attribute to the function decl instead of the type here (assuming of course you really only ever want to actually attach it to function declarations, not function types in general).


https://github.com/llvm/llvm-project/pull/84983


More information about the cfe-commits mailing list