Skip to content

Commit

Permalink
[IR] Add interface to remove a CallBase string function attribute
Browse files Browse the repository at this point in the history
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
  • Loading branch information
teresajohnson committed Apr 26, 2023
1 parent 807f058 commit 85a13c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions llvm/include/llvm/IR/InstrTypes.h
Expand Up @@ -1559,6 +1559,11 @@ class CallBase : public Instruction {
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);
Expand Down
5 changes: 5 additions & 0 deletions llvm/unittests/IR/InstructionsTest.cpp
Expand Up @@ -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) {
Expand Down

0 comments on commit 85a13c7

Please sign in to comment.