[llvm] [Verifier] Check function attributes related to branch protection (NFC) (PR #70565)

Momchil Velikov via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 28 11:32:26 PDT 2023


https://github.com/momchil-velikov created https://github.com/llvm/llvm-project/pull/70565

None

>From 4c3297ffc83ce337afb644b8be5763b6363fc486 Mon Sep 17 00:00:00 2001
From: Momchil Velikov <momchil.velikov at arm.com>
Date: Sat, 28 Oct 2023 15:01:36 +0100
Subject: [PATCH] [Verifier] Check function attributes related to branch
 protection (NFC)

---
 llvm/lib/IR/Verifier.cpp | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 396af600b8dab29..863d77656478fd8 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2231,6 +2231,27 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
   checkUnsignedBaseTenFuncAttr(Attrs, "patchable-function-prefix", V);
   checkUnsignedBaseTenFuncAttr(Attrs, "patchable-function-entry", V);
   checkUnsignedBaseTenFuncAttr(Attrs, "warn-stack-size", V);
+
+  if (Attrs.hasFnAttr("sign-return-adress")) {
+    StringRef S = Attrs.getFnAttr("sign-return-adress").getValueAsString();
+    if (S != "none" && S != "all" && S != "non-leaf")
+      CheckFailed("invalid value for 'sign-return-adress' attribute: " + S, V);
+  }
+
+  if (Attrs.hasFnAttr("sign-return-adress-key")) {
+    StringRef S = Attrs.getFnAttr("sign-return-adress-key").getValueAsString();
+    if (!S.equals_insensitive("a_key") && !S.equals_insensitive("b_key"))
+      CheckFailed("invalid value for 'sign-return-adress-key' attribute: " + S,
+                  V);
+  }
+
+  if (Attrs.hasFnAttr("branch-target-enforcement")) {
+    StringRef S =
+        Attrs.getFnAttr("branch-target-enforcement").getValueAsString();
+    if (!S.equals_insensitive("true") && !S.equals_insensitive("false"))
+      CheckFailed(
+          "invalid value for 'branch-target-enforcement' attribute: " + S, V);
+  }
 }
 
 void Verifier::verifyFunctionMetadata(



More information about the llvm-commits mailing list