Skip to content

Commit

Permalink
Refuse to compile using buggy Clang versions (14.0.0-14.0.4)
Browse files Browse the repository at this point in the history
Clang versions 14.0.0 to 14.0.4 (included) miscompile Dr.Jit / Mitsuba.
The default initialization of `DiffArray<...>::m_index` is optimized
away, which then causes crashes when AD reference counting operations
access nonexistent variable indices.

The issue is resolved in 14.0.5. I did not bisect the specific LLVM
commit, though I suspect that the following loop optimization fixes
are involved:

- llvm/llvm-project@b75bf75
- llvm/llvm-project@d350783

Working around the issue looks to be hopeless, to this commit reverts a
previous attempted fix (bfab9ac) and introduces a hard version check.
  • Loading branch information
wjakob committed Dec 30, 2022
1 parent d55d395 commit 94b1d6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
target_compile_options(drjit INTERFACE -fno-strict-aliasing)
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT APPLE)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14.0.0 AND
CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14.0.5)
message(FATAL_ERROR "Clang versions 14.0.0 to 14.0.4 miscompile Dr.Jit. Please use either a newer (14.0.5+) or older (e.g., 13.x) version. On Ubuntu, you can use the LLVM project's package server (https://apt.llvm.org) to get the latest version.")
endif()
endif()

if (DRJIT_MASTER_PROJECT)
if (APPLE)
set(DRJIT_ORIGIN "@loader_path")
Expand Down
2 changes: 1 addition & 1 deletion include/drjit/array_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ template <typename Value_, bool IsMask_, typename Derived_> struct ArrayBase {
sizeof...(Indices) == Derived::ActualSize, "shuffle(): Invalid size!");
DRJIT_CHKSCALAR("shuffle_");
size_t idx = 0; (void) idx;
Derived out = zeros<Derived>();
Derived out;
((out.entry(idx++) = derived().entry(Indices % Derived::Size)), ...);
return out;
}
Expand Down

0 comments on commit 94b1d6c

Please sign in to comment.