diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2015-02-20 20:31:18 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2015-02-20 20:31:18 +0000 |
commit | 39a4a9d2feb820fecaf8a72066b25f335da5d627 (patch) | |
tree | 5c879a8c999aa1c713dd78c3cac3766b1feb0008 /test/cfi/simple-fail.cpp | |
parent | ae387957e63894c2618b9e404949b0a6b5a26843 (diff) |
Add test suite for the Control Flow Integrity feature.
Differential Revision: http://reviews.llvm.org/D7738
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@230056 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/cfi/simple-fail.cpp')
-rw-r--r-- | test/cfi/simple-fail.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/cfi/simple-fail.cpp b/test/cfi/simple-fail.cpp new file mode 100644 index 000000000..de3b7ed1b --- /dev/null +++ b/test/cfi/simple-fail.cpp @@ -0,0 +1,37 @@ +// RUN: %clangxx_cfi -o %t %s +// RUN: not --crash %t 2>&1 | FileCheck --check-prefix=CFI %s + +// RUN: %clangxx -o %t %s +// RUN: %t 2>&1 | FileCheck --check-prefix=NCFI %s + +// Tests that the CFI mechanism crashes the program when making a virtual call +// to an object of the wrong class but with a compatible vtable, by casting a +// pointer to such an object and attempting to make a call through it. + +#include <stdio.h> + +struct A { + virtual void f(); +}; + +void A::f() {} + +struct B { + virtual void f(); +}; + +void B::f() {} + +int main() { + A *a = new A; + + // CFI: 1 + // NCFI: 1 + fprintf(stderr, "1\n"); + + ((B *)a)->f(); // UB here + + // CFI-NOT: 2 + // NCFI: 2 + fprintf(stderr, "2\n"); +} |