Skip to content

Commit 2e5e5a7

Browse files
author
git apple-llvm automerger
committed
Merge commit '989a40cba889' from llvm.org/main into next
2 parents 2e1bea3 + 989a40c commit 2e5e5a7

File tree

3 files changed

+115
-15
lines changed

3 files changed

+115
-15
lines changed

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,29 @@ struct InputFileEntry {
18241824
uint32_t ContentHash[2];
18251825

18261826
InputFileEntry(FileEntryRef File) : File(File) {}
1827+
1828+
void trySetContentHash(
1829+
Preprocessor &PP,
1830+
llvm::function_ref<std::optional<llvm::MemoryBufferRef>()> GetMemBuff) {
1831+
ContentHash[0] = 0;
1832+
ContentHash[1] = 0;
1833+
1834+
if (!PP.getHeaderSearchInfo()
1835+
.getHeaderSearchOpts()
1836+
.ValidateASTInputFilesContent)
1837+
return;
1838+
1839+
auto MemBuff = GetMemBuff();
1840+
if (!MemBuff) {
1841+
PP.Diag(SourceLocation(), diag::err_module_unable_to_hash_content)
1842+
<< File.getName();
1843+
return;
1844+
}
1845+
1846+
uint64_t Hash = xxh3_64bits(MemBuff->getBuffer());
1847+
ContentHash[0] = uint32_t(Hash);
1848+
ContentHash[1] = uint32_t(Hash >> 32);
1849+
}
18271850
};
18281851

18291852
} // namespace
@@ -1898,25 +1921,41 @@ void ASTWriter::WriteInputFiles(SourceManager &SourceMgr) {
18981921
!IsSLocFileEntryAffecting[IncludeFileID.ID];
18991922
Entry.IsModuleMap = isModuleMap(File.getFileCharacteristic());
19001923

1901-
uint64_t ContentHash = 0;
1902-
if (PP->getHeaderSearchInfo()
1903-
.getHeaderSearchOpts()
1904-
.ValidateASTInputFilesContent) {
1905-
auto MemBuff = Cache->getBufferIfLoaded();
1906-
if (MemBuff)
1907-
ContentHash = xxh3_64bits(MemBuff->getBuffer());
1908-
else
1909-
PP->Diag(SourceLocation(), diag::err_module_unable_to_hash_content)
1910-
<< Entry.File.getName();
1911-
}
1912-
Entry.ContentHash[0] = uint32_t(ContentHash);
1913-
Entry.ContentHash[1] = uint32_t(ContentHash >> 32);
1924+
Entry.trySetContentHash(*PP, [&] { return Cache->getBufferIfLoaded(); });
1925+
19141926
if (Entry.IsSystemFile)
19151927
SystemFiles.push_back(Entry);
19161928
else
19171929
UserFiles.push_back(Entry);
19181930
}
19191931

1932+
// FIXME: Make providing input files not in the SourceManager more flexible.
1933+
// The SDKSettings.json file is necessary for correct evaluation of
1934+
// availability annotations.
1935+
StringRef Sysroot = PP->getHeaderSearchInfo().getHeaderSearchOpts().Sysroot;
1936+
if (!Sysroot.empty()) {
1937+
SmallString<128> SDKSettingsJSON = Sysroot;
1938+
llvm::sys::path::append(SDKSettingsJSON, "SDKSettings.json");
1939+
FileManager &FM = PP->getFileManager();
1940+
if (auto FE = FM.getOptionalFileRef(SDKSettingsJSON)) {
1941+
InputFileEntry Entry(*FE);
1942+
Entry.IsSystemFile = true;
1943+
Entry.IsTransient = false;
1944+
Entry.BufferOverridden = false;
1945+
Entry.IsTopLevel = true;
1946+
Entry.IsModuleMap = false;
1947+
std::unique_ptr<MemoryBuffer> MB;
1948+
Entry.trySetContentHash(*PP, [&]() -> std::optional<MemoryBufferRef> {
1949+
if (auto MBOrErr = FM.getBufferForFile(Entry.File)) {
1950+
MB = std::move(*MBOrErr);
1951+
return MB->getMemBufferRef();
1952+
}
1953+
return std::nullopt;
1954+
});
1955+
SystemFiles.push_back(Entry);
1956+
}
1957+
}
1958+
19201959
// User files go at the front, system files at the back.
19211960
auto SortedFiles = llvm::concat<InputFileEntry>(std::move(UserFiles),
19221961
std::move(SystemFiles));
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// This test checks that the module cache gets invalidated when the SDKSettings.json file changes.
2+
3+
// RUN: rm -rf %t
4+
// RUN: split-file %s %t
5+
6+
//--- AppleTVOS15.0.sdk/SDKSettings-old.json
7+
{
8+
"DisplayName": "tvOS 15.0",
9+
"Version": "15.0",
10+
"CanonicalName": "appletvos15.0",
11+
"MaximumDeploymentTarget": "15.0.99",
12+
"PropertyConditionFallbackNames": []
13+
}
14+
//--- AppleTVOS15.0.sdk/SDKSettings-new.json
15+
{
16+
"DisplayName": "tvOS 15.0",
17+
"Version": "15.0",
18+
"CanonicalName": "appletvos15.0",
19+
"MaximumDeploymentTarget": "15.0.99",
20+
"PropertyConditionFallbackNames": [],
21+
"VersionMap": {
22+
"iOS_tvOS": {
23+
"13.2": "13.1"
24+
},
25+
"tvOS_iOS": {
26+
"13.1": "13.2"
27+
}
28+
}
29+
}
30+
//--- module.modulemap
31+
module M { header "M.h" }
32+
//--- M.h
33+
void foo(void) __attribute__((availability(iOS, obsoleted = 13.2)));
34+
void test() { foo(); }
35+
36+
//--- tu.m
37+
#include "M.h"
38+
39+
// Compiling for tvOS 13.1 without "VersionMap" should succeed, since by default iOS 13.2 gets mapped to tvOS 13.2,
40+
// and \c foo is therefore **not** deprecated.
41+
// RUN: cp %t/AppleTVOS15.0.sdk/SDKSettings-old.json %t/AppleTVOS15.0.sdk/SDKSettings.json
42+
// RUN: %clang -target x86_64-apple-tvos13.1 -isysroot %t/AppleTVOS15.0.sdk \
43+
// RUN: -fsyntax-only %t/tu.m -o %t/tu.o -fmodules -Xclang -fdisable-module-hash -fmodules-cache-path=%t/cache
44+
45+
// Compiling for tvOS 13.1 with "VersionMap" saying it maps to iOS 13.2 should fail, since \c foo is now deprecated.
46+
// RUN: sleep 1
47+
// RUN: cp %t/AppleTVOS15.0.sdk/SDKSettings-new.json %t/AppleTVOS15.0.sdk/SDKSettings.json
48+
// RUN: not %clang -target x86_64-apple-tvos13.1 -isysroot %t/AppleTVOS15.0.sdk \
49+
// RUN: -fsyntax-only %t/tu.m -o %t/tu.o -fmodules -Xclang -fdisable-module-hash -fmodules-cache-path=%t/cache 2>&1 \
50+
// RUN: | FileCheck %s
51+
// CHECK: M.h:2:15: error: 'foo' is unavailable: obsoleted in tvOS 13.1
52+
// CHECK: M.h:1:6: note: 'foo' has been explicitly marked unavailable here
53+
// CHECK: tu.m:1:10: fatal error: could not build module 'M'

clang/tools/clang-scan-deps/ClangScanDeps.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,10 @@ template <typename Container>
601601
static auto toJSONStrings(llvm::json::OStream &JOS, Container &&Strings) {
602602
return [&JOS, Strings = std::forward<Container>(Strings)] {
603603
for (StringRef Str : Strings)
604-
JOS.value(Str);
604+
// Not reporting SDKSettings.json so that test checks can remain (mostly)
605+
// platform-agnostic.
606+
if (!Str.ends_with("SDKSettings.json"))
607+
JOS.value(Str);
605608
};
606609
}
607610

@@ -764,7 +767,12 @@ class FullDeps {
764767
toJSONStrings(JOS, MD.getBuildArguments()));
765768
JOS.attribute("context-hash", StringRef(MD.ID.ContextHash));
766769
JOS.attributeArray("file-deps", [&] {
767-
MD.forEachFileDep([&](StringRef FileDep) { JOS.value(FileDep); });
770+
MD.forEachFileDep([&](StringRef FileDep) {
771+
// Not reporting SDKSettings.json so that test checks can remain
772+
// (mostly) platform-agnostic.
773+
if (!FileDep.ends_with("SDKSettings.json"))
774+
JOS.value(FileDep);
775+
});
768776
});
769777
JOS.attributeArray("link-libraries",
770778
toJSONSorted(JOS, MD.LinkLibraries));

0 commit comments

Comments
 (0)