clang 23.0.0git
Compiler.h
Go to the documentation of this file.
1//===-- clang/Support/Compiler.h - Compiler abstraction support -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines explicit visibility macros used to export symbols from
10// clang-cpp
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef CLANG_SUPPORT_COMPILER_H
15#define CLANG_SUPPORT_COMPILER_H
16
17#include "llvm/Support/Compiler.h"
18
19/// CLANG_ABI is the main export/visibility macro to mark something as
20/// explicitly exported when clang is built as a shared library with everything
21/// else that is unannotated having hidden visibility.
22///
23/// CLANG_EXPORT_TEMPLATE is used on explicit template instantiations in source
24/// files that were declared extern in a header. This macro is only set as a
25/// compiler export attribute on windows, on other platforms it does nothing.
26///
27/// CLANG_TEMPLATE_ABI is for annotating extern template declarations in headers
28/// for both functions and classes. On windows its turned in to dllimport for
29/// library consumers, for other platforms its a default visibility attribute.
30///
31/// CLANG_ABI_EXPORT always exports (or, in a static build, does nothing), it
32/// never expands to dllimport. It is the clang analogue of LLVM_ABI_EXPORT and
33/// is used where a symbol must be exported by the defining library but must not
34/// be imported by consumers.
35#ifndef CLANG_ABI_GENERATING_ANNOTATIONS
36// Marker to add to classes or functions in public headers that should not have
37// export macros added to them by the clang tool
38#define CLANG_ABI_NOT_EXPORTED
39// Some libraries like those for tablegen are linked in to tools that used
40// in the build so can't depend on the llvm shared library. If export macros
41// were left enabled when building these we would get duplicate or
42// missing symbol linker errors on windows.
43#if defined(CLANG_BUILD_STATIC)
44#define CLANG_ABI
45#define CLANG_ABI_EXPORT
46#define CLANG_TEMPLATE_ABI
47#define CLANG_EXPORT_TEMPLATE
48#elif defined(_WIN32) && !defined(__MINGW32__)
49#if defined(CLANG_EXPORTS)
50#define CLANG_ABI __declspec(dllexport)
51#define CLANG_TEMPLATE_ABI
52#define CLANG_EXPORT_TEMPLATE __declspec(dllexport)
53#else
54#define CLANG_ABI __declspec(dllimport)
55#define CLANG_TEMPLATE_ABI __declspec(dllimport)
56#define CLANG_EXPORT_TEMPLATE
57#endif
58#define CLANG_ABI_EXPORT __declspec(dllexport)
59#elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \
60 defined(__MVS__) || defined(__CYGWIN__)
61#define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
62#define CLANG_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
63#define CLANG_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
64#define CLANG_EXPORT_TEMPLATE
65#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__)
66#define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
67#define CLANG_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
68#define CLANG_TEMPLATE_ABI
69#define CLANG_EXPORT_TEMPLATE
70#endif
71#endif
72
73#endif