Unexpected behavior of -finstrument-functions

Hi all,
I was experimenting with Clang and state of the art performance
profiling and tracing tools such as ScoreP [1]. It basically uses
compiler instrumentation to generate call-path profiles / traces.

When used with GCC everything works as expected.

Unfortunately, when used with Clang one runs into problems if the code
under investigation uses exceptions. One example would be the
483.Xalancbmk benchmark of the SPEC CPU 2006 suite [2].

The problem is that Clang does function instrumentation in a way that
the function body itself seems to not getting wrapped in a try/catch.
Thus, if a callee throws, the instrumentation code does not generate
"balanced" enter/exit trees.

I already had a look into the Clang sources, but I was unsure how to fix
this. I will have a look at it and see whether I can supply a patch.
However, ideas and hints how to do that are well appreciated.

Besides this email should I file a bug report somewhere?

Thanks,
JP

[1] VI-HPS :: Projects :: Score-P
[2] 483.xalancbmk: SPEC CPU2006 Benchmark Description

Jan-Patrick Lehr <my.new.social.email@gmail.com> writes:

Hi all,
I was experimenting with Clang and state of the art performance
profiling and tracing tools such as ScoreP [1]. It basically uses
compiler instrumentation to generate call-path profiles / traces.

When used with GCC everything works as expected.

Unfortunately, when used with Clang one runs into problems if the code
under investigation uses exceptions. One example would be the
483.Xalancbmk benchmark of the SPEC CPU 2006 suite [2].

The problem is that Clang does function instrumentation in a way that
the function body itself seems to not getting wrapped in a try/catch.
Thus, if a callee throws, the instrumentation code does not generate
"balanced" enter/exit trees.

I already had a look into the Clang sources, but I was unsure how to fix
this. I will have a look at it and see whether I can supply a patch.
However, ideas and hints how to do that are well appreciated.

If you haven't found where the current instrumentation is done yet, look
for ShouldInstrumentFunction and EmitFunctionInstrumentation in
CodeGenFunction.cpp. I'm guessing the fix will involve setting up the
call to __cyg_profile_func_exit as a "Cleanup" at some point rather than
just emitting it in FinishFunction.

Besides this email should I file a bug report somewhere?

Please do, otherwise we might forget about this. The bug tracker is
here: https://llvm.org/bugs/