Commit f4e12fd
committed
Merge bitcoin#22278: Add LIFETIMEBOUND to CScript where needed
fa7e6c5 Add LIFETIMEBOUND to InitializeChainstate (MarcoFalke)
fa5c896 Add LIFETIMEBOUND to CScript where needed (MarcoFalke)
Pull request description:
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:
```cpp
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'
#define WITH_LOCK(cs, code) [&]() -> decltype(auto) { LOCK(cs); code; }()
^~~~
ACKs for top commit:
theuni:
utACK fa7e6c5.
jonatack:
Light ACK fa7e6c5 debug build with clang 13, reproduced the example compiler warning in the pull description, and briefly looked at `clang::lifetimebound` support in earlier versions of clang; it is in clang 7 (https://releases.llvm.org/7.0.0/tools/clang/docs/AttributeReference.html#lifetimebound-clang-lifetimebound), did not see references to it in earlier docs
Tree-SHA512: e915acdc4532445205b7703fab61a5d682231ace78ecfb274cb8523ca2bddefd85828f50ac047cfb1afaff92a331f5f7b5a1472539f999e30f7cf8ac8c3222f32 files changed
+6
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
438 | 439 | | |
439 | 440 | | |
440 | 441 | | |
441 | | - | |
| 442 | + | |
442 | 443 | | |
443 | | - | |
| 444 | + | |
444 | 445 | | |
445 | 446 | | |
446 | 447 | | |
447 | 448 | | |
448 | 449 | | |
449 | 450 | | |
450 | 451 | | |
451 | | - | |
| 452 | + | |
452 | 453 | | |
453 | 454 | | |
454 | 455 | | |
455 | 456 | | |
456 | 457 | | |
457 | | - | |
| 458 | + | |
458 | 459 | | |
459 | 460 | | |
460 | 461 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
929 | 929 | | |
930 | 930 | | |
931 | 931 | | |
932 | | - | |
| 932 | + | |
933 | 933 | | |
934 | 934 | | |
935 | 935 | | |
| |||
0 commit comments