================
@@ -8631,17 +8632,126 @@ static void HandleNeonVectorTypeAttr(QualType 
&CurType, const ParsedAttr &Attr,
   CurType = S.Context.getVectorType(CurType, numElts, VecKind);
 }
 
+struct PointerAuthQualifierOptions {
+  PointerAuthenticationMode AuthenticationMode =
+      PointerAuthenticationMode::SignAndAuth;
+  bool IsIsaPointer = false;
+  bool AuthenticatesNullValues = false;
+};
+
+static bool
+checkPointerAuthQualiferOptions(Sema &S, Expr *OptionsExpr,
+                                PointerAuthQualifierOptions &Result) {
+  if (!OptionsExpr)
+    return true;
+  if (OptionsExpr->containsErrors())
+    return false;
+
+  if (OptionsExpr->isValueDependent() || OptionsExpr->isTypeDependent()) {
+    S.Diag(OptionsExpr->getExprLoc(),
+           diag::err_ptrauth_dependent_options_string)
+        << OptionsExpr->getSourceRange();
+    return false;
+  }
+
+  auto EvaluatedOptions = S.EvaluateAsAnyKindOfConstantStringYo(
+      OptionsExpr, Sema::StringEvaluationContext::PointerAuthOptions,
+      /*ErrorOnInvalidMessage=*/true);
+  if (!EvaluatedOptions)
+    return false;
+  StringRef OptionsString = StringRef(*EvaluatedOptions).trim();
+  if (OptionsString.empty())
+    return true;
+
+  SmallVector<StringRef, 4> Options;
+  OptionsString.split(Options, ',');
+  auto IsOptionCharacter = [](char Ch) {
+    return llvm::isAlpha(Ch) || Ch == '-';
+  };
+  auto MatchFns = [&](auto... Predicates) {
+    auto MergedPredicates = [=](char Ch) { return (Predicates(Ch) || ...); };
+    return [=](StringRef Str) {
+      return !Str.empty() &&
+             Str.find_if_not(MergedPredicates) == StringRef::npos;
+    };
+  };
+  auto IsOption = MatchFns(IsOptionCharacter);
+  auto IsWSSeparatedOptions = MatchFns(IsOptionCharacter, isWhitespace);
+  auto Fail = [&](unsigned DiagId, auto... DiagArgs) {
+    SourceRange ErrorRange = OptionsExpr->getSourceRange();
+    SourceLocation ErrorLoc = ErrorRange.getBegin();
+    (S.Diag(ErrorLoc, DiagId) << ... << DiagArgs) << ErrorRange;
+    if (!isa<StringLiteral>(OptionsExpr))
+      S.Diag(ErrorLoc, diag::note_ptrauth_evaluated_options) << OptionsString;
+    return false;
+  };
----------------
cor3ntin wrote:

this is still way too general for just parsing one of 3 possible strings, imo

https://github.com/llvm/llvm-project/pull/136828
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to