Issue 1:
🐛 Bug

I am trying to build PyTorch from source without Cuda on OSX. I am currently on version 10.15 of MacOS and followed the steps at https://github.com/pytorch/pytorch#from-source to build it from source. However, I am not sure whether this is a bug in PyTorch or the problem is on Apple's side.

To Reproduce

Steps to reproduce the behavior:

Create a fresh conda environment

Follow the manual on how to build from source over at https://github.com/pytorch/pytorch#from-source

Use the following commands to start the build process:

export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
MACOSX_DEPLOYMENT_TARGET=10.15 CC=clang CXX=clang++ USE_CUDA=0 python setup.py install

Expected behavior

PyTorch can be built and is installed.

Environment

Collecting environment information...

PyTorch version: N/A

Is debug build: N/A

CUDA used to build PyTorch: N/A

OS: Mac OSX 10.15.3

GCC version: Could not collect

CMake version: version 3.14.0

Python version: 3.7

Is CUDA available: N/A

CUDA runtime version: Could not collect

GPU models and configuration: Could not collect

Nvidia driver version: Could not collect

cuDNN version: Could not collect

Versions of relevant libraries:

[pip] numpy==1.18.1

[conda] blas 1.0 mkl

[conda] mkl 2019.4 233

[conda] mkl-include 2020.0 166

[conda] mkl-service 2.3.0 py37hfbe908c_0

[conda] mkl_fft 1.0.15 py37h5e564d8_0

[conda] mkl_random 1.1.0 py37ha771720_0

Additional context

While retrying multiple times I noticed that the build always fails at the SobolEngineOps file.

Error during the build process:

[29/339] Building CXX object caffe2/CMakeFiles/torch.dir/__/aten/src/ATen/native/SobolEngineOps.cpp.o
FAILED: caffe2/CMakeFiles/torch.dir/__/aten/src/ATen/native/SobolEngineOps.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -DAT_PARALLEL_OPENMP=1 -DCAFFE2_BUILD_MAIN_LIB -DCPUINFO_SUPPORTED_PLATFORM=1 -DHAVE_MMAP=1 -DHAVE_SHM_OPEN=1 -DHAVE_SHM_UNLINK=1 -DIDEEP_USE_MKL -DNNP_CONVOLUTION_ONLY=0 -DNNP_INFERENCE_ONLY=0 -DONNX_ML=1 -DONNX_NAMESPACE=onnx_torch -DTH_BLAS_MKL -D_FILE_OFFSET_BITS=64 -Dtorch_EXPORTS -Iaten/src -I../aten/src -I. -I../ -I../cmake/../third_party/benchmark/include -Icaffe2/contrib/aten -I../third_party/onnx -Ithird_party/onnx -I../third_party/foxi -Ithird_party/foxi -I../caffe2/../torch/csrc/api -I../caffe2/../torch/csrc/api/include -I../caffe2/aten/src/TH -Icaffe2/aten/src/TH -I../caffe2/../torch/../aten/src -Icaffe2/aten/src -Icaffe2/../aten/src -Icaffe2/../aten/src/ATen -I../caffe2/../torch/csrc -I../caffe2/../torch/../third_party/miniz-2.0.8 -I../aten/src/TH -I../aten/../third_party/catch/single_include -I../aten/src/ATen/.. -Icaffe2/aten/src/ATen -I../third_party/miniz-2.0.8 -I../caffe2/core/nomnigraph/include -I../c10/.. -Ithird_party/ideep/mkl-dnn/include -I../third_party/ideep/mkl-dnn/src/../include -I../third_party/QNNPACK/include -I../third_party/pthreadpool/include -I../aten/src/ATen/native/quantized/cpu/qnnpack/include -I../aten/src/ATen/native/quantized/cpu/qnnpack/src -I../third_party/QNNPACK/deps/clog/include -I../third_party/NNPACK/include -I../third_party/cpuinfo/include -I../third_party/fbgemm/include -I../third_party/fbgemm -I../third_party/fbgemm/third_party/asmjit/src -I../third_party/FP16/include -isystem ../cmake/../third_party/googletest/googlemock/include -isystem ../cmake/../third_party/googletest/googletest/include -isystem ../third_party/protobuf/src -isystem ~/anaconda3/envs/pytorch/include -isystem ../third_party/gemmlowp -isystem ../third_party/neon2sse -isystem ../third_party -isystem ../cmake/../third_party/eigen -isystem ~/anaconda3/envs/pytorch/include/python3.7m -isystem ~/anaconda3/envs/pytorch/lib/python3.7/site-packages/numpy/core/include -isystem ../cmake/../third_party/pybind11/include -isystem /opt/rocm/hip/include -isystem /include -isystem ../third_party/ideep/mkl-dnn/include -isystem ../third_party/ideep/include -isystem include -Wno-deprecated -fvisibility-inlines-hidden -Wno-deprecated-declarations -Xpreprocessor -fopenmp -I/usr/local/include -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -O2 -fPIC -Wno-narrowing -Wall -Wextra -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -Wno-invalid-partial-specialization -Wno-typedef-redefinition -Wno-unknown-warning-option -Wno-unused-private-field -Wno-inconsistent-missing-override -Wno-aligned-allocation-unavailable -Wno-c++14-extensions -Wno-constexpr-not-const -Wno-missing-braces -Qunused-arguments -fcolor-diagnostics -fno-math-errno -fno-trapping-math -Wno-unused-private-field -Wno-missing-braces -Wno-c++14-extensions -Wno-constexpr-not-const -DHAVE_AVX_CPU_DEFINITION -DHAVE_AVX2_CPU_DEFINITION -O3 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -mmacosx-version-min=10.15 -fPIC -DHAVE_GCC_GET_CPUID -DUSE_AVX -DUSE_AVX2 -DTH_HAVE_THREAD -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-write-strings -Wno-unknown-pragmas -Wno-missing-braces -fvisibility=hidden -O2 -DCAFFE2_BUILD_MAIN_LIB -DASMJIT_STATIC -std=gnu++11 -MD -MT caffe2/CMakeFiles/torch.dir/__/aten/src/ATen/native/SobolEngineOps.cpp.o -MF caffe2/CMakeFiles/torch.dir/__/aten/src/ATen/native/SobolEngineOps.cpp.o.d -o caffe2/CMakeFiles/torch.dir/__/aten/src/ATen/native/SobolEngineOps.cpp.o -c ../aten/src/ATen/native/SobolEngineOps.cpp
clang: error: unable to execute command: Segmentation fault: 11
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Apple clang version 11.0.3 (clang-1103.0.32.29)
Target: x86_64-apple-darwin19.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
clang: note: diagnostic msg: PLEASE submit a bug report to http://developer.apple.com/bugreporter/ and include the crash backtrace, preprocessed source, and associated run script.
clang: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /var/folders/cx/trr2xjp56fs_rq2yzlb8xpb40000gn/T/SobolEngineOps-175bae.cpp
clang: note: diagnostic msg: /var/folders/cx/trr2xjp56fs_rq2yzlb8xpb40000gn/T/SobolEngineOps-175bae.sh
clang: note: diagnostic msg: /var/folders/cx/trr2xjp56fs_rq2yzlb8xpb40000gn/T/SobolEngineOps-175bae.crash
clang: note: diagnostic msg:

********************
[40/339] Building CXX object caffe2/CMakeFiles/torch.dir/__/aten/src/ATen/native/Unique.cpp.o
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
File "setup.py", line 755, in <module>
build_deps()
File "setup.py", line 316, in build_deps
cmake=cmake)
File "~/Desktop/pytorch/tools/build_pytorch_libs.py", line 62, in build_caffe2
cmake.build(my_env)
File "~/Desktop/pytorch/tools/setup_helpers/cmake.py", line 335, in build
self.run(build_args, my_env)
File "~/Desktop/pytorch/tools/setup_helpers/cmake.py", line 141, in run
check_call(command, cwd=self.build_dir, env=env)
File "~/anaconda3/envs/pytorch/lib/python3.7/subprocess.py", line 363, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '-j', '12']' returned non-zero exit status 1.

cc @ezyang @gchanan @zou3519

Issue 2:
Followup of #36618.

I'm getting segfault when building pytorch from source with clang 9.0.0.

Stack dump is available at https://gist.github.com/ailzhang/f69b11f338997d375d3f69ae22bd1aec

It asks me to submit a but report to llvm, I'm also searching around to see if there're any workarounds.