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