]> granicus.if.org Git - clang/commitdiff
Don't silently drop warning flags passed in to
authorDouglas Gregor <dgregor@apple.com>
Wed, 19 Jan 2011 01:02:47 +0000 (01:02 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 19 Jan 2011 01:02:47 +0000 (01:02 +0000)
clang_createTranslationUnitFromSourceFile().

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123793 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/ASTUnit.h
lib/Frontend/ASTUnit.cpp
test/Index/warning-flags.c [new file with mode: 0644]
tools/libclang/CIndex.cpp

index 4e27cf3032e90f4528f695083040b52da2ba74a4..c971ccbc64098eb7bbe01df3d2ac647bf95a12b4 100644 (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:
index d042f3fb857794e14ac4498ee6dbd40bfb84108b..b8c27afe5fda07836ce84b6fda67378b3a92023e 100644 (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()));
diff --git a/test/Index/warning-flags.c b/test/Index/warning-flags.c
new file mode 100644 (file)
index 0000000..b76662e
--- /dev/null
@@ -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 *'
+
index 7f00f9982c8c65e2224eed041826ad0b650524bb..1774870e16c03fc33164e509960fed13447351a5 100644 (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) {