Files
TheRock/compiler/amd-llvm/compiler-rt/test/sanitizer_common/TestCases/Posix/regex.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

79 lines
1.7 KiB
C++

// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
//
// UNSUPPORTED: darwin, target={{.*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(&regex, "[[:upper:]]\\([[:upper:]]\\)", 0);
assert(!rv);
test_matched(&regex, "abc");
test_matched(&regex, "ABC");
test_print_matches(&regex, "ABC");
regfree(&regex);
}
{
regex_t regex;
int rv = regcomp(&regex, "[[:upp:]]", 0);
assert(rv);
char errbuf[1024];
regerror(rv, &regex, errbuf, sizeof errbuf);
printf("error: %s\n", errbuf);
regfree(&regex);
}
// CHECK: regex
// CHECK: abc: not-matched
// CHECK: ABC: matched
// CHECK: matched[0]='AB'
// CHECK: matched[1]='B'
// CHECK: error:{{.*}}
return 0;
}