llvm-project/compiler-rt/test/builtins/Unit/trampoline_setup_test.c
Reid Kleckner 8c78ca2e8f [builtins] Get the builtins tests passing on Windows
Many things were broken:

- We stopped building most builtins on Windows in r261432 for reasons
  that are not at all clear to me. This essentially reverts that patch.

- Fix %librt to expand to clang_rt.builtins-$arch.lib on Windows instead
  of libclang_rt.builtins-$arch.a.

- Fix memory protection tests (trampoline, enable executable, clear
  cache) on Windows. One issue was that the MSVC incremental linker
  generates ILT thunks for functions with external linkage, so memcpying
  the functions into the executable stack buffer wasn't working. You
  can't memcpy an RIP-relative jump without fixing up the offset.

- Disable tests that rely on C99 complex library functions when using
  the MSVC CRT, which isn't compatible with clang's C99 _Complex.

In theory, these could all be separate patches, but it would not green
the tests, so let's try for it all at once. Hopefully this fixes the
clang-x64-ninja-win7 bot.

llvm-svn: 299780
2017-04-07 16:35:09 +00:00

65 lines
1.3 KiB
C

// RUN: %clang_builtins %s %librt -fnested-functions -o %t && %run %t
/* ===-- trampoline_setup_test.c - Test __trampoline_setup -----------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*/
#include <stdio.h>
#include <string.h>
#include <stdint.h>
/*
* Tests nested functions
* The ppc compiler generates a call to __trampoline_setup
* The i386 and x86_64 compilers generate a call to ___enable_execute_stack
*/
/*
* Note that, nested functions are not ISO C and are not supported in Clang.
*/
#if !defined(__clang__)
typedef int (*nested_func_t)(int x);
nested_func_t proc;
int main() {
/* Some locals */
int c = 10;
int d = 7;
/* Define a nested function: */
int bar(int x) { return x*5 + c*d; };
/* Assign global to point to nested function
* (really points to trampoline). */
proc = bar;
/* Invoke nested function: */
c = 4;
if ( (*proc)(3) != 43 )
return 1;
d = 5;
if ( (*proc)(4) != 40 )
return 1;
/* Success. */
return 0;
}
#else
int main() {
printf("skipped\n");
return 0;
}
#endif