Repository: pytorch
Issue: Fail to pass test HAVE_XXX_REGEX while  building pytorch 
Labels: module: build,triaged

### 🐛 Describe the bug

Dear PyTorch team,

# Subject

I am not able to build from the `master` branch due to regex test has failed

```
-- Performing Test HAVE_STD_REGEX
-- Performing Test HAVE_STD_REGEX
-- Performing Test HAVE_STD_REGEX -- compiled but failed to run
-- Performing Test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX -- compiled but failed to run
CMake Error at third_party/benchmark/CMakeLists.txt:304 (message):
  Failed to determine the source files for the regular expression backend
```


# Environment 
OS: Linux Fedora 37
CC: clang
CXX: clang++
LLVM: version 12

# Understanding


Those test `HAVE_XXXX_REGEX` are performed for several third parties: 

- benchmark
- onnx
- protobuf
- QNNPACK
- XNNPACK

Those  `HAVE_XXXX_REGEX`  are defined by the cmake function `cxx_feature_check` in
`pytorch/third_party/benchmark/cmake/CXXFeatureCheck.cmake` line ~ 20 
source code of the function: [here](https://github.com/google/benchmark/blob/main/cmake/CXXFeatureCheck.cmake)


To my understanding, the function will try to i) compile ii) run the code from those files
```
pytorch/third_party/benchmark/cmake/gnu_posix_regex.cpp
pytorch/third_party/benchmark/cmake/posix_regex.cpp
pytorch/third_party/benchmark/cmake/std_regex.cpp
pytorch/third_party/onnx/third_party/benchmark/cmake/gnu_posix_regex.cpp
pytorch/third_party/onnx/third_party/benchmark/cmake/posix_regex.cpp
pytorch/third_party/onnx/third_party/benchmark/cmake/std_regex.cpp
pytorch/third_party/onnx-tensorrt/third_party/onnx/third_party/benchmark/cmake/gnu_posix_regex.cpp
pytorch/third_party/onnx-tensorrt/third_party/onnx/third_party/benchmark/cmake/posix_regex.cpp
pytorch/third_party/onnx-tensorrt/third_party/onnx/third_party/benchmark/cmake/std_regex.cpp
pytorch/third_party/protobuf/third_party/benchmark/cmake/gnu_posix_regex.cpp
pytorch/third_party/protobuf/third_party/benchmark/cmake/posix_regex.cpp
pytorch/third_party/protobuf/third_party/benchmark/cmake/std_regex.cpp
```

So I tried to build those files with clang++ and run them

```bash
$ for f in $(find pytorch/ -name '*regex*.cpp');do echo "Test ==>  $(grep -Po '(?<=pytorch/third_party/)[[:alnum:]\-]+' <<< $f) ---- $(basename $f)"; clang++ $f; ./a.out; echo $?; rm -f ./a.out; done
Test ==>  benchmark ---- gnu_posix_regex.cpp
pytorch/third_party/benchmark/cmake/gnu_posix_regex.cpp:1:10: fatal error: 'gnuregex.h' file not found
#include <gnuregex.h>
         ^~~~~~~~~~~~
1 error generated.
bash: ./a.out: Aucun fichier ou dossier de ce type
127
Test ==>  benchmark ---- posix_regex.cpp
0
Test ==>  benchmark ---- std_regex.cpp
0
Test ==>  onnx ---- gnu_posix_regex.cpp
pytorch/third_party/onnx/third_party/benchmark/cmake/gnu_posix_regex.cpp:1:10: fatal error: 'gnuregex.h' file not found
#include <gnuregex.h>
         ^~~~~~~~~~~~
1 error generated.
bash: ./a.out: Aucun fichier ou dossier de ce type
127
Test ==>  onnx ---- posix_regex.cpp
0
Test ==>  onnx ---- std_regex.cpp
0
Test ==>  onnx-tensorrt ---- gnu_posix_regex.cpp
pytorch/third_party/onnx-tensorrt/third_party/onnx/third_party/benchmark/cmake/gnu_posix_regex.cpp:1:10: fatal error: 'gnuregex.h' file not found
#include <gnuregex.h>
         ^~~~~~~~~~~~
1 error generated.
bash: ./a.out: Aucun fichier ou dossier de ce type
127
Test ==>  onnx-tensorrt ---- posix_regex.cpp
0
Test ==>  onnx-tensorrt ---- std_regex.cpp
0
Test ==>  protobuf ---- gnu_posix_regex.cpp
pytorch/third_party/protobuf/third_party/benchmark/cmake/gnu_posix_regex.cpp:1:10: fatal error: 'gnuregex.h' file not found
#include <gnuregex.h>
         ^~~~~~~~~~~~
1 error generated.
bash: ./a.out: Aucun fichier ou dossier de ce type
127
Test ==>  protobuf ---- posix_regex.cpp
0
Test ==>  protobuf ---- std_regex.cpp
0
```

So this homemade test highlight that `posix_regex` and `std_regex` exit with success.

Why Cmake report that do not run ?


# how to reproduce the error

```
$ podman run -it --rm --name f37 fedora:37 bash
# dnf install -y rocm-comgr-devel rocm-device-libs boost-devel cmake blis-devel libstdc++-devel  python3-setuptools python3-pyyaml ninja-build git
# git clone https://github.com/pytorch/pytorch
# cd pytorch
# export CC="clang"
# export CXX="clang++"
# export LDSHARED="clang --shared"
# export LDFLAGS="-stdlib=libstdc++"
# export CFLAGS="-fsanitize=address -fno-sanitize-recover=all -shared-libasan -pthread"
# export CXX_FLAGS="-shared-libasan -pthread"
# export CPLUS_INCLUDE_PATH="/usr/include/c++/12/:${CPLUS_INCLUDE_PATH}"
# export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer
# USE_CUDA=0 USE_OPENMP=0 BUILD_CAFFE2_OPS=0 USE_DISTRIBUTED=0 DEBUG=1 \
  python setup.py develop
...
-- Performing Test HAVE_STD_REGEX
-- Performing Test HAVE_STD_REGEX
-- Performing Test HAVE_STD_REGEX -- compiled but failed to run
-- Performing Test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX -- compiled but failed to run
CMake Error at third_party/benchmark/CMakeLists.txt:304 (message):
  Failed to determine the source files for the regular expression backend
```


Thanks for your help

### Versions

```
$ python collect_env.py
Collecting environment information...
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: Fedora Linux 37 (Workstation Edition) (x86_64)
GCC version: (GCC) 12.2.1 20221121 (Red Hat 12.2.1-4)
Clang version: 15.0.7 (Fedora 15.0.7-1.fc37)
CMake version: version 3.26.1
Libc version: glibc-2.36

Python version: 3.11.2 (main, Feb  8 2023, 00:00:00) [GCC 12.2.1 20221121 (Red Hat 12.2.1-4)] (64-bit runtime)
Python platform: Linux-6.1.14-200.fc37.x86_64-x86_64-with-glibc2.36
Is CUDA available: N/A
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

CPU:
Architecture :                          x86_64
Mode(s) opératoire(s) des processeurs : 32-bit, 64-bit
Tailles des adresses:                   48 bits physical, 48 bits virtual
Boutisme :                              Little Endian
Processeur(s) :                         12
Liste de processeur(s) en ligne :       0-11
Identifiant constructeur :              AuthenticAMD
Nom de modèle :                         AMD Ryzen 5 5600X 6-Core Processor
Famille de processeur :                 25
Modèle :                                33
Thread(s) par cœur :                    2
Cœur(s) par socket :                    6
Socket(s) :                             1
Révision :                              0
Accroissement de fréquence :            activé
multiplication des MHz du/des CPU(s) :  80%
Vitesse maximale du processeur en MHz : 4650,2920
Vitesse minimale du processeur en MHz : 2200,0000
BogoMIPS :                              7399,98
Drapeaux :                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip pku ospke vaes vpclmulqdq rdpid overflow_recov succor smca fsrm
Virtualisation :                        AMD-V
Cache L1d :                             192 KiB (6 instances)
Cache L1i :                             192 KiB (6 instances)
Cache L2 :                              3 MiB (6 instances)
Cache L3 :                              32 MiB (1 instance)
Nœud(s) NUMA :                          1
Nœud NUMA 0 de processeur(s) :          0-11
Vulnérabilité Itlb multihit :           Not affected
Vulnérabilité L1tf :                    Not affected
Vulnérabilité Mds :                     Not affected
Vulnérabilité Meltdown :                Not affected
Vulnérabilité Mmio stale data :         Not affected
Vulnérabilité Retbleed :                Not affected
Vulnérabilité Spec store bypass :       Mitigation; Speculative Store Bypass disabled via prctl
Vulnérabilité Spectre v1 :              Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnérabilité Spectre v2 :              Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP always-on, RSB filling, PBRSB-eIBRS Not affected
Vulnérabilité Srbds :                   Not affected
Vulnérabilité Tsx async abort :         Not affected

Versions of relevant libraries:
[pip3] numpy==1.24.2
[conda] Could not collect
```


cc @malfet @seemethere