xref: /aosp_15_r20/external/cronet/build/rust/std/compiler_specific.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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/compiler_specific.h (and then
6 // significantly trimmed to just the APIs / macros needed by //build/rust/std).
7 //
8 // TODO(https://crbug.com/1475734): Avoid code duplication / reuse code.
9 
10 #ifndef BUILD_RUST_STD_COMPILER_SPECIFIC_H_
11 #define BUILD_RUST_STD_COMPILER_SPECIFIC_H_
12 
13 #include "build/build_config.h"
14 
15 #if defined(COMPILER_MSVC) && !defined(__clang__)
16 #error "Only clang-cl is supported on Windows, see https://crbug.com/988071"
17 #endif
18 
19 #if defined(__has_attribute)
20 #define HAS_ATTRIBUTE(x) __has_attribute(x)
21 #else
22 #define HAS_ATTRIBUTE(x) 0
23 #endif
24 
25 // Annotate a function indicating it should not be inlined.
26 // Use like:
27 //   NOINLINE void DoStuff() { ... }
28 #if defined(__clang__) && HAS_ATTRIBUTE(noinline)
29 #define NOINLINE [[clang::noinline]]
30 #elif defined(COMPILER_GCC) && HAS_ATTRIBUTE(noinline)
31 #define NOINLINE __attribute__((noinline))
32 #elif defined(COMPILER_MSVC)
33 #define NOINLINE __declspec(noinline)
34 #else
35 #define NOINLINE
36 #endif
37 
38 #endif  // BUILD_RUST_STD_COMPILER_SPECIFIC_H_
39