xref: /aosp_15_r20/external/angle/build/rust/std/alias.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker // Copyright 2023 The Chromium Authors
2*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
4*8975f5c5SAndroid Build Coastguard Worker 
5*8975f5c5SAndroid Build Coastguard Worker // This file has been copied from //base/debug/alias.h (and then trimmed to just
6*8975f5c5SAndroid Build Coastguard Worker // the APIs / macros needed by //build/rust/std;  additionally the APIs were
7*8975f5c5SAndroid Build Coastguard Worker // moved into the `build_rust_std` namespace).
8*8975f5c5SAndroid Build Coastguard Worker //
9*8975f5c5SAndroid Build Coastguard Worker // TODO(crbug.com/40279749): Avoid code duplication / reuse code.
10*8975f5c5SAndroid Build Coastguard Worker 
11*8975f5c5SAndroid Build Coastguard Worker #ifndef BUILD_RUST_STD_ALIAS_H_
12*8975f5c5SAndroid Build Coastguard Worker #define BUILD_RUST_STD_ALIAS_H_
13*8975f5c5SAndroid Build Coastguard Worker 
14*8975f5c5SAndroid Build Coastguard Worker #include <stddef.h>
15*8975f5c5SAndroid Build Coastguard Worker 
16*8975f5c5SAndroid Build Coastguard Worker namespace build_rust_std {
17*8975f5c5SAndroid Build Coastguard Worker namespace debug {
18*8975f5c5SAndroid Build Coastguard Worker 
19*8975f5c5SAndroid Build Coastguard Worker // Make the optimizer think that |var| is aliased. This can be used to prevent a
20*8975f5c5SAndroid Build Coastguard Worker // local variable from being optimized out (which is something that
21*8975f5c5SAndroid Build Coastguard Worker // `NO_CODE_FOLDING` macro definition below depends on).  See
22*8975f5c5SAndroid Build Coastguard Worker // //base/debug/alias.h for more details.
23*8975f5c5SAndroid Build Coastguard Worker void Alias(const void* var);
24*8975f5c5SAndroid Build Coastguard Worker 
25*8975f5c5SAndroid Build Coastguard Worker }  // namespace debug
26*8975f5c5SAndroid Build Coastguard Worker 
27*8975f5c5SAndroid Build Coastguard Worker }  // namespace build_rust_std
28*8975f5c5SAndroid Build Coastguard Worker 
29*8975f5c5SAndroid Build Coastguard Worker // Prevent code folding (where a linker identifies functions that are
30*8975f5c5SAndroid Build Coastguard Worker // bit-identical and overlays them, which saves space but it leads to confusing
31*8975f5c5SAndroid Build Coastguard Worker // call stacks because multiple symbols are at the same address).  See
32*8975f5c5SAndroid Build Coastguard Worker // //base/debug/alias.h for more details.
33*8975f5c5SAndroid Build Coastguard Worker #define NO_CODE_FOLDING()           \
34*8975f5c5SAndroid Build Coastguard Worker   const int line_number = __LINE__; \
35*8975f5c5SAndroid Build Coastguard Worker   build_rust_std::debug::Alias(&line_number)
36*8975f5c5SAndroid Build Coastguard Worker 
37*8975f5c5SAndroid Build Coastguard Worker #endif  // BUILD_RUST_STD_ALIAS_H_
38