Repository: facebookresearch/CompilerGym

Issue:
protoc segfaults on macOS 12.0.1
## 🐛 Bug

The version of protoc used by the CompilerGym build segfaults on macOS 12.0.1:

```
$ bazel-out/host/bin/external/com_github_protocolbuffers_protobuf/protoc
[1]    82656 segmentation fault  bazel-out/host/bin/external/com_github_protocolbuffers_protobuf/protoc
```

Thanks @mostafaelhoushi for discovering this!

## To Reproduce


Steps to reproduce the behavior:

1. Update to macOS 12.0.1.
1. Start from a clean build: `make distclean`.
1. Attempt to build CompilerGym:

```
$ make install BAZEL_BUILD_OPTS='--sandbox_debug'
...
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_cummins/c3f286fbbefcd6317d9b13e427e86632/sandbox/darwin-sandbox/3008/sandbox.sb /var/tmp/_bazel_cummins/install/97cf8d40e3de7fca7ef885fa763bde13/process-wrapper '--timeout=0' '--kill_delay=15' bazel-out/host/bin/external/com_github_protocolbuffers_protobuf/protoc '--python_out=bazel-out/host/bin/external/com_github_protocolbuffers_protobuf/python' -Iexternal/com_github_protocolbuffers_protobuf/python -Ibazel-out/host/bin/external/com_github_protocolbuffers_protobuf/python bazel-out/host/bin/external/com_github_protocolbuffers_protobuf/python/google/protobuf/timestamp.proto) sandbox-exec failed: error executing command
...
```

## Environment

Please fill in this checklist:

- CompilerGym: 0.2.1
- How you installed CompilerGym (conda, pip, source): source
- OS: macOS 12.0.1
- Python version: 3.8
- GCC/clang version (if compiling from source): Apple clang 12.0.5
- Bazel version (if compiling from source): 
- Versions of any other relevant libraries:

You may use the PyTorch
[environment collection script](https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py)
to generate most of this information. You can get the script and run it with:

```sh
wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
```



Discussion:

Resolving patch:
diff --git a/compiler_gym/envs/llvm/service/passes/extract_passes_from_llvm_source_tree.py b/compiler_gym/envs/llvm/service/passes/extract_passes_from_llvm_source_tree.py
--- a/compiler_gym/envs/llvm/service/passes/extract_passes_from_llvm_source_tree.py
+++ b/compiler_gym/envs/llvm/service/passes/extract_passes_from_llvm_source_tree.py
@@ -242,10 +242,17 @@ def main(argv):
     else:
         # Get the names of all files which contain a pass definition.
         matching_paths = []
-        grep = subprocess.check_output(
-            ["grep", "-l", "-E", rf"^\s*{INITIALIZE_PASS_RE}", "-R", "lib/"],
-            universal_newlines=True,
-        )
+        try:
+            grep = subprocess.check_output(
+                ["grep", "-l", "-E", rf"^\s*{INITIALIZE_PASS_RE}", "-R", "lib/"],
+                universal_newlines=True,
+            )
+        except subprocess.CalledProcessError:
+            print(
+                f"fatal: Failed to find any LLVM pass declarations in {root}",
+                file=sys.stderr,
+            )
+            sys.exit(1)
         matching_paths += grep.strip().split("\n")
         logger.debug("Processing %s files ...", len(matching_paths))
         paths = [Path(path) for path in matching_paths]


Test patch: