[IR] Add interface to remove a CallBase string function attribute
authorTeresa Johnson <tejohnson@google.com>
Wed, 26 Apr 2023 13:35:12 +0000 (06:35 -0700)
committerTeresa Johnson <tejohnson@google.com>
Wed, 26 Apr 2023 15:47:15 +0000 (08:47 -0700)
Adds an interface to remove a string function attribute attached to a
CallBase, and a corresponding unittest.

This was extracted from D141077, and will be used by a follow on patch
that removes memprof attributes when needed.

Reviewed By: snehasish

Differential Revision: https://reviews.llvm.org/D149192

llvm/include/llvm/IR/InstrTypes.h
llvm/unittests/IR/InstructionsTest.cpp

index 980a460..53aff55 100644 (file)
@@ -1559,6 +1559,11 @@ public:
     Attrs = Attrs.removeFnAttribute(getContext(), Kind);
   }
 
+  /// Removes the attribute from the function
+  void removeFnAttr(StringRef Kind) {
+    Attrs = Attrs.removeFnAttribute(getContext(), Kind);
+  }
+
   /// Removes the attribute from the return value
   void removeRetAttr(Attribute::AttrKind Kind) {
     Attrs = Attrs.removeRetAttribute(getContext(), Kind);
index eb506f6..b43a8c0 100644 (file)
@@ -102,6 +102,11 @@ TEST_F(ModuleWithFunctionTest, CallInst) {
   Call->addRetAttr(Attribute::get(Call->getContext(), "test-str-attr"));
   EXPECT_TRUE(Call->hasRetAttr("test-str-attr"));
   EXPECT_FALSE(Call->hasRetAttr("not-on-call"));
+
+  Call->addFnAttr(Attribute::get(Call->getContext(), "test-str-fn-attr"));
+  ASSERT_TRUE(Call->hasFnAttr("test-str-fn-attr"));
+  Call->removeFnAttr("test-str-fn-attr");
+  EXPECT_FALSE(Call->hasFnAttr("test-str-fn-attr"));
 }
 
 TEST_F(ModuleWithFunctionTest, InvokeInst) {