From 0b53cf834346d78985aaa9e7300445a39c245614 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 19 Jan 2011 01:02:47 +0000 Subject: [PATCH] Don't silently drop warning flags passed in to clang_createTranslationUnitFromSourceFile(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123793 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/ASTUnit.h | 1 + lib/Frontend/ASTUnit.cpp | 14 +++++++++----- test/Index/warning-flags.c | 16 ++++++++++++++++ tools/libclang/CIndex.cpp | 3 ++- 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 test/Index/warning-flags.c diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index 4e27cf3032..c971ccbc64 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -231,6 +231,7 @@ private: bool ShouldCacheCodeCompletionResults; static void ConfigureDiags(llvm::IntrusiveRefCntPtr &Diags, + const char **ArgBegin, const char **ArgEnd, ASTUnit &AST, bool CaptureDiagnostics); public: diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index d042f3fb85..b8c27afe5f 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -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 &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 &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 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 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 Args; @@ -1543,7 +1547,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin, // Create the AST unit. llvm::OwningPtr 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())); diff --git a/test/Index/warning-flags.c b/test/Index/warning-flags.c new file mode 100644 index 0000000000..b76662e9ee --- /dev/null +++ b/test/Index/warning-flags.c @@ -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 *' + diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 7f00f9982c..1774870e16 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -2211,7 +2211,8 @@ static void clang_parseTranslationUnit_Impl(void *UserData) { // Configure the diagnostics. DiagnosticOptions DiagOpts; llvm::IntrusiveRefCntPtr Diags; - Diags = CompilerInstance::createDiagnostics(DiagOpts, 0, 0); + Diags = CompilerInstance::createDiagnostics(DiagOpts, num_command_line_args, + command_line_args); llvm::SmallVector RemappedFiles; for (unsigned I = 0; I != num_unsaved_files; ++I) { -- 2.40.0