[clang] 83a54e7 - [clang] Implement -Wmissing-include-dirs (#94827)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 12 02:30:14 PDT 2024


Author: Braden Helmer
Date: 2024-06-12T11:30:10+02:00
New Revision: 83a54e75c1229be99875901139f7722be643ce87

URL: https://github.com/llvm/llvm-project/commit/83a54e75c1229be99875901139f7722be643ce87
DIFF: https://github.com/llvm/llvm-project/commit/83a54e75c1229be99875901139f7722be643ce87.diff

LOG: [clang] Implement -Wmissing-include-dirs (#94827)

Implements -Wmissing-include-dirs #92015 

This is my first contribution and would love some feedback. Thanks!

Added: 
    

Modified: 
    clang/include/clang/Basic/DiagnosticDriverKinds.td
    clang/include/clang/Basic/DiagnosticGroups.td
    clang/lib/Driver/Driver.cpp
    clang/test/Driver/warning-options.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 773b234cd68fe..1ca2cb85565a1 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -809,4 +809,7 @@ def warn_android_unversioned_fallback : Warning<
 
 def err_drv_triple_version_invalid : Error<
   "version '%0' in target triple '%1' is invalid">;
+
+def warn_missing_include_dirs : Warning<
+  "no such include directory: '%0'">, InGroup<MissingIncludeDirs>, DefaultIgnore;
 }

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 7d5ba7869ec34..9b37d4bd3205b 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -506,7 +506,7 @@ def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
 def : DiagGroup<"missing-format-attribute">;
-def : DiagGroup<"missing-include-dirs">;
+def MissingIncludeDirs : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
 def : DiagGroup<"nested-externs">;

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index f5ea73a04ae5c..67bf0604acd6e 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1271,6 +1271,14 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
     if (VFS->setCurrentWorkingDirectory(WD->getValue()))
       Diag(diag::err_drv_unable_to_set_working_directory) << WD->getValue();
 
+  // Check for missing include directories.
+  if (!Diags.isIgnored(diag::warn_missing_include_dirs, SourceLocation())) {
+    for (auto IncludeDir : Args.getAllArgValues(options::OPT_I_Group)) {
+      if (!VFS->exists(IncludeDir))
+        Diag(diag::warn_missing_include_dirs) << IncludeDir;
+    }
+  }
+
   // FIXME: This stuff needs to go into the Compilation, not the driver.
   bool CCCPrintPhases;
 

diff  --git a/clang/test/Driver/warning-options.cpp b/clang/test/Driver/warning-options.cpp
index d836ad143a1c5..a7020ff4fc1d9 100644
--- a/clang/test/Driver/warning-options.cpp
+++ b/clang/test/Driver/warning-options.cpp
@@ -6,3 +6,7 @@
 // Check that -isysroot warns on nonexistent paths.
 // RUN: %clang -### -c -target i386-apple-darwin10 -isysroot %t/warning-options %s 2>&1 | FileCheck --check-prefix=CHECK-ISYSROOT %s
 // CHECK-ISYSROOT: warning: no such sysroot directory: '{{.*}}/warning-options'
+
+// Check for proper warning with -Wmissing-include-dirs
+// RUN: %clang -### -Wmissing-include-dirs -I %t/warning-options %s 2>&1 | FileCheck --check-prefix=CHECK-MISSING-INCLUDE-DIRS %s
+// CHECK-MISSING-INCLUDE-DIRS: warning: no such include directory: '{{.*}}/warning-options'


        


More information about the cfe-commits mailing list