From 92432a8db1266f7932bce13a7e6354b0993838d3 Mon Sep 17 00:00:00 2001
From: Duncan Sands <baldrick@free.fr>
Date: Tue, 8 Apr 2008 07:23:58 +0000
Subject: [PATCH] Convenience method for setting the nounwind attribute for a
 function.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49373 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/llvm/Function.h | 1 +
 lib/VMCore/Function.cpp | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/include/llvm/Function.h b/include/llvm/Function.h
index ae51fe2f00b..28c301fe2f6 100644
--- a/include/llvm/Function.h
+++ b/include/llvm/Function.h
@@ -178,6 +178,7 @@ public:
 
   /// @brief Determine if the function cannot return.
   bool doesNotReturn() const { return paramHasAttr(0, ParamAttr::NoReturn); }
+  void setDoesNotThrow(bool doesNotThrow = true);
 
   /// @brief Determine if the function cannot unwind.
   bool doesNotThrow() const {
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 6571f10be5d..de011c07bf6 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -219,6 +219,15 @@ void Function::dropAllReferences() {
   BasicBlocks.clear();    // Delete all basic blocks...
 }
 
+void Function::setDoesNotThrow(bool doesNotThrow) {
+  PAListPtr PAL = getParamAttrs();
+  if (doesNotThrow)
+    PAL = PAL.addAttr(0, ParamAttr::NoUnwind);
+  else
+    PAL = PAL.removeAttr(0, ParamAttr::NoUnwind);
+  setParamAttrs(PAL);
+}
+
 // Maintain the collector name for each function in an on-the-side table. This
 // saves allocating an additional word in Function for programs which do not use
 // GC (i.e., most programs) at the cost of increased overhead for clients which