-
Notifications
You must be signed in to change notification settings - Fork 15k
Description
When compiling and running a Clad + Enzyme test on Apple M1 with Clang 18.1.8, a segmentation fault occurs due to an assertion in DeclTemplate.h.
Error Message:
Assertion failed: (Loc.isValid() && "point of instantiation must be valid!"),
function setPointOfInstantiation, file DeclTemplate.h, line 1937.
System Info:
- macOS 15 (Darwin 25.0.0)
- Apple Silicon (M1)
- Clang version: 18.1.8 (built from llvm-project)
- Clad build: latest main branch
- Enzyme enabled
Steps to Reproduce:
1. Test File (test/Enzyme/DifferentCladEnzymeDerivatives.C):
// RUN: %cladclang %s -I%S/../../include -oDifferentCladEnzymeDerivatives.out | %filecheck %s
// RUN: ./DifferentCladEnzymeDerivatives.out
// REQUIRES: Enzyme
#include "clad/Differentiator/Differentiator.h"
#include
double foo(double x, double y) {
return x * y;
}
int main() {
auto grad = clad::gradient(foo);
auto gradEnzyme = clad::gradientclad::opts::use_enzyme(foo);
double x = 3.0, y = 4.0;
double grads[2];
grad.execute(x, y, grads);
std::cout << grads[0] << " " << grads[1] << std::endl;
}
2. Command:
bash./runclad.sh test/Enzyme/DifferentCladEnzymeDerivatives.C
3. Full Output:
π§ Compiling test/Enzyme/DifferentCladEnzymeDerivatives.C...
Assertion failed: (Loc.isValid() && "point of instantiation must be valid!"), function setPointOfInstantiation, file DeclTemplate.h, line 1937.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
clang++: error: unable to execute command: Segmentation fault: 11
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 18.1.8 (https://github.com/llvm/llvm-project.git 3b5b5c1)
Target: arm64-apple-darwin25.0.0
Thread model: posix
InstalledDir: /Users/vedantgoyal/Desktop/CODING/clad/./llvm-project/build/bin
Diagnostic Files:
clang-18-2025-10-08-104848.txt
DifferentCladEnzymeDerivatives-4f9ddd.cpp
DifferentCladEnzymeDerivatives-4f9ddd.sh
Note: .crash file is renamed to .txt in order to upload it on github
Shell script: I have also attached the shell script that i used to compile and execute the code
#!/bin/zsh
set -e
CLANG=(ccache ./llvm-project/build/bin/clang++)
CLAD_LIB=./llvm-project/build/lib/clad.dylib
INCLUDE1=./llvm-project/llvm/include
INCLUDE2=./include
SRC=$1
BASENAME=$(basename ${SRC%.*})
OUT=build_exe/${BASENAME}
mkdir -p build_exe
echo "π§ Compiling $SRC..."
"${CLANG[@]}" -O0 -isysroot $(xcrun --show-sdk-path)
-I$INCLUDE1 -I$INCLUDE2
-L./llvm-project/build/lib
-fplugin=$CLAD_LIB
-Xclang -load -Xclang $CLAD_LIB
-o $OUT $SRC
echo "π Running $OUT..."
./$OUT
Expected Behavior:
The code should compile successfully, allowing both gradient computation methods (standard Clad and Enzyme-based) to coexist in the same program.
Additional Context:
This appears to be related to template instantiation when mixing different Clad gradient backends in the same translation unit. The assertion occurs during compilation when setPointOfInstantiation is called with an invalid location.