Page MenuHomePhabricator

Add LIFETIMEBOUND attributes where needed
ClosedPublic

Authored by Fabien on Oct 11 2022, 15:22.

Details

Reviewers
PiRK
Group Reviewers
Restricted Project
Commits
rABC571e91c2c95d: 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