[clang] [clang][modules] Use file name as requested (PR #68957)
https://github.com/jansvoboda11 closed https://github.com/llvm/llvm-project/pull/68957 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][modules] Use file name as requested (PR #68957)
https://github.com/benlangmuir approved this pull request. Thanks https://github.com/llvm/llvm-project/pull/68957 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][modules] Use file name as requested (PR #68957)
@@ -1384,10 +1384,10 @@ void ASTWriter::WriteControlBlock(Preprocessor , ASTContext , SmallVector ModMaps(AdditionalModMaps->begin(), AdditionalModMaps->end()); llvm::sort(ModMaps, [](FileEntryRef A, FileEntryRef B) { -return A.getName() < B.getName(); +return A.getNameAsRequested() < B.getNameAsRequested(); }); for (FileEntryRef F : ModMaps) -AddPath(F.getName(), Record); +AddPath(F.getNameAsRequested(), Record); jansvoboda11 wrote: Done in the two new commits. https://github.com/llvm/llvm-project/pull/68957 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][modules] Use file name as requested (PR #68957)
https://github.com/jansvoboda11 updated https://github.com/llvm/llvm-project/pull/68957 >From 4f60df88e1623733a64896ef332fd9a31e5b0e47 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Thu, 12 Oct 2023 21:46:47 -0700 Subject: [PATCH 1/3] [clang][modules] Use file name as requested This prevents redefinition errors due to having multiple paths for the same module map. (rdar://24116019) Originally implemented and tested downstream by @bcardosolopes, I just made use of `FileEntryRef::getNameAsRequested()`. --- clang/lib/Lex/HeaderSearch.cpp| 2 +- clang/lib/Serialization/ASTWriter.cpp | 4 +-- .../Modules/Inputs/all-product-headers.yaml | 33 +++ clang/test/Modules/modulemap-collision.m | 15 + 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 clang/test/Modules/Inputs/all-product-headers.yaml create mode 100644 clang/test/Modules/modulemap-collision.m diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 4c8b64a374b47d5..cf1c0cc5284f316 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -1623,7 +1623,7 @@ bool HeaderSearch::findUsableModuleForHeader( ModuleMap::KnownHeader *SuggestedModule, bool IsSystemHeaderDir) { if (needModuleLookup(RequestingModule, SuggestedModule)) { // If there is a module that corresponds to this header, suggest it. -hasModuleMap(File.getName(), Root, IsSystemHeaderDir); +hasModuleMap(File.getNameAsRequested(), Root, IsSystemHeaderDir); return suggestModule(*this, File, RequestingModule, SuggestedModule); } return true; diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 27700c711d52fdd..0d216927d76260d 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -1384,10 +1384,10 @@ void ASTWriter::WriteControlBlock(Preprocessor , ASTContext , SmallVector ModMaps(AdditionalModMaps->begin(), AdditionalModMaps->end()); llvm::sort(ModMaps, [](FileEntryRef A, FileEntryRef B) { -return A.getName() < B.getName(); +return A.getNameAsRequested() < B.getNameAsRequested(); }); for (FileEntryRef F : ModMaps) -AddPath(F.getName(), Record); +AddPath(F.getNameAsRequested(), Record); } else { Record.push_back(0); } diff --git a/clang/test/Modules/Inputs/all-product-headers.yaml b/clang/test/Modules/Inputs/all-product-headers.yaml new file mode 100644 index 000..53d683f2ad2ecc0 --- /dev/null +++ b/clang/test/Modules/Inputs/all-product-headers.yaml @@ -0,0 +1,33 @@ +{ + 'version': 0, + 'case-sensitive': 'false', + 'roots': [ +{ + 'type': 'directory', + 'name': "DUMMY_DIR/build/A.framework/PrivateHeaders" + 'contents': [ +{ + 'type': 'file', + 'name': "A.h", + 'external-contents': "DUMMY_DIR/sources/A.h" +} + ] +}, +{ + 'type': 'directory', + 'name': "DUMMY_DIR/build/A.framework/Modules" + 'contents': [ +{ + 'type': 'file', + 'name': "module.modulemap", + 'external-contents': "DUMMY_DIR/build/module.modulemap" +}, +{ + 'type': 'file', + 'name': "module.private.modulemap", + 'external-contents': "DUMMY_DIR/build/module.private.modulemap" +} + ] +} + ] +} diff --git a/clang/test/Modules/modulemap-collision.m b/clang/test/Modules/modulemap-collision.m new file mode 100644 index 000..5ada45da3dae191 --- /dev/null +++ b/clang/test/Modules/modulemap-collision.m @@ -0,0 +1,15 @@ +// REQUIRES: shell + +// RUN: rm -rf %t +// RUN: mkdir -p %t/sources %t/build +// RUN: echo "// A.h" > %t/sources/A.h +// RUN: echo "framework module A {}" > %t/sources/module.modulemap +// RUN: echo "framework module A.Private { umbrella header \"A.h\" }" > %t/sources/module.private.modulemap +// RUN: cp %t/sources/module.modulemap %t/build/module.modulemap +// RUN: cp %t/sources/module.private.modulemap %t/build/module.private.modulemap + +// RUN: sed -e "s:DUMMY_DIR:%t:g" %S/Inputs/all-product-headers.yaml > %t/build/all-product-headers.yaml +// RUN: %clang_cc1 -fsyntax-only -ivfsoverlay %t/build/all-product-headers.yaml -F%t/build -fmodules -fimplicit-module-maps -Wno-private-module -fmodules-cache-path=%t/cache -x objective-c %s -verify + +// expected-no-diagnostics +#import >From 68a9858b1c4c8b2aaee4ebf6a72a9d3c081912fe Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Fri, 13 Oct 2023 17:23:47 -0700 Subject: [PATCH 2/3] [clang] Remove `PointerLikeTypeTraits` --- clang/include/clang/ARCMigrate/FileRemapper.h | 4 +- clang/include/clang/Basic/FileEntry.h | 31 --- clang/include/clang/Basic/Module.h| 12 ++-- .../clang/Frontend/VerifyDiagnosticConsumer.h | 9 +-- clang/include/clang/Lex/ModuleMap.h
[clang] [clang][modules] Use file name as requested (PR #68957)
@@ -1384,10 +1384,10 @@ void ASTWriter::WriteControlBlock(Preprocessor , ASTContext , SmallVector ModMaps(AdditionalModMaps->begin(), AdditionalModMaps->end()); llvm::sort(ModMaps, [](FileEntryRef A, FileEntryRef B) { -return A.getName() < B.getName(); +return A.getNameAsRequested() < B.getNameAsRequested(); }); for (FileEntryRef F : ModMaps) -AddPath(F.getName(), Record); +AddPath(F.getNameAsRequested(), Record); jansvoboda11 wrote: Yeah, this is a bit suspicious. This test started failing downstream after de85739ded2 and this change appeared to be required to fix things. Turns out `llvm::SmallPtrSet` determines equality of elements based on the equality of their `void *` representation, not based on `FileEntryRef::operator==()`. This means that when we find the module map through a VFS, but serialize the on-disk path, we aren't able to correctly match them together in `ASTReader`. I don't want to go messing with the `SmallPtrSet` implementation, so I'll probably just revert [D154905](https://reviews.llvm.org/D154905) (making the types unusable in `SmallPtrSet`) and switch from `llvm::SmallPtrSet` to `llvm::DenseMap`. https://github.com/llvm/llvm-project/pull/68957 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][modules] Use file name as requested (PR #68957)
@@ -1384,10 +1384,10 @@ void ASTWriter::WriteControlBlock(Preprocessor , ASTContext , SmallVector ModMaps(AdditionalModMaps->begin(), AdditionalModMaps->end()); llvm::sort(ModMaps, [](FileEntryRef A, FileEntryRef B) { -return A.getName() < B.getName(); +return A.getNameAsRequested() < B.getNameAsRequested(); }); for (FileEntryRef F : ModMaps) -AddPath(F.getName(), Record); +AddPath(F.getNameAsRequested(), Record); benlangmuir wrote: How does this relate to the header search part of the change? https://github.com/llvm/llvm-project/pull/68957 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][modules] Use file name as requested (PR #68957)
llvmbot wrote: @llvm/pr-subscribers-clang-modules Author: Jan Svoboda (jansvoboda11) Changes This prevents redefinition errors due to having multiple paths for the same module map. (rdar://24116019) Originally implemented and tested downstream by @bcardosolopes, I just made use of `FileEntryRef::getNameAsRequested()`. --- Full diff: https://github.com/llvm/llvm-project/pull/68957.diff 4 Files Affected: - (modified) clang/lib/Lex/HeaderSearch.cpp (+1-1) - (modified) clang/lib/Serialization/ASTWriter.cpp (+2-2) - (added) clang/test/Modules/Inputs/all-product-headers.yaml (+33) - (added) clang/test/Modules/modulemap-collision.m (+15) ``diff diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 4c8b64a374b47d5..cf1c0cc5284f316 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -1623,7 +1623,7 @@ bool HeaderSearch::findUsableModuleForHeader( ModuleMap::KnownHeader *SuggestedModule, bool IsSystemHeaderDir) { if (needModuleLookup(RequestingModule, SuggestedModule)) { // If there is a module that corresponds to this header, suggest it. -hasModuleMap(File.getName(), Root, IsSystemHeaderDir); +hasModuleMap(File.getNameAsRequested(), Root, IsSystemHeaderDir); return suggestModule(*this, File, RequestingModule, SuggestedModule); } return true; diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 27700c711d52fdd..0d216927d76260d 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -1384,10 +1384,10 @@ void ASTWriter::WriteControlBlock(Preprocessor , ASTContext , SmallVector ModMaps(AdditionalModMaps->begin(), AdditionalModMaps->end()); llvm::sort(ModMaps, [](FileEntryRef A, FileEntryRef B) { -return A.getName() < B.getName(); +return A.getNameAsRequested() < B.getNameAsRequested(); }); for (FileEntryRef F : ModMaps) -AddPath(F.getName(), Record); +AddPath(F.getNameAsRequested(), Record); } else { Record.push_back(0); } diff --git a/clang/test/Modules/Inputs/all-product-headers.yaml b/clang/test/Modules/Inputs/all-product-headers.yaml new file mode 100644 index 000..53d683f2ad2ecc0 --- /dev/null +++ b/clang/test/Modules/Inputs/all-product-headers.yaml @@ -0,0 +1,33 @@ +{ + 'version': 0, + 'case-sensitive': 'false', + 'roots': [ +{ + 'type': 'directory', + 'name': "DUMMY_DIR/build/A.framework/PrivateHeaders" + 'contents': [ +{ + 'type': 'file', + 'name': "A.h", + 'external-contents': "DUMMY_DIR/sources/A.h" +} + ] +}, +{ + 'type': 'directory', + 'name': "DUMMY_DIR/build/A.framework/Modules" + 'contents': [ +{ + 'type': 'file', + 'name': "module.modulemap", + 'external-contents': "DUMMY_DIR/build/module.modulemap" +}, +{ + 'type': 'file', + 'name': "module.private.modulemap", + 'external-contents': "DUMMY_DIR/build/module.private.modulemap" +} + ] +} + ] +} diff --git a/clang/test/Modules/modulemap-collision.m b/clang/test/Modules/modulemap-collision.m new file mode 100644 index 000..5ada45da3dae191 --- /dev/null +++ b/clang/test/Modules/modulemap-collision.m @@ -0,0 +1,15 @@ +// REQUIRES: shell + +// RUN: rm -rf %t +// RUN: mkdir -p %t/sources %t/build +// RUN: echo "// A.h" > %t/sources/A.h +// RUN: echo "framework module A {}" > %t/sources/module.modulemap +// RUN: echo "framework module A.Private { umbrella header \"A.h\" }" > %t/sources/module.private.modulemap +// RUN: cp %t/sources/module.modulemap %t/build/module.modulemap +// RUN: cp %t/sources/module.private.modulemap %t/build/module.private.modulemap + +// RUN: sed -e "s:DUMMY_DIR:%t:g" %S/Inputs/all-product-headers.yaml > %t/build/all-product-headers.yaml +// RUN: %clang_cc1 -fsyntax-only -ivfsoverlay %t/build/all-product-headers.yaml -F%t/build -fmodules -fimplicit-module-maps -Wno-private-module -fmodules-cache-path=%t/cache -x objective-c %s -verify + +// expected-no-diagnostics +#import `` https://github.com/llvm/llvm-project/pull/68957 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][modules] Use file name as requested (PR #68957)
https://github.com/jansvoboda11 created https://github.com/llvm/llvm-project/pull/68957 This prevents redefinition errors due to having multiple paths for the same module map. (rdar://24116019) Originally implemented and tested downstream by @bcardosolopes, I just made use of `FileEntryRef::getNameAsRequested()`. >From 4f60df88e1623733a64896ef332fd9a31e5b0e47 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Thu, 12 Oct 2023 21:46:47 -0700 Subject: [PATCH] [clang][modules] Use file name as requested This prevents redefinition errors due to having multiple paths for the same module map. (rdar://24116019) Originally implemented and tested downstream by @bcardosolopes, I just made use of `FileEntryRef::getNameAsRequested()`. --- clang/lib/Lex/HeaderSearch.cpp| 2 +- clang/lib/Serialization/ASTWriter.cpp | 4 +-- .../Modules/Inputs/all-product-headers.yaml | 33 +++ clang/test/Modules/modulemap-collision.m | 15 + 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 clang/test/Modules/Inputs/all-product-headers.yaml create mode 100644 clang/test/Modules/modulemap-collision.m diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 4c8b64a374b47d5..cf1c0cc5284f316 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -1623,7 +1623,7 @@ bool HeaderSearch::findUsableModuleForHeader( ModuleMap::KnownHeader *SuggestedModule, bool IsSystemHeaderDir) { if (needModuleLookup(RequestingModule, SuggestedModule)) { // If there is a module that corresponds to this header, suggest it. -hasModuleMap(File.getName(), Root, IsSystemHeaderDir); +hasModuleMap(File.getNameAsRequested(), Root, IsSystemHeaderDir); return suggestModule(*this, File, RequestingModule, SuggestedModule); } return true; diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 27700c711d52fdd..0d216927d76260d 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -1384,10 +1384,10 @@ void ASTWriter::WriteControlBlock(Preprocessor , ASTContext , SmallVector ModMaps(AdditionalModMaps->begin(), AdditionalModMaps->end()); llvm::sort(ModMaps, [](FileEntryRef A, FileEntryRef B) { -return A.getName() < B.getName(); +return A.getNameAsRequested() < B.getNameAsRequested(); }); for (FileEntryRef F : ModMaps) -AddPath(F.getName(), Record); +AddPath(F.getNameAsRequested(), Record); } else { Record.push_back(0); } diff --git a/clang/test/Modules/Inputs/all-product-headers.yaml b/clang/test/Modules/Inputs/all-product-headers.yaml new file mode 100644 index 000..53d683f2ad2ecc0 --- /dev/null +++ b/clang/test/Modules/Inputs/all-product-headers.yaml @@ -0,0 +1,33 @@ +{ + 'version': 0, + 'case-sensitive': 'false', + 'roots': [ +{ + 'type': 'directory', + 'name': "DUMMY_DIR/build/A.framework/PrivateHeaders" + 'contents': [ +{ + 'type': 'file', + 'name': "A.h", + 'external-contents': "DUMMY_DIR/sources/A.h" +} + ] +}, +{ + 'type': 'directory', + 'name': "DUMMY_DIR/build/A.framework/Modules" + 'contents': [ +{ + 'type': 'file', + 'name': "module.modulemap", + 'external-contents': "DUMMY_DIR/build/module.modulemap" +}, +{ + 'type': 'file', + 'name': "module.private.modulemap", + 'external-contents': "DUMMY_DIR/build/module.private.modulemap" +} + ] +} + ] +} diff --git a/clang/test/Modules/modulemap-collision.m b/clang/test/Modules/modulemap-collision.m new file mode 100644 index 000..5ada45da3dae191 --- /dev/null +++ b/clang/test/Modules/modulemap-collision.m @@ -0,0 +1,15 @@ +// REQUIRES: shell + +// RUN: rm -rf %t +// RUN: mkdir -p %t/sources %t/build +// RUN: echo "// A.h" > %t/sources/A.h +// RUN: echo "framework module A {}" > %t/sources/module.modulemap +// RUN: echo "framework module A.Private { umbrella header \"A.h\" }" > %t/sources/module.private.modulemap +// RUN: cp %t/sources/module.modulemap %t/build/module.modulemap +// RUN: cp %t/sources/module.private.modulemap %t/build/module.private.modulemap + +// RUN: sed -e "s:DUMMY_DIR:%t:g" %S/Inputs/all-product-headers.yaml > %t/build/all-product-headers.yaml +// RUN: %clang_cc1 -fsyntax-only -ivfsoverlay %t/build/all-product-headers.yaml -F%t/build -fmodules -fimplicit-module-maps -Wno-private-module -fmodules-cache-path=%t/cache -x objective-c %s -verify + +// expected-no-diagnostics +#import ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits