1//===----------------------------------------------------------------------===//
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// TODO: Investigate
10// XFAIL: msvc
11
12// Test that we encode the hardening mode in an ABI tag to avoid ODR violations
13// when linking TUs that have different values for it.
14
15// Note that GCC doesn't support `-Wno-macro-redefined`.
16// RUN: %{cxx} %s %{flags} %{compile_flags} -c -DTU1 -U_LIBCPP_HARDENING_MODE -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST -o %t.tu1.o
17// RUN: %{cxx} %s %{flags} %{compile_flags} -c -DTU2 -U_LIBCPP_HARDENING_MODE -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -o %t.tu2.o
18// RUN: %{cxx} %s %{flags} %{compile_flags} -c -DTU3 -U_LIBCPP_HARDENING_MODE -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG -o %t.tu3.o
19// RUN: %{cxx} %s %{flags} %{compile_flags} -c -DTU4 -U_LIBCPP_HARDENING_MODE -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -o %t.tu4.o
20// RUN: %{cxx} %s %{flags} %{compile_flags} -c -DMAIN -o %t.main.o
21// RUN: %{cxx} %t.tu1.o %t.tu2.o %t.tu3.o %t.tu4.o %t.main.o %{flags} %{link_flags} -o %t.exe
22// RUN: %{exec} %t.exe
23
24// fast hardening mode
25#ifdef TU1
26# include <__config>
27_LIBCPP_HIDE_FROM_ABI inline int f() { return 1; }
28int tu1() { return f(); }
29#endif // TU1
30
31// extensive hardening mode
32#ifdef TU2
33# include <__config>
34_LIBCPP_HIDE_FROM_ABI inline int f() { return 2; }
35int tu2() { return f(); }
36#endif // TU2
37
38// debug hardening mode
39#ifdef TU3
40# include <__config>
41_LIBCPP_HIDE_FROM_ABI inline int f() { return 3; }
42int tu3() { return f(); }
43#endif // TU3
44
45// No hardening
46#ifdef TU4
47# include <__config>
48_LIBCPP_HIDE_FROM_ABI inline int f() { return 4; }
49int tu4() { return f(); }
50#endif // TU4
51
52#ifdef MAIN
53# include <cassert>
54
55int tu1();
56int tu2();
57int tu3();
58int tu4();
59
60int main(int, char**) {
61 assert(tu1() == 1);
62 assert(tu2() == 2);
63 assert(tu3() == 3);
64 assert(tu4() == 4);
65 return 0;
66}
67#endif // MAIN
68

source code of libcxx/test/libcxx/odr_signature.hardening.sh.cpp