================ @@ -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; + } + } ---------------- dougsonos wrote:
Thank you! I was looking for precedents for this and couldn't find it on any attributes. It bugged me that I was writing something like this. Yes, the parameter can be an arbitrary expression. But if it is dependent: then how would we represent `nolock(expression)` before we can evaluate the expression? And when would it be collapsed back into a concretely true or false form? https://github.com/llvm/llvm-project/pull/84983 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits