clad icon indicating copy to clipboard operation
clad copied to clipboard

Compiler error for inner function call with char argument

Open maxaehle opened this issue 1 year ago • 0 comments

Minimal example: Compile the following code with Clang++ with the clad plugin:

#include "clad/Differentiator/Differentiator.h"

void g(char c){}

double f(double x) {
  g('a');
  return x;
}

int main() {
  auto f_dx = clad::differentiate(f, "x");
  f_dx.execute(3);
}

Expected behavior: Code compiles.

Observed behavior: Compiler error:

charcall.cpp:6:5: warning: attempted to differentiate unsupported statement, no changes applied
  g('a');
    ^
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
...
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Ubuntu clang version 11.1.0-6
...

Further information: The error goes away when the char literal is replaced by an integer literal. The problem also shows up when a string literal is provided for a char* argument (which is the setup where I stumbled across this bug, but the above case shows that it's not related to pointers). Many thanks to @vgvassilev and @parth-07 for your quick responses to my earlier bug reports. I'm trying to apply Clad to a particle physics simulation code with as few changes to that code as possible, which seems to break a few things...

Setup: Clad built from the GitHub master branch at commit 1bdd261 on Ubuntu 22.04 with Clang 11.

maxaehle avatar Dec 06 '23 19:12 maxaehle