[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

via cfe-commits cfe-commits at lists.llvm.org
Thu May 23 20:22:32 PDT 2024


================
@@ -7518,6 +7523,154 @@ static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr &Attr) {
   llvm_unreachable("unexpected attribute kind!");
 }
 
+std::optional<FunctionEffectMode>
+Sema::ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName) {
+  auto BadExpr = [&]() {
+    Diag(CondExpr->getExprLoc(), diag::err_attribute_argument_type)
+        << ("'" + AttributeName.str() + "'") << AANT_ArgumentIntegerConstant
+        << CondExpr->getSourceRange();
+    return std::nullopt;
+  };
+
+  if (CondExpr->isTypeDependent() || CondExpr->isValueDependent()) {
+    if (CondExpr->containsUnexpandedParameterPack())
+      return BadExpr();
+    return FunctionEffectMode::Dependent;
+  }
+
+  std::optional<llvm::APSInt> ConditionValue =
+      CondExpr->getIntegerConstantExpr(Context);
+  if (!ConditionValue)
+    return BadExpr();
+  return ConditionValue->getExtValue() ? FunctionEffectMode::True
----------------
Sirraide wrote:

```suggestion
  return !ConditionValue->isZero() ? FunctionEffectMode::True
```
`getExtValue()` will fail in weird situations (e.g. if someone decides to pass a sufficiently large `__int128` as an argument to this attribute).

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


More information about the cfe-commits mailing list