Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,27 @@
// RUN: %clang -o %t1 %s
// RUN: %t1 2>&1 | FileCheck --check-prefix=NCFI %s
// RUN: %clang_cfi -o %t2 %s
// RUN: %expect_crash %t2 2>&1 | FileCheck --check-prefix=CFI %s
// RUN: %clang_cfi_diag -g -o %t3 %s
// RUN: %t3 2>&1 | FileCheck --check-prefix=CFI-DIAG %s
#include <stdio.h>
void f() {
}
int main() {
// CFI: 1
// NCFI: 1
fprintf(stderr, "1\n");
// CFI-DIAG: runtime error: control flow integrity check for type 'void (int)' failed during indirect function call
// CFI-DIAG: f defined here
((void (*)(int))f)(42); // UB here
// CFI-NOT: 2
// NCFI: 2
fprintf(stderr, "2\n");
}

View File

@@ -0,0 +1,28 @@
// RUN: %clang_cfi -lm -o %t1 %s
// RUN: %t1 c 1 2>&1 | FileCheck --check-prefix=CFI %s
// RUN: %t1 s 2 2>&1 | FileCheck --check-prefix=CFI %s
// This test uses jump tables containing PC-relative references to external
// symbols, which the Mach-O object writer does not currently support.
// The test passes on i386 Darwin and fails on x86_64, hence unsupported instead of xfail.
// UNSUPPORTED: darwin
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main(int argc, char **argv) {
// CFI: 1
fprintf(stderr, "1\n");
double (*fn)(double);
if (argv[1][0] == 's')
fn = sin;
else
fn = cos;
fn(atof(argv[2]));
// CFI: 2
fprintf(stderr, "2\n");
}

View File

@@ -0,0 +1,3 @@
# The cfi-icall checker is only supported on x86 and x86_64 for now.
if config.root.host_arch not in ['x86', 'x86_64']:
config.unsupported = True

View File

@@ -0,0 +1,15 @@
// Test that weak symbols stay weak.
// RUN: %clang_cfi -lm -o %t1 %s && %t1
// XFAIL: darwin
__attribute__((weak)) void does_not_exist(void);
__attribute__((noinline))
void foo(void (*p)(void)) {
p();
}
int main(int argc, char **argv) {
if (does_not_exist)
foo(does_not_exist);
}

View File

@@ -0,0 +1,41 @@
// Test that the checking is done with the actual type of f() even when the
// calling module has an incorrect declaration. Test a mix of lto types.
//
// -flto below overrides -flto=thin in %clang_cfi
// RUN: %clang_cfi %s -DMODULE_A -c -o %t1_a.o
// RUN: %clang_cfi %s -DMODULE_B -c -o %t1_b.o -flto
// RUN: %clang_cfi %t1_a.o %t1_b.o -o %t1
// RUN: %expect_crash %t1 2>&1 | FileCheck --check-prefix=CFI %s
//
// RUN: %clang_cfi %s -DMODULE_A -c -o %t2_a.o -flto
// RUN: %clang_cfi %s -DMODULE_B -c -o %t2_b.o
// RUN: %clang_cfi %t2_a.o %t2_b.o -o %t2
// RUN: %expect_crash %t2 2>&1 | FileCheck --check-prefix=CFI %s
//
// RUN: %clang_cfi %s -DMODULE_A -c -o %t3_a.o
// RUN: %clang_cfi %s -DMODULE_B -c -o %t3_b.o
// RUN: %clang_cfi %t3_a.o %t3_b.o -o %t3
// RUN: %expect_crash %t3 2>&1 | FileCheck --check-prefix=CFI %s
//
// REQUIRES: thinlto
#include <stdio.h>
#if defined(MODULE_B)
int f() {
return 42;
}
#elif defined(MODULE_A)
void f();
int main() {
// CFI: 1
fprintf(stderr, "1\n");
void (*volatile p)() = &f;
p();
// CFI-NOT: 2
fprintf(stderr, "2\n");
}
#endif