Page MenuHomePhabricator

Add artificial debug information to avoid compiler crash
ClosedPublic

Authored by ygao on Jun 28 2016, 3:28 PM.

Details

Summary

Hi,
The compiler crashed with the following test program:

/* test.c

  • To reproduce:
  • $ clang -c -g -fstack-protector-strong test.c
  • (fatal error: error in backend: Broken function found, compilation aborted!)
  • (need an assertion-enabled build of the compiler) */

void __stack_chk_fail(void) { return; }

void foo() {

char bar[5];

}
/* end of test.c */

This is not a legitimate input C file because __stack_chk_fail is a reserved function name.
On the other hand, it seems that the compiler should be able to give a nicer diagnostic or
otherwise fail more gracefully instead of having to crash on invalid input (in the spirit of all
"internal compiler error"s are compiler bugs).

The proposed patch here attempts to add artificial debug information when the compiler
generates the call to __stack_chk_fail. Does this look like a reasonable thing to do?

Many thanks in advance,

  • Gao

Diff Detail

Repository
rL LLVM

Event Timeline

ygao updated this revision to Diff 62141.Jun 28 2016, 3:28 PM
ygao retitled this revision from to Add artificial debug information to avoid compiler crash.
ygao updated this object.
ygao added reviewers: aprantl, echristo, dblaikie.
ygao added a subscriber: llvm-commits.
aprantl edited edge metadata.Jun 28 2016, 5:17 PM

Is it possible to just use

auto NL = ApplyDebugLocation::CreateArtificial(CodeGenFunction);

instead?

See r267904 for a similar change.

Any time we spontaneously emit a call at the IR level, we'd need to put in a line-0 location. Is this the only one?
Fred's patch (D16569) won't help here because that happens after instruction selection, and this looks like an IR verifier crash.

ygao added a comment.Jun 28 2016, 6:01 PM

Hi @aprantl,
I looked at r267904 per your suggestion. Thanks. It looks like it is a cfe patch, and ApplyDebugLocation::CreateArtificial() is defined in clang. Is it okay to use clang functions in the LLVM backend? This particular stackprotector pass is in the llvm backend, and I am under the impression that it is not allowed to use clang functions, but I could be wrong,

  • Gao

Any time we spontaneously emit a call at the IR level, we'd need to put in a line-0 location. Is this the only one?

I do not know. I'm willing to bet that this is not the only one, but I do not know yet how to find out for sure,

aprantl accepted this revision.EditedJun 28 2016, 6:13 PM
aprantl edited edge metadata.

Sorry! I completely missed the fact that this was not a clang patch. In that case this patch LGTM.

thanks!

This revision is now accepted and ready to land.Jun 28 2016, 6:13 PM
This revision was automatically updated to reflect the committed changes.