xref: /aosp_15_r20/external/cronet/build/rust/std/compiler_specific.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker // Copyright 2023 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker 
5*6777b538SAndroid Build Coastguard Worker // This file has been copied from //base/compiler_specific.h (and then
6*6777b538SAndroid Build Coastguard Worker // significantly trimmed to just the APIs / macros needed by //build/rust/std).
7*6777b538SAndroid Build Coastguard Worker //
8*6777b538SAndroid Build Coastguard Worker // TODO(https://crbug.com/1475734): Avoid code duplication / reuse code.
9*6777b538SAndroid Build Coastguard Worker 
10*6777b538SAndroid Build Coastguard Worker #ifndef BUILD_RUST_STD_COMPILER_SPECIFIC_H_
11*6777b538SAndroid Build Coastguard Worker #define BUILD_RUST_STD_COMPILER_SPECIFIC_H_
12*6777b538SAndroid Build Coastguard Worker 
13*6777b538SAndroid Build Coastguard Worker #include "build/build_config.h"
14*6777b538SAndroid Build Coastguard Worker 
15*6777b538SAndroid Build Coastguard Worker #if defined(COMPILER_MSVC) && !defined(__clang__)
16*6777b538SAndroid Build Coastguard Worker #error "Only clang-cl is supported on Windows, see https://crbug.com/988071"
17*6777b538SAndroid Build Coastguard Worker #endif
18*6777b538SAndroid Build Coastguard Worker 
19*6777b538SAndroid Build Coastguard Worker #if defined(__has_attribute)
20*6777b538SAndroid Build Coastguard Worker #define HAS_ATTRIBUTE(x) __has_attribute(x)
21*6777b538SAndroid Build Coastguard Worker #else
22*6777b538SAndroid Build Coastguard Worker #define HAS_ATTRIBUTE(x) 0
23*6777b538SAndroid Build Coastguard Worker #endif
24*6777b538SAndroid Build Coastguard Worker 
25*6777b538SAndroid Build Coastguard Worker // Annotate a function indicating it should not be inlined.
26*6777b538SAndroid Build Coastguard Worker // Use like:
27*6777b538SAndroid Build Coastguard Worker //   NOINLINE void DoStuff() { ... }
28*6777b538SAndroid Build Coastguard Worker #if defined(__clang__) && HAS_ATTRIBUTE(noinline)
29*6777b538SAndroid Build Coastguard Worker #define NOINLINE [[clang::noinline]]
30*6777b538SAndroid Build Coastguard Worker #elif defined(COMPILER_GCC) && HAS_ATTRIBUTE(noinline)
31*6777b538SAndroid Build Coastguard Worker #define NOINLINE __attribute__((noinline))
32*6777b538SAndroid Build Coastguard Worker #elif defined(COMPILER_MSVC)
33*6777b538SAndroid Build Coastguard Worker #define NOINLINE __declspec(noinline)
34*6777b538SAndroid Build Coastguard Worker #else
35*6777b538SAndroid Build Coastguard Worker #define NOINLINE
36*6777b538SAndroid Build Coastguard Worker #endif
37*6777b538SAndroid Build Coastguard Worker 
38*6777b538SAndroid Build Coastguard Worker #endif  // BUILD_RUST_STD_COMPILER_SPECIFIC_H_
39