-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Implement -Wmissing-include-dirs #94827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang Author: Braden Helmer (bradenhelmer) ChangesImplements -Wmissing-include-dirs #92015 This is my first contribution and would love some feedback. Thanks Full diff: https://github.com/llvm/llvm-project/pull/94827.diff 3 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 773b234cd68fe..b7d50e22cc0d0 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 <
+ "the included directory %0 is missing">, InGroup<MissingIncludeDirs>;
}
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..5bc737a43338e 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1271,6 +1271,12 @@ 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
+ for (auto IncludeDir : Args.getAllArgValues(options::OPT_I_Group)) {
+ if (!llvm::sys::fs::is_directory(IncludeDir))
+ Diag(diag::warn_missing_include_dirs) << IncludeDir;
+ }
+
// FIXME: This stuff needs to go into the Compilation, not the driver.
bool CCCPrintPhases;
|
@llvm/pr-subscribers-clang-driver Author: Braden Helmer (bradenhelmer) ChangesImplements -Wmissing-include-dirs #92015 This is my first contribution and would love some feedback. Thanks Full diff: https://github.com/llvm/llvm-project/pull/94827.diff 3 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 773b234cd68fe..b7d50e22cc0d0 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 <
+ "the included directory %0 is missing">, InGroup<MissingIncludeDirs>;
}
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..5bc737a43338e 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1271,6 +1271,12 @@ 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
+ for (auto IncludeDir : Args.getAllArgValues(options::OPT_I_Group)) {
+ if (!llvm::sys::fs::is_directory(IncludeDir))
+ Diag(diag::warn_missing_include_dirs) << IncludeDir;
+ }
+
// FIXME: This stuff needs to go into the Compilation, not the driver.
bool CCCPrintPhases;
|
In a real-world case with functions that have many, many R_RISCV_CALL_PLT relocations due to asan and ubsan instrumentation, all these can be relaxed by an instruction and the net result is more than 65536 bytes of reduction in the output .text section that totals about 1.2MiB in final size. This changes InputSection to use a 32-bit field for bytesDropped. The RISCV relaxation keeps track in a 64-bit field and detects 32-bit overflow as it previously detected 16-bit overflow. It doesn't seem likely that 32-bit overflow will arise, but it's not inconceivable and it's cheap enough to detect it. This unfortunately increases the size of InputSection on 64-bit hosts by a word, but that seems hard to avoid. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D150722
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! The main missing thing is a test for this. Have a look in clang/test/Driver/
to see what the tests can look like.
Some existing tests are failing, see https://buildkite.com/llvm-project/github-pull-requests/builds/70953#018ff782-9ba1-426b-bb3e-7c0e93533ba4
For example it seems clang/test/Frontend/warning-poison-system-directories.c is failing because it builds with -Werror and passes -I flags with directories that don't exist on Windows.
clang/test/Driver/cl-pch.c also failed, but it's not clear to me why.
Maybe if the flag is not enabled by default, these test failures will go away.
@@ -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 < |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no space between Warning
and <
, and two spaces for indentation on the next line
This makes the warning enabled by default. I'm not sure whether that's desirable. Maybe it should be under -Wall
or -Wextra
(what does gcc do?)
To achieve that, add the DefaultIgnore
mark to this definition, and add InGroup<All>
or Extra
to the DiagGroup
definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested with GCC, its not enabled in -Wall
or -Wextra
, leaving as DefaultIgnore
for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This basically looks good to me. Just a few nits.
@@ -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< | |||
"the included directory %0 is missing">, InGroup<MissingIncludeDirs>, DefaultIgnore; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's make this a little shorter and more precise by copying the sysroot warning from the test, how about: "no such include directory: ..."
|
||
// 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: the included directory {{.*}}/warning-options is missing [-Wmissing-include-dirs] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we usually don't include the "[-Warning-flag-name]" in the check (you can just drop that part, the check doesn't have to cover the whole line)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Do you have access to press the "Squash and merge" button, or should I do it? |
You'll have to, i dont have access yet, thx |
@bradenhelmer Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested Please check whether problems have been caused by your change specifically, as How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Implements -Wmissing-include-dirs #92015
This is my first contribution and would love some feedback. Thanks!