[HELP] Segfault on printing out structure elements

Hi, all.

I’m a graduate student working on creating llvm pass that generates resilient version of code automatically.

Basically, what it does is to duplicate instructions and compare them at the synchronization points, such as function call, branch. Plus, there is one more copy for recovery. So if two copies agree, program will proceed with original copy, or otherwise it will use the third copy as corrected one. It looks like below.

$inst1 = add $1, $2

$inst2 = add $3, $4

$inst3 = add $5, $6

$cmp = icmp $inst1, $inst2

$corrected = sel $cmp, $inst1, $inst3

printf $corrected //very simplified form

Everything was going fine, but now I’m stuck at a weird bug that I cannot quite understand.

If the instructions to be copied are accessing structure elements and they are printed out by printf or fprintf(like example above except it does not access structure), it occurs segfault at runtime even though they are legit memory access.

  • Here’s more clarification for my situation.
  • It compiles successfully.

  • If I commented out ‘printf’ or ‘fprintf’ from the source code, the program works fine. So it seems like there’s a problem on this part.

  • For other printf with corrected value, they works fine if they are not accessing structure element.

Error msg and comparison between original code and transformed code by my pass are attached below. I tried to make it shown here but the size wasn’t fit.

Is there anyone who had same problem or have any idea/guess/hint for me?

Thank you in advance!

Perhaps you can run verify [1] after your transformation to do sanity check.

[1] http://llvm.org/docs/doxygen/Verifier_8h_source.html