Don't silently drop warning flags passed in to

clang_createTranslationUnitFromSourceFile().

llvm-svn: 123793
This commit is contained in:
Douglas Gregor 2011-01-19 01:02:47 +00:00
parent d077e4595c
commit 345c1bcb80
4 changed files with 28 additions and 6 deletions

View File

@ -231,6 +231,7 @@ private:
bool ShouldCacheCodeCompletionResults;
static void ConfigureDiags(llvm::IntrusiveRefCntPtr<Diagnostic> &Diags,
const char **ArgBegin, const char **ArgEnd,
ASTUnit &AST, bool CaptureDiagnostics);
public:

View File

@ -465,6 +465,7 @@ llvm::MemoryBuffer *ASTUnit::getBufferForFile(llvm::StringRef Filename,
/// \brief Configure the diagnostics object for use with ASTUnit.
void ASTUnit::ConfigureDiags(llvm::IntrusiveRefCntPtr<Diagnostic> &Diags,
const char **ArgBegin, const char **ArgEnd,
ASTUnit &AST, bool CaptureDiagnostics) {
if (!Diags.getPtr()) {
// No diagnostics engine was provided, so create our own diagnostics object
@ -473,7 +474,8 @@ void ASTUnit::ConfigureDiags(llvm::IntrusiveRefCntPtr<Diagnostic> &Diags,
DiagnosticClient *Client = 0;
if (CaptureDiagnostics)
Client = new StoredDiagnosticClient(AST.StoredDiagnostics);
Diags = CompilerInstance::createDiagnostics(DiagOpts, 0, 0, Client);
Diags = CompilerInstance::createDiagnostics(DiagOpts, ArgEnd- ArgBegin,
ArgBegin, Client);
} else if (CaptureDiagnostics) {
Diags->setClient(new StoredDiagnosticClient(AST.StoredDiagnostics));
}
@ -487,7 +489,7 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
unsigned NumRemappedFiles,
bool CaptureDiagnostics) {
llvm::OwningPtr<ASTUnit> AST(new ASTUnit(true));
ConfigureDiags(Diags, *AST, CaptureDiagnostics);
ConfigureDiags(Diags, 0, 0, *AST, CaptureDiagnostics);
AST->OnlyLocalDecls = OnlyLocalDecls;
AST->CaptureDiagnostics = CaptureDiagnostics;
@ -1414,6 +1416,7 @@ bool ASTUnit::LoadFromCompilerInvocation(bool PrecompilePreamble) {
// We'll manage file buffers ourselves.
Invocation->getPreprocessorOpts().RetainRemappedFileBuffers = true;
Invocation->getFrontendOpts().DisableFree = false;
ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts());
llvm::MemoryBuffer *OverrideMainBuffer = 0;
if (PrecompilePreamble) {
@ -1438,7 +1441,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
// Create the AST unit.
llvm::OwningPtr<ASTUnit> AST;
AST.reset(new ASTUnit(false));
ConfigureDiags(Diags, *AST, CaptureDiagnostics);
ConfigureDiags(Diags, 0, 0, *AST, CaptureDiagnostics);
AST->Diagnostics = Diags;
AST->OnlyLocalDecls = OnlyLocalDecls;
AST->CaptureDiagnostics = CaptureDiagnostics;
@ -1467,7 +1470,8 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
// No diagnostics engine was provided, so create our own diagnostics object
// with the default options.
DiagnosticOptions DiagOpts;
Diags = CompilerInstance::createDiagnostics(DiagOpts, 0, 0);
Diags = CompilerInstance::createDiagnostics(DiagOpts, ArgEnd - ArgBegin,
ArgBegin);
}
llvm::SmallVector<const char *, 16> Args;
@ -1543,7 +1547,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
// Create the AST unit.
llvm::OwningPtr<ASTUnit> AST;
AST.reset(new ASTUnit(false));
ConfigureDiags(Diags, *AST, CaptureDiagnostics);
ConfigureDiags(Diags, ArgBegin, ArgEnd, *AST, CaptureDiagnostics);
AST->Diagnostics = Diags;
AST->FileMgr.reset(new FileManager(FileSystemOptions()));

View File

@ -0,0 +1,16 @@
int foo() { }
int *bar(float *f) { return f; }
// RUN: c-index-test -test-load-source all %s 2>&1|FileCheck -check-prefix=CHECK-BOTH-WARNINGS %s
// RUN: c-index-test -test-load-source-reparse 5 all %s 2>&1|FileCheck -check-prefix=CHECK-BOTH-WARNINGS %s
// RUN: c-index-test -test-load-source all -Wno-return-type %s 2>&1|FileCheck -check-prefix=CHECK-SECOND-WARNING %s
// RUN: c-index-test -test-load-source-reparse 5 all -Wno-return-type %s 2>&1|FileCheck -check-prefix=CHECK-SECOND-WARNING %s
// RUN: c-index-test -test-load-source all -w %s 2>&1|not grep warning:
// RUN: c-index-test -test-load-source-reparse 5 all -w %s 2>&1|not grep warning:
// CHECK-BOTH-WARNINGS: warning: control reaches end of non-void function
// CHECK-BOTH-WARNINGS: warning: incompatible pointer types returning 'float *' from a function with result type 'int *'
// CHECK-SECOND-WARNING-NOT:control reaches end of non-void
// CHECK-SECOND-WARNING: warning: incompatible pointer types returning 'float *' from a function with result type 'int *'

View File

@ -2211,7 +2211,8 @@ static void clang_parseTranslationUnit_Impl(void *UserData) {
// Configure the diagnostics.
DiagnosticOptions DiagOpts;
llvm::IntrusiveRefCntPtr<Diagnostic> Diags;
Diags = CompilerInstance::createDiagnostics(DiagOpts, 0, 0);
Diags = CompilerInstance::createDiagnostics(DiagOpts, num_command_line_args,
command_line_args);
llvm::SmallVector<ASTUnit::RemappedFile, 4> RemappedFiles;
for (unsigned I = 0; I != num_unsaved_files; ++I) {