HomePhabricator

Add LIFETIMEBOUND attributes where needed

Description

Add LIFETIMEBOUND attributes where needed

Summary:

Without this, stack-use-after-scope can only be detected at runtime with ASan or code review, both of which are expensive.

Use LIFETIMEBOUND to turn this error into a compile warning.

See https://releases.llvm.org/12.0.0/tools/clang/docs/AttributeReference.html#lifetimebound

Example:

const CScript a{WITH_LOCK(::cs_main, return CScript{} << OP_0 << OP_1)};

Before: (no warning)
After:

warning: returning reference to local temporary object [-Wreturn-stack-address]
    const CScript a{WITH_LOCK(::cs_main, return CScript{} << OP_0 << OP_1)};
                                                ^~~~~~~~~
./sync.h:276:65: note: expanded from macro 'WITH_LOCK'
                                                                ^~~~

Backport of core#22278.

Test Plan:
With Clang:

ninja all check

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D12207

Details

Provenance
FabienAuthored on Oct 11 2022, 15:18
FabienPushed on Oct 11 2022, 18:15
Reviewer
Restricted Project
Differential Revision
D12207: Add LIFETIMEBOUND attributes where needed
Parents
rABC0804a0d47eaf: Small fix to the node broadcast logic
Branches
Unknown
Tags
Unknown