diff options
author | David Carlier <devnexen@gmail.com> | 2018-12-22 11:17:27 +0000 |
---|---|---|
committer | David Carlier <devnexen@gmail.com> | 2018-12-22 11:17:27 +0000 |
commit | c697faffde242dc19a39c508785dae8c305bfd2a (patch) | |
tree | 2464f7cc3f7d962f27dc25e670a26c015ff579aa /test/sanitizer_common/TestCases/Posix | |
parent | 2835fe7cf7dc2add5f2c93f4f6470b0f07863c28 (diff) | |
download | compiler-rt-c697faffde242dc19a39c508785dae8c305bfd2a.tar.gz |
[Sanitizer] Enable POSIX regex api on FreeBSD.
Reviewers: krytarowski
Reviewed By: krytarowski
Differential Revision: https://reviews.llvm.org/D56009
M lib/sanitizer_common/sanitizer_common_interceptors.inc
M lib/sanitizer_common/sanitizer_platform_interceptors.h
M lib/sanitizer_common/sanitizer_platform_limits_freebsd.cc
M lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
D test/sanitizer_common/TestCases/NetBSD/regex.cc
A + test/sanitizer_common/TestCases/Posix/regex.cc
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@350002 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/sanitizer_common/TestCases/Posix')
-rw-r--r-- | test/sanitizer_common/TestCases/Posix/regex.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test/sanitizer_common/TestCases/Posix/regex.cc b/test/sanitizer_common/TestCases/Posix/regex.cc new file mode 100644 index 000000000..a6f19f39b --- /dev/null +++ b/test/sanitizer_common/TestCases/Posix/regex.cc @@ -0,0 +1,71 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s +// +// UNSUPPORTED: linux, darwin, solaris + +#include <assert.h> +#include <regex.h> +#include <stdio.h> +#include <stdlib.h> + +#ifndef __arraycount +#define __arraycount(a) ((sizeof(a) / sizeof(a[0]))) +#endif + +void test_matched(const regex_t *preg, const char *string) { + int rv = regexec(preg, string, 0, NULL, 0); + if (!rv) + printf("%s: matched\n", string); + else if (rv == REG_NOMATCH) + printf("%s: not-matched\n", string); + else + abort(); +} + +void test_print_matches(const regex_t *preg, const char *string) { + regmatch_t rm[10]; + int rv = regexec(preg, string, __arraycount(rm), rm, 0); + if (!rv) { + for (size_t i = 0; i < __arraycount(rm); i++) { + // This condition shall be simplified, but verify that the data fields + // are accessible. + if (rm[i].rm_so == -1 && rm[i].rm_eo == -1) + continue; + printf("matched[%zu]='%.*s'\n", i, (int)(rm[i].rm_eo - rm[i].rm_so), + string + rm[i].rm_so); + } + } else if (rv == REG_NOMATCH) + printf("%s: not-matched\n", string); + else + abort(); +} + +int main(void) { + printf("regex\n"); + + regex_t regex; + int rv = regcomp(®ex, "[[:upper:]]\\([[:upper:]]\\)", 0); + assert(!rv); + + test_matched(®ex, "abc"); + test_matched(®ex, "ABC"); + + test_print_matches(®ex, "ABC"); + + regfree(®ex); + + rv = regcomp(®ex, "[[:upp:]]", 0); + assert(rv); + + char errbuf[1024]; + regerror(rv, ®ex, errbuf, sizeof errbuf); + printf("error: %s\n", errbuf); + + // CHECK: regex + // CHECK: abc: not-matched + // CHECK: ABC: matched + // CHECK: matched[0]='AB' + // CHECK: matched[1]='B' + // CHECK: error:{{.*}} + + return 0; +} |