[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 16 10:47:29 PDT 2024
================
@@ -395,6 +395,33 @@ bool Sema::checkStringLiteralArgumentAttr(const ParsedAttr &AL, unsigned ArgNum,
return checkStringLiteralArgumentAttr(AL, ArgExpr, Str, ArgLocation);
}
+/// Check if the argument \p ArgNum of \p Attr is a compile-time constant
+/// integer (boolean) expression. If not, emit an error and return false.
+bool Sema::checkBoolExprArgumentAttr(const ParsedAttr &AL, unsigned ArgNum,
+ bool &Value) {
+ if (AL.isInvalid()) {
+ return false;
+ }
+ Expr *ArgExpr = AL.getArgAsExpr(ArgNum);
+ SourceLocation ErrorLoc(AL.getLoc());
+
+ if (AL.isArgIdent(ArgNum)) {
+ IdentifierLoc *IL = AL.getArgAsIdent(ArgNum);
+ ErrorLoc = IL->Loc;
+ } else if (ArgExpr != nullptr) {
+ if (const std::optional<llvm::APSInt> MaybeVal =
+ ArgExpr->getIntegerConstantExpr(Context, &ErrorLoc)) {
+ Value = MaybeVal->getBoolValue();
+ return true;
+ }
+ }
----------------
Sirraide wrote:
Specifying `ExprArgument` in `Attr.td` takes care of the parsing the expression, yeah.
https://github.com/llvm/llvm-project/pull/84983
More information about the cfe-commits
mailing list