Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ void ExpandModularHeadersPPCallbacks::PragmaDiagnostic(SourceLocation Loc,
}
void ExpandModularHeadersPPCallbacks::HasInclude(SourceLocation Loc, StringRef,
bool, OptionalFileEntryRef,
SrcMgr::CharacteristicKind) {
SrcMgr::CharacteristicKind,
bool AddToDepCollector) {
parseToLocation(Loc);
}
void ExpandModularHeadersPPCallbacks::PragmaOpenCLExtension(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class ExpandModularHeadersPPCallbacks : public PPCallbacks {
void PragmaDiagnostic(SourceLocation Loc, StringRef, diag::Severity,
StringRef) override;
void HasInclude(SourceLocation Loc, StringRef, bool, OptionalFileEntryRef,
SrcMgr::CharacteristicKind) override;
SrcMgr::CharacteristicKind,
bool AddToDepCollector = true) override;
void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *,
SourceLocation StateLoc, unsigned) override;
void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier,
Expand Down
6 changes: 4 additions & 2 deletions clang/include/clang/Lex/PPCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ class PPCallbacks {
/// read.
virtual void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
OptionalFileEntryRef File,
SrcMgr::CharacteristicKind FileType);
SrcMgr::CharacteristicKind FileType,
bool AddToDepCollector = true);

/// Hook called when a source range is skipped.
/// \param Range The SourceRange that was skipped. The range begins at the
Expand Down Expand Up @@ -621,7 +622,8 @@ class PPChainedCallbacks : public PPCallbacks {

void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
OptionalFileEntryRef File,
SrcMgr::CharacteristicKind FileType) override;
SrcMgr::CharacteristicKind FileType,
bool AddToDepCollector = true) override;

void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name,
SourceLocation StateLoc, unsigned State) override {
Expand Down
12 changes: 7 additions & 5 deletions clang/lib/Frontend/DependencyFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,17 @@ struct DepCollectorPPCallbacks : public PPCallbacks {

void HasInclude(SourceLocation Loc, StringRef SpelledFilename, bool IsAngled,
OptionalFileEntryRef File,
SrcMgr::CharacteristicKind FileType) override {
SrcMgr::CharacteristicKind FileType,
bool AddToDepCollector = true) override {
if (!File)
return;
StringRef Filename =
llvm::sys::path::remove_leading_dotslash(File->getName());
DepCollector.maybeAddDependency(Filename, /*FromModule=*/false,
/*IsSystem=*/isSystem(FileType),
/*IsModuleFile=*/false,
/*IsMissing=*/false);
if (AddToDepCollector)
DepCollector.maybeAddDependency(Filename, /*FromModule=*/false,
/*IsSystem=*/isSystem(FileType),
/*IsModuleFile=*/false,
/*IsMissing=*/false);
}

void EndOfMainFile() override {
Expand Down
11 changes: 7 additions & 4 deletions clang/lib/Lex/PPCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ PPCallbacks::~PPCallbacks() = default;

void PPCallbacks::HasInclude(SourceLocation Loc, StringRef FileName,
bool IsAngled, OptionalFileEntryRef File,
SrcMgr::CharacteristicKind FileType) {}
SrcMgr::CharacteristicKind FileType,
bool AddToDepCollector) {}

// Out of line key method.
PPChainedCallbacks::~PPChainedCallbacks() = default;

void PPChainedCallbacks::HasInclude(SourceLocation Loc, StringRef FileName,
bool IsAngled, OptionalFileEntryRef File,
SrcMgr::CharacteristicKind FileType) {
First->HasInclude(Loc, FileName, IsAngled, File, FileType);
Second->HasInclude(Loc, FileName, IsAngled, File, FileType);
SrcMgr::CharacteristicKind FileType,
bool AddToDepCollector) {
First->HasInclude(Loc, FileName, IsAngled, File, FileType, AddToDepCollector);
Second->HasInclude(Loc, FileName, IsAngled, File, FileType,
AddToDepCollector);
}
3 changes: 2 additions & 1 deletion clang/lib/Lex/PPMacroExpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,8 @@ static bool EvaluateHasIncludeCommon(Token &Tok, IdentifierInfo *II,
SrcMgr::CharacteristicKind FileType = SrcMgr::C_User;
if (File)
FileType = PP.getHeaderSearchInfo().getFileDirFlavor(*File);
Callbacks->HasInclude(FilenameLoc, Filename, isAngled, File, FileType);
Callbacks->HasInclude(FilenameLoc, Filename, isAngled, File, FileType,
false);
}

// Get the result value. A result of true means the file exists.
Expand Down
8 changes: 4 additions & 4 deletions clang/test/ClangScanDeps/has_include_if_elif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// RUN: clang-scan-deps -compilation-database %t/cdb.json -mode preprocess | FileCheck %s

// CHECK: tu.c
// CHECK-NEXT: header1.h
// CHECK-NEXT: header2.h
// CHECK-NEXT: header3.h
// CHECK-NEXT: header4.h
// CHECK-NOT: header1.h
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think skipping header1.h is undesired. header1.h is not inside #if 0 ... #endif . Whether the file is present affects the build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that, for this case

#if __has_include(<limits.h>)
// DO NOTHING
#endif

limits.h should be listed in the dependencies?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gcc doesn't, thus glibc depends on this behavior. I guess that we need to make it clear.

// CHECK-NOT: header2.h
// CHECK-NOT: header3.h
// CHECK-NOT: header4.h
6 changes: 3 additions & 3 deletions clang/test/Frontend/dependency-gen-has-include.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
// RUN: FileCheck -input-file=%t.dir/file.deps %s
// CHECK: dependency-gen-has-include.o
// CHECK: dependency-gen-has-include.c
// CHECK: a{{[/\\]}}header.h
// CHECK-NOT: a{{[/\\]}}header.h
// CHECK-NOT: missing{{[/\\]}}file.h
// CHECK: system{{[/\\]}}system-header.h
// CHECK-NOT: system{{[/\\]}}system-header.h
// CHECK: next-a{{[/\\]}}next-header.h
// CHECK: next-b{{[/\\]}}next-header.h
// CHECK-NOT: next-b{{[/\\]}}next-header.h

// Verify that we ignore system headers in user-only headers mode.
// RUN: %clang -MMD -MF %t.dir/user-headers.deps %s -fsyntax-only -I %t.dir -isystem %t.dir/system -I %t.dir/next-a -I %t.dir/next-b
Expand Down
23 changes: 23 additions & 0 deletions clang/test/Preprocessor/dependencies-on-has-include.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Test -MF and -E flags with has_include

#ifdef TEST_HAS_INCLUDE_NEXT
#if __has_include_next(<limits.h>)
// DO NOTHING
#endif
#endif

#ifdef TEST_HAS_INCLUDE
#if __has_include(<limits.h>)
// DO NOTHING
#endif
#endif

// RUN: %clang -DTEST_HAS_INCLUDE -E -MD -MF - %s \
// RUN: | FileCheck -check-prefix=TEST-HAS %s
// TEST-HAS: dependencies-on-has-include.o:
// TEST-HAS-NOT: limits.h

// RUN: %clang -Wno-include-next-outside-header -DTEST_HAS_INCLUDE_NEXT -E -MD -MF - %s \
// RUN: | FileCheck -check-prefix=TEST-HAS-N %s
// TEST-HAS-N: dependencies-on-has-include.o:
// TEST-HAS-N-NOT: limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,9 @@ TEST(DependencyScanner, ScanDepsReuseFilemanagerHasInclude) {
TestDependencyScanningAction Action(Deps);
Tool.run(&Action);
using llvm::sys::path::convert_to_slash;
ASSERT_EQ(Deps.size(), 6u);
ASSERT_EQ(Deps.size(), 2u);
EXPECT_EQ(convert_to_slash(Deps[0]), "/root/test.cpp");
EXPECT_EQ(convert_to_slash(Deps[1]), "/root/header.h");
EXPECT_EQ(convert_to_slash(Deps[2]), "/root/symlink.h");
EXPECT_EQ(convert_to_slash(Deps[3]), "/root/test.cpp");
EXPECT_EQ(convert_to_slash(Deps[4]), "/root/header.h");
EXPECT_EQ(convert_to_slash(Deps[5]), "/root/symlink.h");
EXPECT_EQ(convert_to_slash(Deps[1]), "/root/test.cpp");
}

TEST(DependencyScanner, ScanDepsWithFS) {
Expand Down
Loading