This is an archive of the discontinued LLVM Phabricator instance.

[llc] New diagnostic handler
ClosedPublic

Authored by rovka on May 12 2016, 5:04 AM.

Details

Summary

Without a diagnostic handler installed, llc's behaviour is to exit on the first error that it encounters. This is very different from the behaviour of clang and other front ends, which try to gather as many errors as possible before exiting.

This commit adds a diagnostic handler to llc, allowing it to find and report more than one error. The old behaviour is preserved under a flag (-exit-on-error).

Some of the tests fail with the new diagnostic handler, so they have to use the new flag in order to run under the previous behaviour. Some of these are known bugs, others need further investigation. Ideally, we should fix the tests and remove the flag at some point in the future.

Diff Detail

Event Timeline

rovka updated this revision to Diff 57020.May 12 2016, 5:04 AM
rovka retitled this revision from to [llc] New diagnostic handler.
rovka updated this object.
rengolin added inline comments.
tools/llc/llc.cpp
468

I think this could be before "if (CompileTwice)" above. Unless we're expecting it to fail one time and not the other, which I think it's a very slim chance.

Also, this cast is a bit odd. Maybe keeping that original HasError up there in in a global (anonymous) namespace would be better?

rovka added inline comments.May 12 2016, 9:26 AM
tools/llc/llc.cpp
468

It has to be after a PM.run, because that's where the errors may happen. We can add it after the first PM.run as well, for a quick exit in case of errors, but it still needs to be here as well in case CompileTwice is false.

WRT the cast: I'm not a big fan of either globals or casts, so I wouldn't mind using a global instead if you think that's cleaner.

rnk added a subscriber: rnk.May 12 2016, 10:38 AM
rnk added inline comments.
tools/llc/llc.cpp
191

How about making this a static method of LLVMContext rather than duplicating it from LLVMContext.cpp?

468

I think it's better the way you have it. You're exercising the diagnostic context just the way it is intended: by downcasting a void*.

rengolin added inline comments.May 12 2016, 1:51 PM
tools/llc/llc.cpp
468

If that's how it was supposed to work, looks good. :)

rovka updated this revision to Diff 57169.May 13 2016, 6:54 AM
rovka updated this object.
rovka added reviewers: rnk, t.p.northover.
rovka added a subscriber: llvm-commits.

Addressed some of the comments.

Added a new llc flag, -exit-on-error (which preserves the old behaviour).

Added -exit-on-error to the tests that fail under the new behaviour.

I also had to specify an underlying integer type for DiagnosticSeverity, so we can forward declare it in LLVMContext.h (otherwise we'd have to include DiagnosticInfo.h, which doesn't seem very nice considering how slender LLVMContext.h is).

rnk accepted this revision.May 13 2016, 8:09 AM
rnk edited edge metadata.

lgtm

This revision is now accepted and ready to land.May 13 2016, 8:09 AM
rovka added a comment.May 13 2016, 8:23 AM
In D20202#429530, @rnk wrote:

lgtm

Thanks

rengolin closed this revision.May 13 2016, 8:44 AM

Committed in r269428. Thanks!

rovka updated this revision to Diff 57345.May 16 2016, 6:54 AM
rovka edited edge metadata.

Get rid of some UB that I accidentally introduced along with the new flag.

rovka updated this revision to Diff 57347.May 16 2016, 7:08 AM

...and a style fix : )