From abc0f53e5459af848eecf40ffb883c707745860d Mon Sep 17 00:00:00 2001 From: Richard Howell Date: Wed, 11 Feb 2026 09:52:07 -0800 Subject: [PATCH] [PrintAsClang] skip header maps when collecting include paths Header map lookup is not handled when doing prefix checks for textual header inclusion. Skip adding them to the list instead of adding invalid paths for each header map. --- lib/PrintAsClang/PrintAsClang.cpp | 5 ++++ ...nonmodular-includes-skip-header-maps.swift | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 test/PrintAsObjC/emit-clang-header-nonmodular-includes-skip-header-maps.swift diff --git a/lib/PrintAsClang/PrintAsClang.cpp b/lib/PrintAsClang/PrintAsClang.cpp index bb2ebc32ca3..31897d370a1 100644 --- a/lib/PrintAsClang/PrintAsClang.cpp +++ b/lib/PrintAsClang/PrintAsClang.cpp @@ -450,6 +450,11 @@ writeImports(raw_ostream &out, llvm::SmallPtrSetImpl &imports, for (auto searchDir = clangHeaderSearchInfo.search_dir_begin(); searchDir != clangHeaderSearchInfo.search_dir_end(); ++searchDir) { + // Header map lookup is not supported for now, so don't add the hmap + // paths to the search list. + if (searchDir->isHeaderMap()) + continue; + // Ensure search directories end in / so that we don't prefix match // against a folder that starts with the same substring. auto path = normalizePath(searchDir->getName()); diff --git a/test/PrintAsObjC/emit-clang-header-nonmodular-includes-skip-header-maps.swift b/test/PrintAsObjC/emit-clang-header-nonmodular-includes-skip-header-maps.swift new file mode 100644 index 00000000000..a3f4e0d8afd --- /dev/null +++ b/test/PrintAsObjC/emit-clang-header-nonmodular-includes-skip-header-maps.swift @@ -0,0 +1,26 @@ +// REQUIRES: objc_interop + +// RUN: %empty-directory(%t) + +// Create a header map that maps header-regular.h to its real path. +// RUN: echo '{"mappings": {"header-regular.h": "%/S/Inputs/custom-modules/header_subdirectory/header-regular.h"}}' > %t/hmap.json +// RUN: %hmaptool write %t/hmap.json %t/headers.hmap + +// Compile with the header map as a search directory alongside a regular +// include directory. The header map should be skipped when collecting include +// paths for nonmodular includes. +// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -emit-objc-header-path %t/textual-imports.h -Xcc -fmodule-map-file=%S/Inputs/custom-modules/module.modulemap -Xcc -I%t/headers.hmap -Xcc -I%S/Inputs/custom-modules/header_subdirectory/ -emit-clang-header-nonmodular-includes %s +// RUN: %FileCheck %s < %t/textual-imports.h + +import EmitClangHeaderNonmodularIncludesStressTest + +public class Bar : Baz {} + +// CHECK: @import EmitClangHeaderNonmodularIncludesStressTest; +// CHECK-NEXT: #elif defined(__OBJC__) +// CHECK-NEXT: #import +// CHECK-NEXT: #import +// CHECK-NEXT: #else +// CHECK-NEXT: #include +// CHECK-NEXT: #include +// CHECK-NEXT: #endif