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

Doug Wyatt via cfe-commits cfe-commits at lists.llvm.org
Mon May 6 08:54:46 PDT 2024


================
@@ -7963,6 +7967,148 @@ static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr &Attr) {
   llvm_unreachable("unexpected attribute kind!");
 }
 
+ExprResult Sema::ActOnEffectExpression(Expr *CondExpr, FunctionEffectMode &Mode,
+                                       bool RequireConstexpr) {
+  // see checkFunctionConditionAttr, Sema::CheckCXXBooleanCondition
+  if (RequireConstexpr || !CondExpr->isTypeDependent()) {
+    ExprResult E = PerformContextuallyConvertToBool(CondExpr);
+    if (E.isInvalid())
+      return E;
+    CondExpr = E.get();
+    if (RequireConstexpr || !CondExpr->isValueDependent()) {
+      llvm::APSInt CondInt;
+      E = VerifyIntegerConstantExpression(
----------------
dougsonos wrote:

> Also, can you add some test cases with placeholder expressions as the argument, e.g. `[[clang::nonblocking(__builtin_memset)]]`, and also a case where the argument is an unexpanded pack?

Not quite sure how to construct a test that won't fail in uninteresting other ways ... e.g.

```
void t5() [[clang::nonblocking(__builtin_memset)]] {}
// error: nonblocking attribute requires an integer constant
// (via err_attribute_argument_type)

template <bool V>
struct ValueDependent {};

template <typename X>
struct TypeDependent {};

ValueDependent<__builtin_memset> x3;
// error: builtin functions must be directly called

TypeDependent<__builtin_memset> x3;
// error: template argument for template type parameter must be a type
```

I wasn't able to find examples of tests using unexpanded packs, at least not in Sema. Would appreciate any tips, thanks. I've got a few more basic tests done and will push those shortly.

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


More information about the cfe-commits mailing list