Skip to content

Commit

Permalink
Merge pull request #726 from gmarkall/ban-alwaysinline-noinline
Browse files Browse the repository at this point in the history
Disallow alwaysinline and noinline on functions
  • Loading branch information
esc committed Jun 16, 2021
2 parents 990a0d4 + 0ba9bd9 commit a1dcfe5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docs/source/glossary.rst
Expand Up @@ -44,8 +44,9 @@ getelementptr
An LLVM :ref:`instruction` that lets you get the address of a
subelement of an aggregate data structure.

See :llvm:ref:`i_getelementptr` in the official LLVM
documentation.
See `the getelementptr instruction
<https://releases.llvm.org/10.0.0/docs/LangRef.html#i-getelementptr>`_ in the
official LLVM documentation.


.. _global value:
Expand Down
7 changes: 7 additions & 0 deletions llvmlite/ir/values.py
Expand Up @@ -556,6 +556,13 @@ def __init__(self, args=()):
self._personality = None
super(FunctionAttributes, self).__init__(args)

def add(self, name):
if ((name == 'alwaysinline' and 'noinline' in self) or
(name == 'noinline' and 'alwaysinline' in self)):
raise ValueError("Can't have alwaysinline and noinline")

super().add(name)

@property
def alignstack(self):
return self._alignstack
Expand Down
18 changes: 18 additions & 0 deletions llvmlite/tests/test_ir.py
Expand Up @@ -209,6 +209,24 @@ def test_pickling(self):
fn = self.function()
self.assert_pickle_correctly(fn)

def test_alwaysinline_noinline_disallowed(self):
module = self.module()
func = self.function(module)
func.attributes.add('alwaysinline')

msg = "Can't have alwaysinline and noinline"
with self.assertRaisesRegex(ValueError, msg):
func.attributes.add('noinline')

def test_noinline_alwaysinline_disallowed(self):
module = self.module()
func = self.function(module)
func.attributes.add('noinline')

msg = "Can't have alwaysinline and noinline"
with self.assertRaisesRegex(ValueError, msg):
func.attributes.add('alwaysinline')


class TestIR(TestBase):

Expand Down

0 comments on commit a1dcfe5

Please sign in to comment.