# Buggy code
def _make_returns(self, ail_graph: networkx.DiGraph):
    """
    Work on each return statement and fill in its return expressions.
    """

    # Block walker

    def _handle_Return(
        stmt_idx: int, stmt: ailment.Stmt.Return, block: Optional[ailment.Block]
    ):  # pylint:disable=unused-argument
        if (
            block is not None
            and not stmt.ret_exprs
            and self.function.calling_convention.ret_val is not None
        ):
            new_stmt = stmt.copy()
            ret_val = self.function.calling_convention.ret_val
            if isinstance(ret_val, SimRegArg):
                reg = self.project.arch.registers[ret_val.reg_name]
                new_stmt.ret_exprs.append(
                    ailment.Expr.Register(
                        None, None, reg[0], reg[1] * self.project.arch.byte_width
                    )
                )
            else:
                l.warning(
                    "Unsupported type of return expression %s.",
                    type(self.function.calling_convention.ret_val),
                )
            block.statements[stmt_idx] = new_stmt

    def _handler(block):
        walker = AILBlockWalker()
        # we don't need to handle any statement besides Returns
        walker.stmt_handlers.clear()
        walker.expr_handlers.clear()
        walker.stmt_handlers[ailment.Stmt.Return] = _handle_Return
        walker.walk(block)

    # Graph walker

    AILGraphWalker(ail_graph, _handler, replace_nodes=True).walk()

    return ail_graph


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/main_window.py", line 496, in decompile_current_function
self.workspace.decompile_current_function()
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/workspace.py", line 265, in decompile_current_function
view.decompile_current_function()
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/views/disassembly_view.py", line 382, in decompile_current_function
self.workspace.decompile_function(self._current_function.am_obj)
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/workspace.py", line 279, in decompile_function
view.function = func
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/views/code_view.py", line 66, in function
self.decompile()
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/views/code_view.py", line 43, in decompile
d = self.workspace.instance.project.analyses.Decompiler(
File "/home/dnivra/angr-dev/angr/angr/analyses/analysis.py", line 115, in __call__
oself.__init__(*args, **kwargs)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/decompiler.py", line 24, in __init__
self._decompile()
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/decompiler.py", line 41, in _decompile
clinic = self.project.analyses.Clinic(self.func,
File "/home/dnivra/angr-dev/angr/angr/analyses/analysis.py", line 115, in __call__
oself.__init__(*args, **kwargs)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/clinic.py", line 70, in __init__
self._analyze()
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/clinic.py", line 138, in _analyze
ail_graph = self._make_returns(ail_graph)
File "/home/dnivra/angr-dev/angr/angr/utils/timing.py", line 28, in timed_func
return func(*args, **kwargs)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/clinic.py", line 457, in _make_returns
AILGraphWalker(ail_graph, _handler, replace_nodes=True).walk()
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/ailgraph_walker.py", line 23, in walk
r = self.handler(node)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/clinic.py", line 453, in _handler
walker.walk(block)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/ailblock_walker.py", line 37, in walk
self._handle_stmt(i, stmt, block)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/ailblock_walker.py", line 50, in _handle_stmt
return handler(stmt_idx, stmt, block)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/clinic.py", line 434, in _handle_Return
and self.function.calling_convention.ret_val is not None:
AttributeError: 'NoneType' object has no attribute 'ret_val'

# Fixed code
def _make_returns(self, ail_graph: networkx.DiGraph) -> networkx.DiGraph:
    """
    Work on each return statement and fill in its return expressions.
    """

    if self.function.calling_convention is None:
        # unknown calling convention. cannot do much about return expressions.
        return ail_graph

    # Block walker

    def _handle_Return(
        stmt_idx: int, stmt: ailment.Stmt.Return, block: Optional[ailment.Block]
    ):  # pylint:disable=unused-argument
        if (
            block is not None
            and not stmt.ret_exprs
            and self.function.calling_convention.ret_val is not None
        ):
            new_stmt = stmt.copy()
            ret_val = self.function.calling_convention.ret_val
            if isinstance(ret_val, SimRegArg):
                reg = self.project.arch.registers[ret_val.reg_name]
                new_stmt.ret_exprs.append(
                    ailment.Expr.Register(
                        None, None, reg[0], reg[1] * self.project.arch.byte_width
                    )
                )
            else:
                l.warning(
                    "Unsupported type of return expression %s.",
                    type(self.function.calling_convention.ret_val),
                )
            block.statements[stmt_idx] = new_stmt

    def _handler(block):
        walker = AILBlockWalker()
        # we don't need to handle any statement besides Returns
        walker.stmt_handlers.clear()
        walker.expr_handlers.clear()
        walker.stmt_handlers[ailment.Stmt.Return] = _handle_Return
        walker.walk(block)

    # Graph walker

    AILGraphWalker(ail_graph, _handler, replace_nodes=True).walk()

    return ail_graph