Repository: pytorch
Issue: Compile error with -WERROR on clang-12
Labels: triaged,actionable

### 🐛 Describe the bug

EDIT(albanD): removed llm example showing the final result works and reworded a little bit.

When trying to compile the lattest torch version on my system with amd cpu. the compilation failed. In order for it to compile i had to modify a file which i specified below.

The file i had to modify to get it to compile was
. /home/myles/pytorch/test/cpp/api/CMakeLists.txt at line 59 replaced that text below.

```C++
if(NOT MSVC)
  # Clang has an unfixed bug leading to spurious missing braces warnings
  # see https://bugs.llvm.org/show_bug.cgi?id=21629
  target_compile_options_if_supported(test_api "-Wno-missing-braces")
  
  # Considered to be flaky. See the discussion at
  # https://github.com/pytorch/pytorch/pull/9608
  target_compile_options_if_supported(test_api "-Wno-maybe-uninitialized")
  
  # gcc gives nonsensical warnings about variadic.h
  target_compile_options_if_supported(test_api "-Wno-unused-but-set-parameter")
  
  # Suppress warnings for deprecated declarations and nonnull errors
  target_compile_options(test_api PRIVATE "-Wno-deprecated-declarations" "-Wno-error=nonnull")
endif()

```

### Error logs


```shell
FAILED: test_api/CMakeFiles/test_api.dir/dataloader.cpp.o 
/usr/bin/ccache /usr/bin/c++ -DFLASHATTENTION_DISABLE_ALIBI -DHAVE_MALLOC_USABLE_SIZE=1 -DHAVE_MMAP=1 -DHAVE_SHM_OPEN=1 -DHAVE_SHM_UNLINK=1 -DIDEEP_USE_MKL -DMINIZ_DISABLE_ZIP_READER_CRC32_CHECKS -DONNXIFI_ENABLE_EXT=1 -DONNX_ML=1 -DONNX_NAMESPACE=onnx_torch -DUSE_C10D_GLOO -DUSE_C10D_MPI -DUSE_C10D_NCCL -DUSE_CUDA -DUSE_DISTRIBUTED -DUSE_EXTERNAL_MZCRC -DUSE_RPC -DUSE_TENSORPIPE -D_FILE_OFFSET_BITS=64 -I/home/myles/pytorch/build/aten/src -I/home/myles/pytorch/aten/src -I/home/myles/pytorch/build -I/home/myles/pytorch -I/home/myles/pytorch/cmake/../third_party/benchmark/include -I/home/myles/pytorch/third_party/onnx -I/home/myles/pytorch/build/third_party/onnx -I/home/myles/pytorch/nlohmann -I/home/myles/pytorch/build/caffe2/../aten/src -I/home/myles/pytorch/torch/csrc/api -I/home/myles/pytorch/torch/csrc/api/include -I/home/myles/pytorch/c10/.. -I/home/myles/pytorch/c10/cuda/../.. -isystem /home/myles/pytorch/build/third_party/gloo -isystem /home/myles/pytorch/cmake/../third_party/gloo -isystem /home/myles/pytorch/cmake/../third_party/tensorpipe/third_party/libuv/include -isystem /home/myles/pytorch/cmake/../third_party/googletest/googlemock/include -isystem /home/myles/pytorch/cmake/../third_party/googletest/googletest/include -isystem /home/myles/pytorch/third_party/protobuf/src -isystem /home/myles/pytorch/third_party/XNNPACK/include -isystem /home/myles/pytorch/third_party/ittapi/include -isystem /home/myles/pytorch/cmake/../third_party/eigen -isystem /usr/local/cuda-12.4/include -isystem /home/myles/pytorch/third_party/ideep/mkl-dnn/include/oneapi/dnnl -isystem /home/myles/pytorch/third_party/ideep/include -isystem /home/myles/pytorch/INTERFACE -isystem /home/myles/pytorch/third_party/nlohmann/include -isystem /home/myles/pytorch/third_party/googletest/googletest/include -isystem /home/myles/pytorch/third_party/googletest/googletest -D_GLIBCXX_USE_CXX11_ABI=1 -Wno-error -Wno-non-virtual-dtor -Wno-return-type -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOROCTRACER -DLIBKINETO_NOXPUPTI=ON -DUSE_FBGEMM -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=range-loop-construct -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-strict-overflow -Wno-strict-aliasing -Wno-stringop-overflow -Wsuggest-override -Wno-psabi -Wno-error=old-style-cast -Wno-missing-braces -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow -DHAVE_AVX512_CPU_DEFINITION -DHAVE_AVX2_CPU_DEFINITION -O3 -DNDEBUG -DNDEBUG -std=gnu++17 -fPIE -DMKL_HAS_SBGEMM -DMKL_HAS_SHGEMM -DTORCH_USE_LIBUV -DCAFFE2_USE_GLOO -Wno-missing-braces -Wno-maybe-uninitialized -Wno-unused-but-set-parameter -MD -MT test_api/CMakeFiles/test_api.dir/dataloader.cpp.o -MF test_api/CMakeFiles/test_api.dir/dataloader.cpp.o.d -o test_api/CMakeFiles/test_api.dir/dataloader.cpp.o -c /home/myles/pytorch/test/cpp/api/dataloader.cpp
In file included from /usr/include/c++/12/bits/stl_uninitialized.h:63,
                 from /usr/include/c++/12/memory:65,
                 from /home/myles/pytorch/third_party/googletest/googletest/include/gtest/gtest.h:57,
                 from /home/myles/pytorch/test/cpp/api/dataloader.cpp:1:
In static member function ‘static _Tp* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(const _Tp*, const _Tp*, _Tp*) [with _Tp = long unsigned int; bool _IsMove = false]’,
    inlined from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = const long unsigned int*; _OI = long unsigned int*]’ at /usr/include/c++/12/bits/stl_algobase.h:495:30,
    inlined from ‘_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = const long unsigned int*; _OI = long unsigned int*]’ at /usr/include/c++/12/bits/stl_algobase.h:522:42,
    inlined from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<const long unsigned int*, vector<long unsigned int> >; _OI = __gnu_cxx::__normal_iterator<long unsigned int*, vector<long unsigned int> >]’ at /usr/include/c++/12/bits/stl_algobase.h:529:31,
    inlined from ‘_OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<const long unsigned int*, vector<long unsigned int> >; _OI = __gnu_cxx::__normal_iterator<long unsigned int*, vector<long unsigned int> >]’ at /usr/include/c++/12/bits/stl_algobase.h:620:7,
    inlined from ‘std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long unsigned int; _Alloc = std::allocator<long unsigned int>]’ at /usr/include/c++/12/bits/vector.tcc:244:21:
/usr/include/c++/12/bits/stl_algobase.h:431:30: error: argument 1 null where non-null expected [-Werror=nonnull]
  431 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/12/bits/stl_algobase.h:431:30: note: in a call to built-in function ‘void* __builtin_memmove(void*, const void*, long unsigned int)’
cc1plus: some warnings being treated as errors
```

### Minified repro

_No response_

### Versions
```shell
curl -OL https://raw.githubusercontent.com/pytorch/pytorch/main/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python3 collect_env.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 23357  100 23357    0     0  63001      0 --:--:-- --:--:-- --:--:-- 63127
Collecting environment information...
PyTorch version: 2.6.0a0+gite248c1d
Is debug build: False
CUDA used to build PyTorch: 12.4
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
Clang version: 14.0.0-1ubuntu1.1
CMake version: version 3.30.2
Libc version: glibc-2.35

Python version: 3.12.6 (main, Sep  7 2024, 19:24:43) [GCC 12.3.0] (64-bit runtime)
Python platform: Linux-6.8.0-44-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.4.131
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA GeForce RTX 4090
GPU 1: NVIDIA GeForce RTX 4090
GPU 2: NVIDIA GeForce RTX 4090
GPU 3: NVIDIA GeForce RTX 4090
GPU 4: NVIDIA GeForce RTX 4090
GPU 5: NVIDIA GeForce RTX 4090
GPU 6: NVIDIA GeForce RTX 4090
GPU 7: NVIDIA GeForce RTX 4090

Nvidia driver version: 550.90.07
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.5.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Address sizes:                        43 bits physical, 48 bits virtual
Byte Order:                           Little Endian
CPU(s):                               128
On-line CPU(s) list:                  0-127
Vendor ID:                            AuthenticAMD
Model name:                           AMD Ryzen Threadripper PRO 3995WX 64-Cores
CPU family:                           23
Model:                                49
Thread(s) per core:                   2
Core(s) per socket:                   64
Socket(s):                            1
Stepping:                             0
Frequency boost:                      enabled
CPU max MHz:                          4308.3979
CPU min MHz:                          2200.0000
BogoMIPS:                             5389.69
Flags:                                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 x2apic 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 ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip rdpid overflow_recov succor smca sev sev_es
Virtualization:                       AMD-V
L1d cache:                            2 MiB (64 instances)
L1i cache:                            2 MiB (64 instances)
L2 cache:                             32 MiB (64 instances)
L3 cache:                             256 MiB (16 instances)
NUMA node(s):                         1
NUMA node0 CPU(s):                    0-127
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Mitigation; untrained return thunk; SMT enabled with STIBP protection
Vulnerability Spec rstack overflow:   Mitigation; Safe RET
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Retpolines; IBPB conditional; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] mypy-extensions==1.0.0
[pip3] numpy==2.1.2
[pip3] onnx==1.17.0
[pip3] onnxruntime==1.19.2
[pip3] open_clip_torch==2.26.1
[pip3] optree==0.12.1
[pip3] pytorch-triton==3.0.0+757b6a61e7
[pip3] torch==2.6.0a0+gite248c1d
[pip3] torchaudio==2.5.0a0+b4a286a
[pip3] torchvision==0.20.0a0+945bdad
[pip3] triton==3.0.0
[conda] Could not collect

```
cc @ezyang @chauhang @penguinwu