The problem here is funciton createDiagnostics you've been using wrong.
createDiagnostics has two forms:
void createDiagnostics(DiagnosticConsumer *Client = 0,
bool ShouldOwnClient = true);
static IntrusiveRefCntPtr<DiagnosticsEngine>
createDiagnostics(DiagnosticOptions *Opts,
DiagnosticConsumer *Client = 0,
bool ShouldOwnClient = true,
const CodeGenOptions *CodeGenOpts = 0);
You should provide a DiagnosticConsumer to it. But a simpler fix is:
CompilerInstance compiler;
compiler.createDiagnostics();