Skip to content

Commit

Permalink
cfi: Start testing CFI in both standalone and devirtualization modes.
Browse files Browse the repository at this point in the history
Differential Revision: http://reviews.llvm.org/D21123

llvm-svn: 273758
  • Loading branch information
pcc committed Jun 25, 2016
1 parent 0ca0363 commit c79ad57
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
15 changes: 12 additions & 3 deletions compiler-rt/test/cfi/CMakeLists.txt
@@ -1,6 +1,13 @@
set(CFI_LIT_TEST_MODE Standalone)
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
${CMAKE_CURRENT_BINARY_DIR}/Standalone/lit.site.cfg
)

set(CFI_LIT_TEST_MODE Devirt)
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/Devirt/lit.site.cfg
)

set(CFI_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
Expand Down Expand Up @@ -32,11 +39,13 @@ if(NOT COMPILER_RT_STANDALONE_BUILD)
endif()

add_lit_testsuite(check-cfi "Running the cfi regression tests"
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/Standalone
${CMAKE_CURRENT_BINARY_DIR}/Devirt
DEPENDS ${CFI_TEST_DEPS})

add_lit_target(check-cfi-and-supported "Running the cfi regression tests"
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/Standalone
${CMAKE_CURRENT_BINARY_DIR}/Devirt
PARAMS check_supported=1
DEPENDS ${CFI_TEST_DEPS})

Expand Down
8 changes: 8 additions & 0 deletions compiler-rt/test/cfi/lit.cfg
Expand Up @@ -11,6 +11,14 @@ config.substitutions.append((r"%clang ", ' '.join([config.clang]) + ' '))
config.substitutions.append((r"%clangxx ", clangxx + ' '))
if config.lto_supported:
clang_cfi = ' '.join(config.lto_launch + [config.clang] + config.lto_flags + ['-flto -fsanitize=cfi '])

if config.cfi_lit_test_mode == "Devirt":
config.available_features.add('devirt')
clang_cfi += '-fwhole-program-vtables '
config.substitutions.append((r"%expect_crash_unless_devirt ", ""))
else:
config.substitutions.append((r"%expect_crash_unless_devirt ", config.expect_crash))

cxx = ' '.join(config.cxx_mode_flags) + ' '
diag = '-fno-sanitize-trap=cfi -fsanitize-recover=cfi '
non_dso = '-fvisibility=hidden '
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/test/cfi/lit.site.cfg.in
@@ -1,4 +1,6 @@
@LIT_SITE_CFG_IN_HEADER@

config.cfi_lit_test_mode = "@CFI_LIT_TEST_MODE@"

lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg")
7 changes: 5 additions & 2 deletions compiler-rt/test/cfi/overwrite.cpp
@@ -1,5 +1,5 @@
// RUN: %clangxx_cfi -o %t1 %s
// RUN: %expect_crash %t1 2>&1 | FileCheck --check-prefix=CFI %s
// RUN: %expect_crash_unless_devirt %t1 2>&1 | FileCheck --check-prefix=CFI %s

// RUN: %clangxx_cfi -DB32 -o %t2 %s
// RUN: %expect_crash %t2 2>&1 | FileCheck --check-prefix=CFI %s
Expand Down Expand Up @@ -55,7 +55,10 @@ int main() {
// CFI-DIAG-NEXT: note: invalid vtable
a->f();

// CFI-NOT: {{^2$}}
// We don't check for the absence of a 2 here because under devirtualization
// our virtual call may be devirtualized and we will proceed with execution
// rather than crashing.

// NCFI: {{^2$}}
fprintf(stderr, "2\n");
}
3 changes: 3 additions & 0 deletions compiler-rt/test/cfi/stats.cpp
Expand Up @@ -2,6 +2,9 @@
// RUN: env SANITIZER_STATS_PATH=%t.stats %t
// RUN: sanstats %t.stats | FileCheck %s

// FIXME: We currently emit the wrong debug info under devirtualization.
// UNSUPPORTED: devirt

struct ABase {};

struct A : ABase {
Expand Down
6 changes: 4 additions & 2 deletions compiler-rt/test/lit.common.cfg
Expand Up @@ -92,9 +92,11 @@ if config.host_os == 'Windows':
# does not crash but exits with a non-zero exit code. We ought to merge
# KillTheDoctor and not --crash to make the latter more useful and remove the
# need for this substitution.
config.substitutions.append( ("%expect_crash ", "not KillTheDoctor ") )
config.expect_crash = "not KillTheDoctor "
else:
config.substitutions.append( ("%expect_crash ", "not --crash ") )
config.expect_crash = "not --crash "

config.substitutions.append( ("%expect_crash ", config.expect_crash) )

target_arch = getattr(config, 'target_arch', None)
if target_arch:
Expand Down

0 comments on commit c79ad57

Please sign in to comment.