[clang] [llvm] [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (PR #75385)
dexonsmith wrote: I remember discovering that there are effectively two kinds of DISubprogram already... one for declarations (which usually get uniqued/deduped) and another for definitions (which I believe never do... IIRC they are always "distinct"). I imagine it would be possible/good to separate into two classes. If I'd understood there were two uses I would have done so originally. (The main effort is updating testcases.) Even without two classes, you might be able to clean up the type graph, knowing that there are in fact two ways DISubprogram is used. https://github.com/llvm/llvm-project/pull/75385 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (PR #75385)
dexonsmith wrote: > An immediate fix would be to not set the "identifier" field for the > DICompositeType when it's created if it's inside a function scope to avoid > ODRUniqing. I've only got a light understanding of what the identifier field > is for, so there might be unexpected consequences, plus there'll be a > metadata/DWARF size cost to that. Actually, that seems like probably the correct fix. The identifier field is precisely for "ODR-unique-based-on-this" and only for that, IIRC (@aprantl, can you confirm? these are old memories for me at this point...). If the function-local types should not be ODR-uniqued, then dropping the identifier field sounds correct. https://github.com/llvm/llvm-project/pull/75385 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Processing real directories added as virtual ones (PR #91645)
dexonsmith wrote: @benlangmuir and @jansvoboda11 might also be good reviewers for this. https://github.com/llvm/llvm-project/pull/91645 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] NFC: Remove `{File, Directory}Entry::getName()` (PR #74910)
https://github.com/dexonsmith approved this pull request. Amazing! LGTM, once the branch is clear. https://github.com/llvm/llvm-project/pull/74910 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Bfi precision (PR #66285)
dexonsmith wrote: Interesting. Probably `Value::getMetadata()` could/should call `DenseMap::find()` instead of `operator[]()` and assert that it's found before dereferencing, because `Value::hasMetadata()` (which, IIRC, consults a bit stored in `Value`) has already promised something will be there. Probably you'll find me on the git-blame for this... Your plan SGTM! https://github.com/llvm/llvm-project/pull/66285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Bfi precision (PR #66285)
dexonsmith wrote: > Seems this got introduced in https://reviews.llvm.org/D34312 with the rough > idea that we shouldn't inline into parts of the code that > `_builtin_expect(...)` deems unlikely. Which makes sense when you express it > like this, but I guess numeric thresholds can go wrong... Heh, yeah, the premise seems correct, but a percentage-based numeric threshold doesn't seem right. You kind of want a flag for the block. Or a special value, like "freq=0", which indicates "annotation says this is cold". https://github.com/llvm/llvm-project/pull/66285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Bfi precision (PR #66285)
dexonsmith wrote: Not entirely accidental. When BPI/BFI first landed it was heavily profiled to be sure it didn't pessimize non-PGO code. I don't see why we'd suddenly be okay with pessimizing it. Under 2% isn't hard to hit for hot path code. Lots of functions will have strings of early exit conditions. https://github.com/llvm/llvm-project/pull/66285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Bfi precision (PR #66285)
dexonsmith wrote: Not entirely accidental. When BPI/BFI first landed it was heavily profiled to be sure it didn't pessimize non-PGO code. I don't see why we'd suddenly be okay with pessimizing it. Under 2% isn't hard to hit for hot path code. Lots of functions will have strings of early exit conditions. https://github.com/llvm/llvm-project/pull/66285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Bfi precision (PR #66285)
dexonsmith wrote: Seems awkward to pessimize as "cold" when there's no real data (no PGO, no other marking). What happens if you change the cold call threshold to 0% when there's no PGO data? (I.e., never assume a call is cold without actual evidence) https://github.com/llvm/llvm-project/pull/66285 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] c1e17c7 - ExtractAPI: Use %clang_cc1 and -verify in enum.c
Author: Duncan P. N. Exon Smith Date: 2022-05-03T11:57:24-07:00 New Revision: c1e17c7dfedd27b95c8c2fba2b6473c7348f0e77 URL: https://github.com/llvm/llvm-project/commit/c1e17c7dfedd27b95c8c2fba2b6473c7348f0e77 DIFF: https://github.com/llvm/llvm-project/commit/c1e17c7dfedd27b95c8c2fba2b6473c7348f0e77.diff LOG: ExtractAPI: Use %clang_cc1 and -verify in enum.c Fix one test (enum.c) in ExtractAPI to use %clang_cc1 and -verify instead of calling the full driver and FileCheck. This is an example for my comment from https://reviews.llvm.org/D121873. Differential Revision: https://reviews.llvm.org/D124634 Added: Modified: clang/test/ExtractAPI/enum.c Removed: diff --git a/clang/test/ExtractAPI/enum.c b/clang/test/ExtractAPI/enum.c index a14666a037471..8c06d850dbdaf 100644 --- a/clang/test/ExtractAPI/enum.c +++ b/clang/test/ExtractAPI/enum.c @@ -2,17 +2,14 @@ // RUN: split-file %s %t // RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \ // RUN: %t/reference.output.json.in >> %t/reference.output.json -// RUN: %clang -extract-api -target arm64-apple-macosx \ -// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s +// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \ +// RUN: -x c-header %t/input.h -o %t/output.json -verify // Generator version is not consistent across test runs, normalize it. // RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \ // RUN: %t/output.json >> %t/output-normalized.json // RUN: diff %t/reference.output.json %t/output-normalized.json -// CHECK-NOT: error: -// CHECK-NOT: warning: - //--- input.h /// Kinds of vehicles enum Vehicle { @@ -37,6 +34,7 @@ enum { enum { OtherConstant = 2 }; +// expected-no-diagnostics //--- reference.output.json.in { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 2d13386 - Frontend: Delete output streams before closing CompilerInstance outputs
Author: Duncan P. N. Exon Smith Date: 2022-04-28T19:07:40-07:00 New Revision: 2d133867833fe8eb20c11377ff1221f71afc1db3 URL: https://github.com/llvm/llvm-project/commit/2d133867833fe8eb20c11377ff1221f71afc1db3 DIFF: https://github.com/llvm/llvm-project/commit/2d133867833fe8eb20c11377ff1221f71afc1db3.diff LOG: Frontend: Delete output streams before closing CompilerInstance outputs Delete the output streams coming from CompilerInstance::createOutputFile() and friends once writes are finished. Concretely, replacing `OS->flush()` with `OS.reset()` in: - `ExtractAPIAction::EndSourceFileAction()` - `PrecompiledPreambleAction::setEmittedPreamblePCH()` - `cc1_main()'s support for `-ftime-trace` This fixes theoretical bugs related to proxy streams, which may have cleanups to run in their destructor. For example, a proxy that CompilerInstance sometimes uses is `buffer_ostream`, which wraps a `raw_ostream` lacking pwrite support and adds it. `flush()` does not promise that output is complete; `buffer_ostream` needs to wait until the destructor to forward anything so that it can service later calls to `pwrite()`. If the destructor isn't called then the proxied stream hasn't received any content. This also protects against some logic bugs, triggering a null dereference on a later attempt to write to the stream. No tests, since in practice these particular code paths never use use `buffer_ostream`; you need to be writing a binary file to a pipe (such as stdout) to hit it, but `-extract-api` writes a text file and the other two use computed filenames that will never (in practice) be a pipe. This is effectively NFC, for now. But I have some other patches in the works that add guard rails, crashing if the stream hasn't been destructed by the time the CompilerInstance is told to keep the output file, since in most cases this is a problem. Differential Revision: https://reviews.llvm.org/D124635 Added: Modified: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp clang/lib/Frontend/PrecompiledPreamble.cpp clang/tools/driver/cc1_main.cpp Removed: diff --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp index 0217c656cbb04..b1de2674b622b 100644 --- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp +++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp @@ -793,7 +793,7 @@ void ExtractAPIAction::EndSourceFileAction() { // FIXME: Make the kind of APISerializer configurable. SymbolGraphSerializer SGSerializer(*API, ProductName); SGSerializer.serialize(*OS); - OS->flush(); + OS.reset(); } std::unique_ptr diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp index 341ea6121637d..d5aab4aedadd6 100644 --- a/clang/lib/Frontend/PrecompiledPreamble.cpp +++ b/clang/lib/Frontend/PrecompiledPreamble.cpp @@ -248,7 +248,7 @@ class PrecompilePreambleAction : public ASTFrontendAction { if (FileOS) { *FileOS << Buffer->Data; // Make sure it hits disk now. - FileOS->flush(); + FileOS.reset(); } this->HasEmittedPreamblePCH = true; diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp index f648adeba4834..5adc07154f88c 100644 --- a/clang/tools/driver/cc1_main.cpp +++ b/clang/tools/driver/cc1_main.cpp @@ -260,8 +260,7 @@ int cc1_main(ArrayRef Argv, const char *Argv0, void *MainAddr) { Path.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false, /*useTemporary=*/false)) { llvm::timeTraceProfilerWrite(*profilerOutput); - // FIXME(ibiryukov): make profilerOutput flush in destructor instead. - profilerOutput->flush(); + profilerOutput.reset(); llvm::timeTraceProfilerCleanup(); Clang->clearOutputFiles(false); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 37e7cf7 - Driver: Make macOS the default target OS for -arch arm64
Author: Duncan P. N. Exon Smith Date: 2022-03-18T13:36:47-07:00 New Revision: 37e7cf7f1c6920d33a4a5dd3f0a415a61dd24731 URL: https://github.com/llvm/llvm-project/commit/37e7cf7f1c6920d33a4a5dd3f0a415a61dd24731 DIFF: https://github.com/llvm/llvm-project/commit/37e7cf7f1c6920d33a4a5dd3f0a415a61dd24731.diff LOG: Driver: Make macOS the default target OS for -arch arm64 This is a follow up to 565603cc94d79a8d0de6df840fd53714899fb890, which made macOS the default target OS for `-arch arm64` when running on an Apple Silicon Mac. Now it'll be the default when running on an Intel Mac too. clang/test/Driver/apple-arm64-arch.c was a bit odd before: it was added for the above commit, but tested the inverse behaviour and XFAIL'ed on Apple Silicon. This inverts it to the (new) behaviour (that's now correct regardless) and removes the XFAIL. Radar-Id: rdar://90500294 Added: Modified: clang/lib/Driver/ToolChains/Darwin.cpp clang/test/Driver/apple-arm64-arch.c Removed: diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index a11cd3fbaa71c..47eb14ffb83e4 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1886,16 +1886,9 @@ inferDeploymentTargetFromArch(DerivedArgList &Args, const Darwin &Toolchain, llvm::Triple::OSType OSTy = llvm::Triple::UnknownOS; StringRef MachOArchName = Toolchain.getMachOArchName(Args); - if (MachOArchName == "arm64" || MachOArchName == "arm64e") { -#if __arm64__ -// A clang running on an Apple Silicon mac defaults -// to building for mac when building for arm64 rather than -// defaulting to iOS. + if (MachOArchName == "arm64" || MachOArchName == "arm64e") OSTy = llvm::Triple::MacOSX; -#else -OSTy = llvm::Triple::IOS; -#endif - } else if (MachOArchName == "armv7" || MachOArchName == "armv7s") + else if (MachOArchName == "armv7" || MachOArchName == "armv7s") OSTy = llvm::Triple::IOS; else if (MachOArchName == "armv7k" || MachOArchName == "arm64_32") OSTy = llvm::Triple::WatchOS; diff --git a/clang/test/Driver/apple-arm64-arch.c b/clang/test/Driver/apple-arm64-arch.c index a37346b1a9bb0..a111260b38a6b 100644 --- a/clang/test/Driver/apple-arm64-arch.c +++ b/clang/test/Driver/apple-arm64-arch.c @@ -2,6 +2,5 @@ // RUN: FileCheck %s // // REQUIRES: system-darwin -// XFAIL: apple-silicon-mac // -// CHECK: "-triple" "arm64-apple-ios{{[0-9.]+}}" +// CHECK: "-triple" "arm64-apple-macosx{{[0-9.]+}}" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 3110060 - AST: Avoid using SmallVector::set_size() in UnresolvedSet
Author: Duncan P. N. Exon Smith Date: 2022-01-11T17:47:23-08:00 New Revision: 3110060bc721a02e69ead4c56e037a03d31bedef URL: https://github.com/llvm/llvm-project/commit/3110060bc721a02e69ead4c56e037a03d31bedef DIFF: https://github.com/llvm/llvm-project/commit/3110060bc721a02e69ead4c56e037a03d31bedef.diff LOG: AST: Avoid using SmallVector::set_size() in UnresolvedSet Update UnresolvedSet to use (and expose) `SmallVector::truncate()` instead of `SmallVector::set_size()`. The latter is going to made private in a future commit to avoid misuse. Differential Revision: https://reviews.llvm.org/D115386 Added: Modified: clang/include/clang/AST/UnresolvedSet.h clang/lib/Sema/SemaLookup.cpp Removed: diff --git a/clang/include/clang/AST/UnresolvedSet.h b/clang/include/clang/AST/UnresolvedSet.h index c75aa0785a63a..17b47f6ab96be 100644 --- a/clang/include/clang/AST/UnresolvedSet.h +++ b/clang/include/clang/AST/UnresolvedSet.h @@ -121,7 +121,7 @@ class UnresolvedSetImpl { void setAccess(iterator I, AccessSpecifier AS) { I.I->setAccess(AS); } void clear() { decls().clear(); } - void set_size(unsigned N) { decls().set_size(N); } + void truncate(unsigned N) { decls().truncate(N); } bool empty() const { return decls().empty(); } unsigned size() const { return decls().size(); } diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index c905a10990d21..af6ee24240ceb 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -620,7 +620,7 @@ void LookupResult::resolveKind() { getSema().diagnoseEquivalentInternalLinkageDeclarations( getNameLoc(), HasNonFunction, EquivalentNonFunctions); - Decls.set_size(N); + Decls.truncate(N); if (HasNonFunction && (HasFunction || HasUnresolved)) Ambiguous = true; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] f0b2a1a - ASTMatchers: Avoid using SmallVector::set_size()
Author: Duncan P. N. Exon Smith Date: 2022-01-11T17:01:46-08:00 New Revision: f0b2a1a629dab17f2ea161a9281d8dc63b37a7a0 URL: https://github.com/llvm/llvm-project/commit/f0b2a1a629dab17f2ea161a9281d8dc63b37a7a0 DIFF: https://github.com/llvm/llvm-project/commit/f0b2a1a629dab17f2ea161a9281d8dc63b37a7a0.diff LOG: ASTMatchers: Avoid using SmallVector::set_size() Update `variadicMatcherDescriptor` to assert on reserved capacity and to call `emplace_back()` instead of calling `set_size()` and constructing the element in-place. Differential Revision: https://reviews.llvm.org/D115379 Added: Modified: clang/lib/ASTMatchers/Dynamic/Marshallers.h Removed: diff --git a/clang/lib/ASTMatchers/Dynamic/Marshallers.h b/clang/lib/ASTMatchers/Dynamic/Marshallers.h index 2b4d9b6a7e852..3e9c4f31b84d3 100644 --- a/clang/lib/ASTMatchers/Dynamic/Marshallers.h +++ b/clang/lib/ASTMatchers/Dynamic/Marshallers.h @@ -524,8 +524,9 @@ variadicMatcherDescriptor(StringRef MatcherName, SourceRange NameRange, } return {}; } -InnerArgs.set_size(i + 1); -InnerArgsPtr[i] = new (&InnerArgs[i]) ArgT(ArgTraits::get(Value)); +assert(InnerArgs.size() < InnerArgs.capacity()); +InnerArgs.emplace_back(ArgTraits::get(Value)); +InnerArgsPtr[i] = &InnerArgs[i]; } return outvalueToVariantMatcher(Func(InnerArgsPtr)); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cfd1d49 - OpenMP: Avoid using SmallVector::set_size()
Author: Duncan P. N. Exon Smith Date: 2021-12-08T15:22:50-08:00 New Revision: cfd1d49dc0cc4369ace2e9485bdba04b27f158b5 URL: https://github.com/llvm/llvm-project/commit/cfd1d49dc0cc4369ace2e9485bdba04b27f158b5 DIFF: https://github.com/llvm/llvm-project/commit/cfd1d49dc0cc4369ace2e9485bdba04b27f158b5.diff LOG: OpenMP: Avoid using SmallVector::set_size() Update `OpenMPIRBuilder::collapseLoops()` to call `resize()` instead of `set_size()`. The latter asserts on capacity limits and cannot grow, which seems likely to be unintentional here (if it is, I think a local assertion would be good for clarity). Also update `CodeGenFunction::EmitOMPCollapsedCanonicalLoopNest()` to use `pop_back_n()` instead of `set_size()`. Differential Revision: https://reviews.llvm.org/D115378 Added: Modified: clang/lib/CodeGen/CGStmtOpenMP.cpp llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp Removed: diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index f6853a22cd361..6f0ef7bb7fe52 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -1972,7 +1972,7 @@ CodeGenFunction::EmitOMPCollapsedCanonicalLoopNest(const Stmt *S, int Depth) { // Pop the \p Depth loops requested by the call from that stack and restore // the previous context. - OMPLoopNestStack.set_size(OMPLoopNestStack.size() - Depth); + OMPLoopNestStack.pop_back_n(Depth); ExpectedOMPLoopDepth = ParentExpectedOMPLoopDepth; return Result; diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp index d5776964889b4..81f5ec54d1ce3 100644 --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -1831,7 +1831,7 @@ OpenMPIRBuilder::collapseLoops(DebugLoc DL, ArrayRef Loops, Value *Leftover = Result->getIndVar(); SmallVector NewIndVars; - NewIndVars.set_size(NumLoops); + NewIndVars.resize(NumLoops); for (int i = NumLoops - 1; i >= 1; --i) { Value *OrigTripCount = Loops[i]->getTripCount(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 46a68c8 - Sema: const-qualify ParsedAttr::iterator::operator*()
Author: Duncan P. N. Exon Smith Date: 2021-11-12T11:47:16-08:00 New Revision: 46a68c85bfc99f0bc651e5096a641d5d4051e99d URL: https://github.com/llvm/llvm-project/commit/46a68c85bfc99f0bc651e5096a641d5d4051e99d DIFF: https://github.com/llvm/llvm-project/commit/46a68c85bfc99f0bc651e5096a641d5d4051e99d.diff LOG: Sema: const-qualify ParsedAttr::iterator::operator*() `const`-qualify ParsedAttr::iterator::operator*(), clearing up confusion about the two meanings of const for pointers/iterators. Helps unblock removal of (non-const) iterator_facade_base::operator->(). Added: Modified: clang/include/clang/Sema/ParsedAttr.h Removed: diff --git a/clang/include/clang/Sema/ParsedAttr.h b/clang/include/clang/Sema/ParsedAttr.h index 52b2c0d963fce..ff2303c84bd21 100644 --- a/clang/include/clang/Sema/ParsedAttr.h +++ b/clang/include/clang/Sema/ParsedAttr.h @@ -894,7 +894,7 @@ class ParsedAttributesView { ParsedAttr> { iterator() : iterator_adaptor_base(nullptr) {} iterator(VecTy::iterator I) : iterator_adaptor_base(I) {} -reference operator*() { return **I; } +reference operator*() const { return **I; } friend class ParsedAttributesView; }; struct const_iterator ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 9091df5 - Fix a use-after-scope from 99023627010bbfefb71e25a2b4d056de1cbd354e
Author: Duncan P. N. Exon Smith Date: 2021-10-29T16:25:13-07:00 New Revision: 9091df5fad52ab6a281d7f4d6a508696e6f9fbae URL: https://github.com/llvm/llvm-project/commit/9091df5fad52ab6a281d7f4d6a508696e6f9fbae DIFF: https://github.com/llvm/llvm-project/commit/9091df5fad52ab6a281d7f4d6a508696e6f9fbae.diff LOG: Fix a use-after-scope from 99023627010bbfefb71e25a2b4d056de1cbd354e Added: Modified: clang/lib/Basic/FileManager.cpp Removed: diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 1cb52d5594d59..f4cf27848d7d9 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -123,14 +123,14 @@ FileManager::getDirectoryRef(StringRef DirName, bool CacheFailure) { DirName != llvm::sys::path::root_path(DirName) && llvm::sys::path::is_separator(DirName.back())) DirName = DirName.substr(0, DirName.size()-1); + Optional DirNameStr; if (is_style_windows(llvm::sys::path::Style::native)) { // Fixing a problem with "clang C:test.c" on Windows. // Stat("C:") does not recognize "C:" as a valid directory -std::string DirNameStr; if (DirName.size() > 1 && DirName.back() == ':' && DirName.equals_insensitive(llvm::sys::path::root_name(DirName))) { DirNameStr = DirName.str() + '.'; - DirName = DirNameStr; + DirName = *DirNameStr; } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D112289: Support: Use sys::path::is_style_{posix,windows}() in a few places
Looking now. > On 2021 Oct 29, at 16:07, Nico Weber via Phabricator > wrote: > > thakis added a comment. > > Looks like this breaks tests on windows: > http://45.33.8.238/win/47971/step_7.txt > > Please take a look and revert for now if it takes a while to fix. > > > Repository: > rG LLVM Github Monorepo > > CHANGES SINCE LAST ACTION > https://reviews.llvm.org/D112289/new/ > > https://reviews.llvm.org/D112289 > ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 9902362 - Support: Use sys::path::is_style_{posix, windows}() in a few places
Author: Duncan P. N. Exon Smith Date: 2021-10-29T12:09:41-07:00 New Revision: 99023627010bbfefb71e25a2b4d056de1cbd354e URL: https://github.com/llvm/llvm-project/commit/99023627010bbfefb71e25a2b4d056de1cbd354e DIFF: https://github.com/llvm/llvm-project/commit/99023627010bbfefb71e25a2b4d056de1cbd354e.diff LOG: Support: Use sys::path::is_style_{posix,windows}() in a few places Use the new sys::path::is_style_posix() and is_style_windows() in a few places that need to detect the system's native path style. In llvm/lib/Support/Path.cpp, this patch removes most uses of the private `real_style()`, where is_style_posix() and is_style_windows() are just a little tidier. Elsewhere, this removes `_WIN32` macro checks. Added a FIXME to a FileManagerTest that seemed fishy, but maintained the existing behaviour. Differential Revision: https://reviews.llvm.org/D112289 Added: Modified: clang/include/clang/Basic/JsonSupport.h clang/lib/Basic/FileManager.cpp clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChain.cpp clang/lib/Lex/PPDirectives.cpp clang/unittests/Basic/FileManagerTest.cpp clang/unittests/Driver/ToolChainTest.cpp clang/unittests/Lex/HeaderSearchTest.cpp clang/unittests/Tooling/RefactoringTest.cpp llvm/include/llvm/Support/VirtualFileSystem.h llvm/lib/Support/GraphWriter.cpp llvm/lib/Support/Path.cpp llvm/tools/lli/lli.cpp Removed: diff --git a/clang/include/clang/Basic/JsonSupport.h b/clang/include/clang/Basic/JsonSupport.h index 6cd3f4d57b846..2ccb08e4bdaa2 100644 --- a/clang/include/clang/Basic/JsonSupport.h +++ b/clang/include/clang/Basic/JsonSupport.h @@ -12,6 +12,7 @@ #include "clang/Basic/LLVM.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include @@ -98,18 +99,19 @@ inline void printSourceLocationAsJson(raw_ostream &Out, SourceLocation Loc, if (AddBraces) Out << "{ "; std::string filename(PLoc.getFilename()); -#ifdef _WIN32 -// Remove forbidden Windows path characters -auto RemoveIt = -std::remove_if(filename.begin(), filename.end(), [](auto Char) { - static const char ForbiddenChars[] = "<>*?\"|"; - return std::find(std::begin(ForbiddenChars), std::end(ForbiddenChars), - Char) != std::end(ForbiddenChars); -}); -filename.erase(RemoveIt, filename.end()); -// Handle windows-specific path delimiters. -std::replace(filename.begin(), filename.end(), '\\', '/'); -#endif +if (is_style_windows(llvm::sys::path::Style::native)) { + // Remove forbidden Windows path characters + auto RemoveIt = + std::remove_if(filename.begin(), filename.end(), [](auto Char) { +static const char ForbiddenChars[] = "<>*?\"|"; +return std::find(std::begin(ForbiddenChars), + std::end(ForbiddenChars), + Char) != std::end(ForbiddenChars); + }); + filename.erase(RemoveIt, filename.end()); + // Handle windows-specific path delimiters. + std::replace(filename.begin(), filename.end(), '\\', '/'); +} Out << "\"line\": " << PLoc.getLine() << ", \"column\": " << PLoc.getColumn() << ", \"file\": \"" << filename << "\""; diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index c4eae6acd7b04..1cb52d5594d59 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -123,16 +123,16 @@ FileManager::getDirectoryRef(StringRef DirName, bool CacheFailure) { DirName != llvm::sys::path::root_path(DirName) && llvm::sys::path::is_separator(DirName.back())) DirName = DirName.substr(0, DirName.size()-1); -#ifdef _WIN32 - // Fixing a problem with "clang C:test.c" on Windows. - // Stat("C:") does not recognize "C:" as a valid directory - std::string DirNameStr; - if (DirName.size() > 1 && DirName.back() == ':' && - DirName.equals_insensitive(llvm::sys::path::root_name(DirName))) { -DirNameStr = DirName.str() + '.'; -DirName = DirNameStr; + if (is_style_windows(llvm::sys::path::Style::native)) { +// Fixing a problem with "clang C:test.c" on Windows. +// Stat("C:") does not recognize "C:" as a valid directory +std::string DirNameStr; +if (DirName.size() > 1 && DirName.back() == ':' && +DirName.equals_insensitive(llvm::sys::path::root_name(DirName))) { + DirNameStr = DirName.str() + '.'; + DirName = DirNameStr; +} } -#endif ++NumDirLookups; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 5b64ca8657d0e..2ddb753660e40 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4899,11 +4899,11 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobActi
[clang] da47ec3 - Basic: Stop using expectedToOptional() in FileManagerTest, NFC
Author: Duncan P. N. Exon Smith Date: 2021-10-25T13:44:45-07:00 New Revision: da47ec3ca076477b994a5fdd7b777aed9b8cbdf4 URL: https://github.com/llvm/llvm-project/commit/da47ec3ca076477b994a5fdd7b777aed9b8cbdf4 DIFF: https://github.com/llvm/llvm-project/commit/da47ec3ca076477b994a5fdd7b777aed9b8cbdf4.diff LOG: Basic: Stop using expectedToOptional() in FileManagerTest, NFC Remove a couple of uses of expectedToOptional() in FileManagerTest, using Expected::moveInto() to extract the value instead instead. Added: Modified: clang/unittests/Basic/CMakeLists.txt clang/unittests/Basic/FileManagerTest.cpp Removed: diff --git a/clang/unittests/Basic/CMakeLists.txt b/clang/unittests/Basic/CMakeLists.txt index cbb18ca87a80c..e633040eac153 100644 --- a/clang/unittests/Basic/CMakeLists.txt +++ b/clang/unittests/Basic/CMakeLists.txt @@ -18,4 +18,5 @@ clang_target_link_libraries(BasicTests clangAST clangBasic clangLex + LLVMTestingSupport ) diff --git a/clang/unittests/Basic/FileManagerTest.cpp b/clang/unittests/Basic/FileManagerTest.cpp index b40ba01121f8f..a122747efdc11 100644 --- a/clang/unittests/Basic/FileManagerTest.cpp +++ b/clang/unittests/Basic/FileManagerTest.cpp @@ -12,6 +12,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Path.h" #include "llvm/Support/VirtualFileSystem.h" +#include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" using namespace llvm; @@ -559,9 +560,10 @@ TEST_F(FileManagerTest, getBypassFile) { // Calling a second time should not affect the UID or size. unsigned VirtualUID = FE.getUID(); - EXPECT_EQ( - &FE, - &expectedToOptional(Manager.getFileRef("/tmp/test"))->getFileEntry()); + llvm::Optional SearchRef; + ASSERT_THAT_ERROR(Manager.getFileRef("/tmp/test").moveInto(SearchRef), +Succeeded()); + EXPECT_EQ(&FE, &SearchRef->getFileEntry()); EXPECT_EQ(FE.getUID(), VirtualUID); EXPECT_EQ(FE.getSize(), 10); @@ -578,9 +580,9 @@ TEST_F(FileManagerTest, getBypassFile) { EXPECT_NE(BypassRef->getSize(), FE.getSize()); // The virtual file should still be returned when searching. - EXPECT_EQ( - &FE, - &expectedToOptional(Manager.getFileRef("/tmp/test"))->getFileEntry()); + ASSERT_THAT_ERROR(Manager.getFileRef("/tmp/test").moveInto(SearchRef), +Succeeded()); + EXPECT_EQ(&FE, &SearchRef->getFileEntry()); } } // anonymous namespace ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 2410fb4 - Support: Use Expected::moveInto() in a few places
Author: Duncan P. N. Exon Smith Date: 2021-10-22T12:40:10-07:00 New Revision: 2410fb4616b2c08bbaddd44e6c11da8285fbd1d3 URL: https://github.com/llvm/llvm-project/commit/2410fb4616b2c08bbaddd44e6c11da8285fbd1d3 DIFF: https://github.com/llvm/llvm-project/commit/2410fb4616b2c08bbaddd44e6c11da8285fbd1d3.diff LOG: Support: Use Expected::moveInto() in a few places These are some usage examples for `Expected::moveInto()`. Differential Revision: https://reviews.llvm.org/D112280 Added: Modified: clang/lib/CodeGen/BackendUtil.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/DebugInfo/Symbolize/Symbolize.cpp llvm/lib/Object/ObjectFile.cpp llvm/lib/XRay/InstrumentationMap.cpp Removed: diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index ff76ef1d9dd8..30f81b8ae473 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1657,16 +1657,17 @@ void clang::EmitBackendOutput(DiagnosticsEngine &Diags, // If we are performing a ThinLTO importing compile, load the function index // into memory and pass it into runThinLTOBackend, which will run the // function importer and invoke LTO passes. -Expected> IndexOrErr = -llvm::getModuleSummaryIndexForFile(CGOpts.ThinLTOIndexFile, - /*IgnoreEmptyThinLTOIndexFile*/true); -if (!IndexOrErr) { - logAllUnhandledErrors(IndexOrErr.takeError(), errs(), +std::unique_ptr CombinedIndex; +if (Error E = llvm::getModuleSummaryIndexForFile( + CGOpts.ThinLTOIndexFile, + /*IgnoreEmptyThinLTOIndexFile*/ true) + .moveInto(CombinedIndex)) { + logAllUnhandledErrors(std::move(E), errs(), "Error loading index file '" + CGOpts.ThinLTOIndexFile + "': "); return; } -std::unique_ptr CombinedIndex = std::move(*IndexOrErr); + // A null CombinedIndex means we should skip ThinLTO compilation // (LLVM will optionally ignore empty index files, returning null instead // of an error). diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 349d40e1a63c..301145939904 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -179,10 +179,8 @@ static Expected readIdentificationBlock(BitstreamCursor &Stream) { while (true) { BitstreamEntry Entry; -if (Expected Res = Stream.advance()) - Entry = Res.get(); -else - return Res.takeError(); +if (Error E = Stream.advance().moveInto(Entry)) + return std::move(E); switch (Entry.Kind) { default: @@ -226,10 +224,8 @@ static Expected readIdentificationCode(BitstreamCursor &Stream) { return ""; BitstreamEntry Entry; -if (Expected Res = Stream.advance()) - Entry = std::move(Res.get()); -else - return Res.takeError(); +if (Error E = Stream.advance().moveInto(Entry)) + return std::move(E); switch (Entry.Kind) { case BitstreamEntry::EndBlock: @@ -305,10 +301,8 @@ static Expected hasObjCCategory(BitstreamCursor &Stream) { // need to understand them all. while (true) { BitstreamEntry Entry; -if (Expected Res = Stream.advance()) - Entry = std::move(Res.get()); -else - return Res.takeError(); +if (Error E = Stream.advance().moveInto(Entry)) + return std::move(E); switch (Entry.Kind) { case BitstreamEntry::Error: diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp index 6da0b6907786..f3f09584fdc9 100644 --- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp +++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp @@ -280,10 +280,7 @@ bool getGNUDebuglinkContents(const ObjectFile *Obj, std::string &DebugName, return false; for (const SectionRef &Section : Obj->sections()) { StringRef Name; -if (Expected NameOrErr = Section.getName()) - Name = *NameOrErr; -else - consumeError(NameOrErr.takeError()); +consumeError(Section.getName().moveInto(Name)); Name = Name.substr(Name.find_first_not_of("._")); if (Name == "gnu_debuglink") { diff --git a/llvm/lib/Object/ObjectFile.cpp b/llvm/lib/Object/ObjectFile.cpp index 5c894439ff67..6fd02f3b9592 100644 --- a/llvm/lib/Object/ObjectFile.cpp +++ b/llvm/lib/Object/ObjectFile.cpp @@ -55,14 +55,15 @@ bool SectionRef::containsSymbol(SymbolRef S) const { } Expected ObjectFile::getSymbolValue(DataRefImpl Ref) const { - if (Expected FlagsOrErr = getSymbolFlags(Ref)) { -if (*FlagsOrErr & SymbolRef::SF_Undefined) - return 0; -if (*FlagsOrErr & SymbolRef::SF_Common) - return getCommonSymbolSize(Ref); - } else + uint32_t Flags; + if (Error E = getSymbolFlags(Ref).moveI
[clang] 8976a1e - VFS: Document goals of 'use-external-name' and related logic, NFC
Author: Duncan P. N. Exon Smith Date: 2021-09-01T15:55:33-04:00 New Revision: 8976a1e111393aab7b4965196364ad734a17f2d5 URL: https://github.com/llvm/llvm-project/commit/8976a1e111393aab7b4965196364ad734a17f2d5 DIFF: https://github.com/llvm/llvm-project/commit/8976a1e111393aab7b4965196364ad734a17f2d5.diff LOG: VFS: Document goals of 'use-external-name' and related logic, NFC Document 'use-external-name' and the various bits of logic that make it work, to avoid others having to repeat the archival work (given that I added getFileRefReturnsCorrectNameForDifferentStatPath to FileManagerTest, seems possible I understood this once before!). - b59cf679e81483cbb3a9252056b7528f4c49586c added 'use-external-name' to RedirectingFileSystem. This causes `stat`s to return the external name for a redirected file instead of the name it was accessed by, leaking it through the VFS. - d066d4c849be06a01c0d17e8dc206913f4e7bfe3 propagated the external name further through clang::FileManager. - 4dc5573acc0d2e7c59d8bac2543eb25cb4b32984, which added clang::FileEntryRef to clang::FileManager, has complicated concession to account for this as well (since refactored a bit). The goal of 'use-external-name' is to enable Clang to report "real" file paths to users (via diagnostics) and to external tools (such as debuggers reading debug info and build systems reading `.d` files). I've added FIXMEs to look at other channels for communicating the external names, since the current implementation adds complexity to FileManager and exposes an inconsistent interface to clients. Besides that, the FileManager logic appears to be kicking in outside of 'use-external-name'. Seems that *some* vfs::FileSystem implementations canonicalize some paths returned by `stat` in *some* cases (the bug isn't fully understood yet). Volodymyr Sapsai is investigating, this at least better documents what *is* understood. Added: Modified: clang/lib/Basic/FileManager.cpp clang/unittests/Basic/FileManagerTest.cpp llvm/include/llvm/Support/VirtualFileSystem.h Removed: diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 74cd2f295be60..c4eae6acd7b04 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -276,6 +276,18 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { } else { // Name mismatch. We need a redirect. First grab the actual entry we want // to return. +// +// This redirection logic intentionally leaks the external name of a +// redirected file that uses 'use-external-name' in \a +// vfs::RedirectionFileSystem. This allows clang to report the external +// name to users (in diagnostics) and to tools that don't have access to +// the VFS (in debug info and dependency '.d' files). +// +// FIXME: This is pretty complicated. It's also inconsistent with how +// "real" filesystems behave and confuses parts of clang expect to see the +// name-as-accessed on the \a FileEntryRef. Maybe the returned \a +// FileEntryRef::getName() could return the accessed name unmodified, but +// make the external name available via a separate API. auto &Redirection = *SeenFileEntries .insert({Status.getName(), FileEntryRef::MapValue(UFE, DirInfo)}) diff --git a/clang/unittests/Basic/FileManagerTest.cpp b/clang/unittests/Basic/FileManagerTest.cpp index 0a1f58f3bb90d..b40ba01121f8f 100644 --- a/clang/unittests/Basic/FileManagerTest.cpp +++ b/clang/unittests/Basic/FileManagerTest.cpp @@ -276,9 +276,9 @@ TEST_F(FileManagerTest, getFileReturnsSameFileEntryForAliasedRealFiles) { TEST_F(FileManagerTest, getFileRefReturnsCorrectNameForDifferentStatPath) { // Inject files with the same inode, but where some files have a stat that - // gives a diff erent name. This is adding coverage for weird stat behaviour - // triggered by the RedirectingFileSystem that FileManager::getFileRef has - // special logic for. + // gives a diff erent name. This is adding coverage for stat behaviour + // triggered by the RedirectingFileSystem for 'use-external-name' that + // FileManager::getFileRef has special logic for. auto StatCache = std::make_unique(); StatCache->InjectDirectory("dir", 40); StatCache->InjectFile("dir/f1.cpp", 41); diff --git a/llvm/include/llvm/Support/VirtualFileSystem.h b/llvm/include/llvm/Support/VirtualFileSystem.h index 323e6719645d9..e43da9c94f355 100644 --- a/llvm/include/llvm/Support/VirtualFileSystem.h +++ b/llvm/include/llvm/Support/VirtualFileSystem.h @@ -596,6 +596,17 @@ class RedirectingFileSystemParser; /// contain multiple path components (e.g. /path/to/file). However, any /// directory in such a path that contains more than one child must be uniquely /// represented by a 'directory' entry. +/// +/// When the 'use-external-name' field i
[clang] d8a08fa - Clean up test for -f{, no-}implicit-modules-uses-lock
Author: Duncan P. N. Exon Smith Date: 2021-08-16T16:23:04-07:00 New Revision: d8a08fae0af9aa09c108b3e7c60f192249dd2098 URL: https://github.com/llvm/llvm-project/commit/d8a08fae0af9aa09c108b3e7c60f192249dd2098 DIFF: https://github.com/llvm/llvm-project/commit/d8a08fae0af9aa09c108b3e7c60f192249dd2098.diff LOG: Clean up test for -f{,no-}implicit-modules-uses-lock @arichardson pointed out in post-commit review for https://reviews.llvm.org/D95583 (b714f73defc8e075) that `-verify` has an optional argument that works a lot like `FileCheck`'s `-check-prefix`. Use it to simplify the test for `-fno-implicit-modules-use-lock`! Added: Modified: clang/test/Modules/implicit-modules-use-lock.m Removed: diff --git a/clang/test/Modules/implicit-modules-use-lock.m b/clang/test/Modules/implicit-modules-use-lock.m index 811b83a7e4c76..6c9582df4de52 100644 --- a/clang/test/Modules/implicit-modules-use-lock.m +++ b/clang/test/Modules/implicit-modules-use-lock.m @@ -4,20 +4,20 @@ // // RUN: rm -rf %t.cache // RUN: %clang_cc1 -fmodules -fimplicit-module-maps \ -// RUN: -fimplicit-modules-use-lock -Rmodule-lock \ +// RUN: -fimplicit-modules-use-lock -Rmodule-lock -Rmodule-build \ // RUN: -fmodules-cache-path=%t.cache -I%S/Inputs/system-out-of-date \ // RUN: -fsyntax-only %s -Wnon-modular-include-in-framework-module \ -// RUN: -Werror=non-modular-include-in-framework-module 2>&1 \ -// RUN: | FileCheck %s -check-prefix=CHECK-LOCKS +// RUN: -Werror=non-modular-include-in-framework-module \ +// RUN: -verify=locks,build // // RUN: rm -rf %t.cache // RUN: %clang_cc1 -fmodules -fimplicit-module-maps \ -// RUN: -fno-implicit-modules-use-lock -Rmodule-lock \ +// RUN: -fno-implicit-modules-use-lock -Rmodule-lock -Rmodule-build \ // RUN: -fmodules-cache-path=%t.cache -I%S/Inputs/system-out-of-date \ // RUN: -fsyntax-only %s -Wnon-modular-include-in-framework-module \ -// RUN: -Werror=non-modular-include-in-framework-module 2>&1 \ -// RUN: | FileCheck %s -check-prefix=CHECK-NO-LOCKS -allow-empty +// RUN: -Werror=non-modular-include-in-framework-module \ +// RUN: -verify=build -// CHECK-NO-LOCKS-NOT: remark: -// CHECK-LOCKS: remark: locking '{{.*}}.pcm' to build module 'X' [-Rmodule-lock] -@import X; +@import X; // locks-remark-re {{locking '{{.*}}.pcm' to build module 'X'}} \ + // build-remark {{building module 'X'}} \ + // build-remark {{finished building module 'X'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] b714f73 - Frontend: Add -f{,no-}implicit-modules-uses-lock and -Rmodule-lock
Author: Duncan P. N. Exon Smith Date: 2021-08-12T15:58:19-07:00 New Revision: b714f73defc8e0755c7c7cf043df1f1c21344839 URL: https://github.com/llvm/llvm-project/commit/b714f73defc8e0755c7c7cf043df1f1c21344839 DIFF: https://github.com/llvm/llvm-project/commit/b714f73defc8e0755c7c7cf043df1f1c21344839.diff LOG: Frontend: Add -f{,no-}implicit-modules-uses-lock and -Rmodule-lock Add -cc1 flags `-fmodules-uses-lock` and `-fno-modules-uses-lock` to allow the lock manager to be turned off when building implicit modules. Add `-Rmodule-lock` so that we can see when it's being used. Differential Revision: https://reviews.llvm.org/D95583 Added: clang/test/Modules/implicit-modules-use-lock.m Modified: clang/include/clang/Basic/DiagnosticFrontendKinds.td clang/include/clang/Basic/DiagnosticGroups.td clang/include/clang/Driver/Options.td clang/include/clang/Frontend/FrontendOptions.h clang/lib/Frontend/CompilerInstance.cpp Removed: diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 0f4ccec385506..4bc5097762186 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -229,6 +229,8 @@ def remark_module_build : Remark<"building module '%0' as '%1'">, InGroup; def remark_module_build_done : Remark<"finished building module '%0'">, InGroup; +def remark_module_lock : Remark<"locking '%0' to build module '%1'">, + InGroup; def err_modules_embed_file_not_found : Error<"file '%0' specified by '-fmodules-embed-file=' not found">, DefaultFatal; diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 1555a9ee24650..4a67dffb2f7d4 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -465,6 +465,7 @@ def MismatchedParameterTypes : DiagGroup<"mismatched-parameter-types">; def MismatchedReturnTypes : DiagGroup<"mismatched-return-types">; def MismatchedTags : DiagGroup<"mismatched-tags">; def MissingFieldInitializers : DiagGroup<"missing-field-initializers">; +def ModuleLock : DiagGroup<"module-lock">; def ModuleBuild : DiagGroup<"module-build">; def ModuleImport : DiagGroup<"module-import">; def ModuleConflict : DiagGroup<"module-conflict">; diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index a91114f76ff07..5d43660ca7dec 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5301,6 +5301,12 @@ def fmodules_embed_all_files : Joined<["-"], "fmodules-embed-all-files">, HelpText<"Embed the contents of all files read by this compilation into " "the produced module file.">, MarshallingInfoFlag>; +defm fimplicit_modules_use_lock : BoolOption<"f", "implicit-modules-use-lock", + FrontendOpts<"BuildingImplicitModuleUsesLock">, DefaultTrue, + NegFlag, + PosFlag>; // FIXME: We only need this in C++ modules / Modules TS if we might textually // enter a diff erent module (eg, when building a header unit). def fmodules_local_submodule_visibility : diff --git a/clang/include/clang/Frontend/FrontendOptions.h b/clang/include/clang/Frontend/FrontendOptions.h index 15c905d712a37..41ea45ca0b103 100644 --- a/clang/include/clang/Frontend/FrontendOptions.h +++ b/clang/include/clang/Frontend/FrontendOptions.h @@ -289,6 +289,9 @@ class FrontendOptions { /// Whether we are performing an implicit module build. unsigned BuildingImplicitModule : 1; + /// Whether to use a filesystem lock when building implicit modules. + unsigned BuildingImplicitModuleUsesLock : 1; + /// Whether we should embed all used files into the PCM file. unsigned ModulesEmbedAllFiles : 1; @@ -461,9 +464,9 @@ class FrontendOptions { SkipFunctionBodies(false), UseGlobalModuleIndex(true), GenerateGlobalModuleIndex(true), ASTDumpDecls(false), ASTDumpLookups(false), BuildingImplicitModule(false), -ModulesEmbedAllFiles(false), IncludeTimestamps(true), -UseTemporary(true), AllowPCMWithCompilerErrors(false), -TimeTraceGranularity(500) {} +BuildingImplicitModuleUsesLock(true), ModulesEmbedAllFiles(false), +IncludeTimestamps(true), UseTemporary(true), +AllowPCMWithCompilerErrors(false), TimeTraceGranularity(500) {} /// getInputKindForExtension - Return the appropriate input kind for a file /// extension. For example, "c" would return Language::C. diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index d90b292808f21..0f9bd70efc73e 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1331,6 +1331,9 @@ static bool compileModuleAndReadASTBehindLock( SourceLocation ModuleNameLoc,
[clang] c130300 - Frontend: Refactor compileModuleAndReadAST, NFC
Author: Duncan P. N. Exon Smith Date: 2021-08-12T15:16:08-07:00 New Revision: c130300f8ba0363749cf2490bbd43515fad8a759 URL: https://github.com/llvm/llvm-project/commit/c130300f8ba0363749cf2490bbd43515fad8a759 DIFF: https://github.com/llvm/llvm-project/commit/c130300f8ba0363749cf2490bbd43515fad8a759.diff LOG: Frontend: Refactor compileModuleAndReadAST, NFC This renames `compileModuleAndReadAST`, adding a `BehindLock` suffix, and refactors it to significantly reduce nesting. - Split out helpers `compileModuleAndReadASTImpl` and `readASTAfterCompileModule` which have straight-line code that doesn't worry about locks. - Use `break` in the interesting cases of `switch` statements to reduce nesting. - Use early `return`s to reduce nesting. Detangling the compile-and-read logic from the check-for-locks logic should be a net win for readability, although I also have a side motivation of making the locks optional in a follow-up. No functionality change here. Differential Revision: https://reviews.llvm.org/D95581 Added: Modified: clang/lib/Frontend/CompilerInstance.cpp Removed: diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index c642af1849bc4..d90b292808f21 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1264,31 +1264,79 @@ static bool compileModule(CompilerInstance &ImportingInstance, return Result; } +/// Read the AST right after compiling the module. +static bool readASTAfterCompileModule(CompilerInstance &ImportingInstance, + SourceLocation ImportLoc, + SourceLocation ModuleNameLoc, + Module *Module, StringRef ModuleFileName, + bool *OutOfDate) { + DiagnosticsEngine &Diags = ImportingInstance.getDiagnostics(); + + unsigned ModuleLoadCapabilities = ASTReader::ARR_Missing; + if (OutOfDate) +ModuleLoadCapabilities |= ASTReader::ARR_OutOfDate; + + // Try to read the module file, now that we've compiled it. + ASTReader::ASTReadResult ReadResult = + ImportingInstance.getASTReader()->ReadAST( + ModuleFileName, serialization::MK_ImplicitModule, ImportLoc, + ModuleLoadCapabilities); + if (ReadResult == ASTReader::Success) +return true; + + // The caller wants to handle out-of-date failures. + if (OutOfDate && ReadResult == ASTReader::OutOfDate) { +*OutOfDate = true; +return false; + } + + // The ASTReader didn't diagnose the error, so conservatively report it. + if (ReadResult == ASTReader::Missing || !Diags.hasErrorOccurred()) +Diags.Report(ModuleNameLoc, diag::err_module_not_built) + << Module->Name << SourceRange(ImportLoc, ModuleNameLoc); + + return false; +} + /// Compile a module in a separate compiler instance and read the AST, /// returning true if the module compiles without errors. +static bool compileModuleAndReadASTImpl(CompilerInstance &ImportingInstance, +SourceLocation ImportLoc, +SourceLocation ModuleNameLoc, +Module *Module, +StringRef ModuleFileName) { + if (!compileModule(ImportingInstance, ModuleNameLoc, Module, + ModuleFileName)) { +ImportingInstance.getDiagnostics().Report(ModuleNameLoc, + diag::err_module_not_built) +<< Module->Name << SourceRange(ImportLoc, ModuleNameLoc); +return false; + } + + return readASTAfterCompileModule(ImportingInstance, ImportLoc, ModuleNameLoc, + Module, ModuleFileName, + /*OutOfDate=*/nullptr); +} + +/// Compile a module in a separate compiler instance and read the AST, +/// returning true if the module compiles without errors, using a lock manager +/// to avoid building the same module in multiple compiler instances. /// /// Uses a lock file manager and exponential backoff to reduce the chances that /// multiple instances will compete to create the same module. On timeout, /// deletes the lock file in order to avoid deadlock from crashing processes or /// bugs in the lock file manager. -static bool compileModuleAndReadAST(CompilerInstance &ImportingInstance, -SourceLocation ImportLoc, -SourceLocation ModuleNameLoc, -Module *Module, StringRef ModuleFileName) { +static bool compileModuleAndReadASTBehindLock( +CompilerInstance &ImportingInstance, SourceLocation ImportLoc, +SourceLocation ModuleNameLoc, Module *Module, StringRef ModuleFileName) { DiagnosticsEngine &Diags = ImportingInstance.getDiagnostics();
[clang] 05d0f1a - Frontend: Respect -fno-temp-file when creating a PCH
Author: Zachary Henkel Date: 2021-06-17T18:34:10-07:00 New Revision: 05d0f1a8ea012a6b7b8ea65893ec4121106444b5 URL: https://github.com/llvm/llvm-project/commit/05d0f1a8ea012a6b7b8ea65893ec4121106444b5 DIFF: https://github.com/llvm/llvm-project/commit/05d0f1a8ea012a6b7b8ea65893ec4121106444b5.diff LOG: Frontend: Respect -fno-temp-file when creating a PCH When creating a PCH file the use of a temp file will be dictated by the presence or absence of the -fno-temp-file flag. Creating a module file will always use a temp file via the new ForceUseTemporary flag. This fixes bug 50033. Added: Modified: clang/include/clang/Frontend/CompilerInstance.h clang/lib/Frontend/CompilerInstance.cpp clang/lib/Frontend/FrontendActions.cpp Removed: diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index 9d6dd8fa1006f..861b15020329b 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -696,15 +696,13 @@ class CompilerInstance : public ModuleLoader { /// The files created by this are usually removed on signal, and, depending /// on FrontendOptions, may also use a temporary file (that is, the data is /// written to a temporary file which will atomically replace the target - /// output on success). If a client (like libclang) needs to disable - /// RemoveFileOnSignal, temporary files will be forced on. + /// output on success). /// /// \return - Null on error. - std::unique_ptr - createDefaultOutputFile(bool Binary = true, StringRef BaseInput = "", - StringRef Extension = "", - bool RemoveFileOnSignal = true, - bool CreateMissingDirectories = false); + std::unique_ptr createDefaultOutputFile( + bool Binary = true, StringRef BaseInput = "", StringRef Extension = "", + bool RemoveFileOnSignal = true, bool CreateMissingDirectories = false, + bool ForceUseTemporary = false); /// Create a new output file, optionally deriving the output path name, and /// add it to the list of tracked output files. diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 78c7d84bbef45..063384130f730 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -743,11 +743,9 @@ void CompilerInstance::clearOutputFiles(bool EraseFiles) { } } -std::unique_ptr -CompilerInstance::createDefaultOutputFile(bool Binary, StringRef InFile, - StringRef Extension, - bool RemoveFileOnSignal, - bool CreateMissingDirectories) { +std::unique_ptr CompilerInstance::createDefaultOutputFile( +bool Binary, StringRef InFile, StringRef Extension, bool RemoveFileOnSignal, +bool CreateMissingDirectories, bool ForceUseTemporary) { StringRef OutputPath = getFrontendOpts().OutputFile; Optional> PathStorage; if (OutputPath.empty()) { @@ -760,9 +758,8 @@ CompilerInstance::createDefaultOutputFile(bool Binary, StringRef InFile, } } - // Force a temporary file if RemoveFileOnSignal was disabled. return createOutputFile(OutputPath, Binary, RemoveFileOnSignal, - getFrontendOpts().UseTemporary || !RemoveFileOnSignal, + getFrontendOpts().UseTemporary || ForceUseTemporary, CreateMissingDirectories); } diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 6df57cbb45ae0..c6ebbdc8c04e1 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -239,7 +239,8 @@ GenerateModuleFromModuleMapAction::CreateOutputFile(CompilerInstance &CI, // Because this is exposed via libclang we must disable RemoveFileOnSignal. return CI.createDefaultOutputFile(/*Binary=*/true, InFile, /*Extension=*/"", /*RemoveFileOnSignal=*/false, -/*CreateMissingDirectories=*/true); +/*CreateMissingDirectories=*/true, +/*ForceUseTemporary=*/true); } bool GenerateModuleInterfaceAction::BeginSourceFileAction( ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 7c57a9b - Modules: Simplify how DisableGeneratingGlobalModuleIndex is set, likely NFC
Author: Duncan P. N. Exon Smith Date: 2021-05-13T10:39:40-07:00 New Revision: 7c57a9bd7d4c976b7a824472c427433359200e02 URL: https://github.com/llvm/llvm-project/commit/7c57a9bd7d4c976b7a824472c427433359200e02 DIFF: https://github.com/llvm/llvm-project/commit/7c57a9bd7d4c976b7a824472c427433359200e02.diff LOG: Modules: Simplify how DisableGeneratingGlobalModuleIndex is set, likely NFC DisableGeneratingGlobalModuleIndex was being set by CompilerInstance::findOrCompileModuleAndReadAST most of (but not all of) the times it returned `nullptr` as a "normal" failure. Pull that up to the caller, CompilerInstance::loadModule, to simplify the code. This resolves a number of FIXMEs added during the refactoring in 5cca622310c10fdf6f921b6cce26f91d9f14c762. The extra cases where this is set are all some version of a fatal error, and the only client of the field, shouldBuildGlobalModuleIndex, seems to be unreachable in that case. Even if there is some corner case where this has an effect, it seems like the right/consistent behaviour. Differential Revision: https://reviews.llvm.org/D101672 Added: Modified: clang/lib/Frontend/CompilerInstance.cpp Removed: diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 54917b3fb0fb..a623580bac7f 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1683,7 +1683,6 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( // We can't find a module, error out here. getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_found) << ModuleName << SourceRange(ImportLoc, ModuleNameLoc); -DisableGeneratingGlobalModuleIndex = true; return nullptr; } if (ModuleFilename.empty()) { @@ -1695,7 +1694,6 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( getDiagnostics().Report(ModuleNameLoc, diag::err_module_build_disabled) << ModuleName; -DisableGeneratingGlobalModuleIndex = true; return nullptr; } @@ -1742,7 +1740,6 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( if (*ModuleFile == M->getASTFile()) return M; -DisableGeneratingGlobalModuleIndex = true; getDiagnostics().Report(ModuleNameLoc, diag::err_module_prebuilt) << ModuleName; return ModuleLoadResult(); @@ -1764,14 +1761,12 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( LLVM_FALLTHROUGH; case ASTReader::VersionMismatch: case ASTReader::HadErrors: -// FIXME: Should this set DisableGeneratingGlobalModuleIndex = true? ModuleLoader::HadFatalFailure = true; // FIXME: The ASTReader will already have complained, but can we shoehorn // that diagnostic information into a more useful form? return ModuleLoadResult(); case ASTReader::Failure: -// FIXME: Should this set DisableGeneratingGlobalModuleIndex = true? ModuleLoader::HadFatalFailure = true; return ModuleLoadResult(); } @@ -1781,7 +1776,6 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( // We don't know the desired configuration for this module and don't // necessarily even have a module map. Since ReadAST already produces // diagnostics for these two cases, we simply error out here. -DisableGeneratingGlobalModuleIndex = true; return ModuleLoadResult(); } @@ -1806,7 +1800,6 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( getDiagnostics().Report(ModuleNameLoc, diag::err_module_cycle) << ModuleName << CyclePath; -// FIXME: Should this set DisableGeneratingGlobalModuleIndex = true? return nullptr; } @@ -1816,7 +1809,6 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( getPreprocessorOpts().FailedModules->hasAlreadyFailed(ModuleName)) { getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_built) << ModuleName << SourceRange(ImportLoc, ModuleNameLoc); -DisableGeneratingGlobalModuleIndex = true; return nullptr; } @@ -1827,7 +1819,6 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( "undiagnosed error in compileModuleAndReadAST"); if (getPreprocessorOpts().FailedModules) getPreprocessorOpts().FailedModules->addFailed(ModuleName); -DisableGeneratingGlobalModuleIndex = true; return nullptr; } @@ -1878,11 +1869,10 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, } else { ModuleLoadResult Result = findOrCompileModuleAndReadAST( ModuleName, ImportLoc, ModuleNameLoc, IsInclusionDirective); -// FIXME: Can we pull 'DisableGeneratingGlobalModuleIndex = true' out of -// the return sequences for findOrCompileModuleAndReadAST and do it here -// (as long as the result is not a config mismatch)? See FIXMEs there. i
[clang] 23e9146 - Modules: Rename ModuleBuildFailed => DisableGeneratingGlobalModuleIndex, NFC
Author: Duncan P. N. Exon Smith Date: 2021-05-13T10:22:40-07:00 New Revision: 23e9146fba298d38142337b615e17067fb8ccb91 URL: https://github.com/llvm/llvm-project/commit/23e9146fba298d38142337b615e17067fb8ccb91 DIFF: https://github.com/llvm/llvm-project/commit/23e9146fba298d38142337b615e17067fb8ccb91.diff LOG: Modules: Rename ModuleBuildFailed => DisableGeneratingGlobalModuleIndex, NFC Rename CompilerInstance's ModuleBuildFailed field to DisableGeneratingGlobalModuleIndex, which more precisely describes its role. Otherwise, it's hard to suss out how it's different from ModuleLoader::HadFatalFailure, and what sort of code simplifications are safe. Differential Revision: https://reviews.llvm.org/D101670 Added: Modified: clang/include/clang/Frontend/CompilerInstance.h clang/lib/Frontend/CompilerInstance.cpp Removed: diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index 54d57019fa548..7778924fc452f 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -150,7 +150,7 @@ class CompilerInstance : public ModuleLoader { bool HaveFullGlobalModuleIndex = false; /// One or more modules failed to build. - bool ModuleBuildFailed = false; + bool DisableGeneratingGlobalModuleIndex = false; /// The stream for verbose output if owned, otherwise nullptr. std::unique_ptr OwnedVerboseOutputStream; diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 695c7e335fb40..54917b3fb0fbe 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -77,7 +77,7 @@ bool CompilerInstance::shouldBuildGlobalModuleIndex() const { return (BuildGlobalModuleIndex || (TheASTReader && TheASTReader->isGlobalIndexUnavailable() && getFrontendOpts().GenerateGlobalModuleIndex)) && - !ModuleBuildFailed; + !DisableGeneratingGlobalModuleIndex; } void CompilerInstance::setDiagnostics(DiagnosticsEngine *Value) { @@ -1683,7 +1683,7 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( // We can't find a module, error out here. getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_found) << ModuleName << SourceRange(ImportLoc, ModuleNameLoc); -ModuleBuildFailed = true; +DisableGeneratingGlobalModuleIndex = true; return nullptr; } if (ModuleFilename.empty()) { @@ -1695,7 +1695,7 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( getDiagnostics().Report(ModuleNameLoc, diag::err_module_build_disabled) << ModuleName; -ModuleBuildFailed = true; +DisableGeneratingGlobalModuleIndex = true; return nullptr; } @@ -1742,7 +1742,7 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( if (*ModuleFile == M->getASTFile()) return M; -ModuleBuildFailed = true; +DisableGeneratingGlobalModuleIndex = true; getDiagnostics().Report(ModuleNameLoc, diag::err_module_prebuilt) << ModuleName; return ModuleLoadResult(); @@ -1764,14 +1764,14 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( LLVM_FALLTHROUGH; case ASTReader::VersionMismatch: case ASTReader::HadErrors: -// FIXME: Should this set ModuleBuildFailed = true? +// FIXME: Should this set DisableGeneratingGlobalModuleIndex = true? ModuleLoader::HadFatalFailure = true; // FIXME: The ASTReader will already have complained, but can we shoehorn // that diagnostic information into a more useful form? return ModuleLoadResult(); case ASTReader::Failure: -// FIXME: Should this set ModuleBuildFailed = true? +// FIXME: Should this set DisableGeneratingGlobalModuleIndex = true? ModuleLoader::HadFatalFailure = true; return ModuleLoadResult(); } @@ -1781,7 +1781,7 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( // We don't know the desired configuration for this module and don't // necessarily even have a module map. Since ReadAST already produces // diagnostics for these two cases, we simply error out here. -ModuleBuildFailed = true; +DisableGeneratingGlobalModuleIndex = true; return ModuleLoadResult(); } @@ -1806,7 +1806,7 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( getDiagnostics().Report(ModuleNameLoc, diag::err_module_cycle) << ModuleName << CyclePath; -// FIXME: Should this set ModuleBuildFailed = true? +// FIXME: Should this set DisableGeneratingGlobalModuleIndex = true? return nullptr; } @@ -1816,7 +1816,7 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( getPreprocessorOpts().FailedModules->hasAlreadyFailed(ModuleName)) { getDiagnostics().Repor
[clang] 7c2afd5 - Modules: Remove ModuleLoader::OtherUncachedFailure, NFC
Author: Duncan P. N. Exon Smith Date: 2021-05-13T10:10:46-07:00 New Revision: 7c2afd5899df876eaf5ffb485194dc58e92daf89 URL: https://github.com/llvm/llvm-project/commit/7c2afd5899df876eaf5ffb485194dc58e92daf89 DIFF: https://github.com/llvm/llvm-project/commit/7c2afd5899df876eaf5ffb485194dc58e92daf89.diff LOG: Modules: Remove ModuleLoader::OtherUncachedFailure, NFC 5cca622310c10fdf6f921b6cce26f91d9f14c762 refactored CompilerInstance::loadModule, splitting out findOrCompileModuleAndReadAST, but was careful to avoid making any functional changes. It added ModuleLoader::OtherUncachedFailure to facilitate this and left behind FIXMEs asking why certain failures weren't cached. After a closer look, I think we can just remove this and simplify the code. This changes the behaviour of the following (simplified) code from CompilerInstance::loadModule, causing a failure to be cached more often: ``` if (auto MaybeModule = MM.getCachedModuleLoad(*Path[0].first)) return *MaybeModule; if (ModuleName == getLangOpts().CurrentModule) return MM.cacheModuleLoad(PP.lookupModule(...)); ModuleLoadResult Result = findOrCompileModuleAndReadAST(...); if (Result.isNormal()) // This will be 'true' more often. return MM.cacheModuleLoad(..., Module); return Result; ``` `MM` here is a ModuleMap owned by the Preprocessor. Here are the cases where `findOrCompileModuleAndReadAST` starts returning a "normal" failed result: - Emitted `diag::err_module_not_found`, where there's no module map found. - Emitted `diag::err_module_build_disabled`, where implicitly building modules is disabled. - Emitted `diag::err_module_cycle`, which detects module cycles in the implicit modules build system. - Emitted `diag::err_module_not_built`, which avoids building a module in this CompilerInstance if another one tried and failed already. - `compileModuleAndReadAST()` was called and failed to build. The four errors are all fatal, and last item also reports a fatal error, so it this extra caching has no functionality change... but even if it did, it seems fine to cache these failed results within a ModuleMap instance (note that each CompilerInstance has its own Preprocessor and ModuleMap). Differential Revision: https://reviews.llvm.org/D101667 Added: Modified: clang/include/clang/Lex/ModuleLoader.h clang/lib/Frontend/CompilerInstance.cpp Removed: diff --git a/clang/include/clang/Lex/ModuleLoader.h b/clang/include/clang/Lex/ModuleLoader.h index c1f7f068c0f1d..bf044e0e5f506 100644 --- a/clang/include/clang/Lex/ModuleLoader.h +++ b/clang/include/clang/Lex/ModuleLoader.h @@ -45,9 +45,6 @@ class ModuleLoadResult { // The module exists but cannot be imported due to a configuration mismatch. ConfigMismatch, - -// We failed to load the module, but we shouldn't cache the failure. -OtherUncachedFailure, }; llvm::PointerIntPair Storage; diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index bcf9f9694f885..695c7e335fb40 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1684,8 +1684,7 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_found) << ModuleName << SourceRange(ImportLoc, ModuleNameLoc); ModuleBuildFailed = true; -// FIXME: Why is this not cached? -return ModuleLoadResult::OtherUncachedFailure; +return nullptr; } if (ModuleFilename.empty()) { if (M && M->HasIncompatibleModuleFile) { @@ -1697,8 +1696,7 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( getDiagnostics().Report(ModuleNameLoc, diag::err_module_build_disabled) << ModuleName; ModuleBuildFailed = true; -// FIXME: Why is this not cached? -return ModuleLoadResult::OtherUncachedFailure; +return nullptr; } // Create an ASTReader on demand. @@ -1809,8 +1807,7 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( getDiagnostics().Report(ModuleNameLoc, diag::err_module_cycle) << ModuleName << CyclePath; // FIXME: Should this set ModuleBuildFailed = true? -// FIXME: Why is this not cached? -return ModuleLoadResult::OtherUncachedFailure; +return nullptr; } // Check whether we have already attempted to build this module (but @@ -1820,8 +1817,7 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_built) << ModuleName << SourceRange(ImportLoc, ModuleNameLoc); ModuleBuildFailed = true; -// FIXME: Why is this not cached? -return ModuleLoadResult::OtherUncachedFailure; +return nullptr; } // Try to compile and then read the AST. @@ -1832,8 +1828,7 @@ ModuleLoadResult CompilerInstance::findOrCompileMo
[clang] 64a390c - Modules: Remove an extra early return, NFC
Author: Duncan P. N. Exon Smith Date: 2021-05-03T10:50:09-07:00 New Revision: 64a390c1bc75eb55eeed3061df15dc581fd563e6 URL: https://github.com/llvm/llvm-project/commit/64a390c1bc75eb55eeed3061df15dc581fd563e6 DIFF: https://github.com/llvm/llvm-project/commit/64a390c1bc75eb55eeed3061df15dc581fd563e6.diff LOG: Modules: Remove an extra early return, NFC Remove an early return from an `else` block that's immediately followed by an equivalent early return after the `else` block. Differential Revision: https://reviews.llvm.org/D101671 Added: Modified: clang/lib/Frontend/CompilerInstance.cpp Removed: diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 4a765b9203cc7..bcf9f9694f885 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1890,8 +1890,6 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, return Result; Module = Result; MM.cacheModuleLoad(*Path[0].first, Module); -if (!Module) - return Module; } // If we never found the module, fail. Otherwise, verify the module and link ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] d4ee603 - Coverage: Document how to collect a profile without a filesystem
Author: Duncan P. N. Exon Smith Date: 2021-04-22T11:29:39-07:00 New Revision: d4ee603c8f21b4ae722c2a34d4dfa54b7abeeb16 URL: https://github.com/llvm/llvm-project/commit/d4ee603c8f21b4ae722c2a34d4dfa54b7abeeb16 DIFF: https://github.com/llvm/llvm-project/commit/d4ee603c8f21b4ae722c2a34d4dfa54b7abeeb16.diff LOG: Coverage: Document how to collect a profile without a filesystem The profiling runtime was designed to work without static initializers or a a filesystem (see 117cf2bd1ff585f9754b5f30f5a4cfd65b230bbf and others). The no-static-initializers part was already documented but this part got missed before. Differential Revision: https://reviews.llvm.org/D101000 Added: Modified: clang/docs/SourceBasedCodeCoverage.rst Removed: diff --git a/clang/docs/SourceBasedCodeCoverage.rst b/clang/docs/SourceBasedCodeCoverage.rst index a54bba94eb98..5f4bcf8e0ff0 100644 --- a/clang/docs/SourceBasedCodeCoverage.rst +++ b/clang/docs/SourceBasedCodeCoverage.rst @@ -346,6 +346,34 @@ without using static initializers, do this manually: In C++ files, declare these as ``extern "C"``. +Using the profiling runtime without a filesystem + + +The profiling runtime also supports freestanding environments that lack a +filesystem. The runtime ships as a static archive that's structured to make +dependencies on a hosted environment optional, depending on what features +the client application uses. + +The first step is to export ``__llvm_profile_runtime``, as above, to disable +the default static initializers. Instead of calling the ``*_file()`` APIs +described above, use the following to save the profile directly to a buffer +under your control: + +* Forward-declare ``uint64_t __llvm_profile_get_size_for_buffer(void)`` and + call it to determine the size of the profile. You'll need to allocate a + buffer of this size. + +* Forward-declare ``int __llvm_profile_write_buffer(char *Buffer)`` and call it + to copy the current counters to ``Buffer``, which is expected to already be + allocated and big enough for the profile. + +* Optionally, forward-declare ``void __llvm_profile_reset_counters(void)`` and + call it to reset the counters before entering a specific section to be + profiled. This is only useful if there is some setup that should be excluded + from the profile. + +In C++ files, declare these as ``extern "C"``. + Collecting coverage reports for the llvm project ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 64d8c78 - Revert "Module: Use FileEntryRef and DirectoryEntryRef in Umbrella, Header, and DirectoryName, NFC"
Author: Duncan P. N. Exon Smith Date: 2021-02-23T09:57:28-08:00 New Revision: 64d8c7818db2bd428d4e2a9f27661ee49225477f URL: https://github.com/llvm/llvm-project/commit/64d8c7818db2bd428d4e2a9f27661ee49225477f DIFF: https://github.com/llvm/llvm-project/commit/64d8c7818db2bd428d4e2a9f27661ee49225477f.diff LOG: Revert "Module: Use FileEntryRef and DirectoryEntryRef in Umbrella, Header, and DirectoryName, NFC" This (mostly) reverts 32c501dd88b62787d3a5ffda7aabcf4650dbe3cd. Hit a case where this causes a behaviour change, perhaps the same root cause that triggered the revert of a40db5502b2515a6f2f1676b5d7a655ae0f41179 in 7799ef7121aa7d59f4bd95cdf70035de724ead6f. (The API changes in DirectoryEntry.h have NOT been reverted as a number of subsequent commits depend on those.) https://reviews.llvm.org/D90497#2582166 Added: Modified: clang/include/clang/Basic/Module.h clang/include/clang/Lex/ModuleMap.h clang/lib/Basic/Module.cpp clang/lib/Frontend/FrontendActions.cpp clang/lib/Lex/ModuleMap.cpp clang/lib/Serialization/ASTReader.cpp Removed: diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h index f5b176f8d20b..82ea1f462949 100644 --- a/clang/include/clang/Basic/Module.h +++ b/clang/include/clang/Basic/Module.h @@ -133,9 +133,7 @@ class Module { std::string PresumedModuleMapFile; /// The umbrella header or directory. - llvm::PointerUnion - Umbrella; + llvm::PointerUnion Umbrella; /// The module signature. ASTFileSignature Signature; @@ -190,18 +188,18 @@ class Module { /// file. struct Header { std::string NameAsWritten; -OptionalFileEntryRefDegradesToFileEntryPtr Entry; +const FileEntry *Entry; -explicit operator bool() { return Entry != None; } +explicit operator bool() { return Entry; } }; /// Information about a directory name as found in the module map /// file. struct DirectoryName { std::string NameAsWritten; -OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr Entry; +const DirectoryEntry *Entry; -explicit operator bool() { return Entry != None; } +explicit operator bool() { return Entry; } }; /// The headers that are part of this module. @@ -546,15 +544,15 @@ class Module { /// Retrieve the header that serves as the umbrella header for this /// module. Header getUmbrellaHeader() const { -if (auto *ME = Umbrella.dyn_cast()) - return Header{UmbrellaAsWritten, FileEntryRef(*ME)}; +if (auto *FE = Umbrella.dyn_cast()) + return Header{UmbrellaAsWritten, FE}; return Header{}; } /// Determine whether this module has an umbrella directory that is /// not based on an umbrella header. bool hasUmbrellaDir() const { -return Umbrella && Umbrella.is(); +return Umbrella && Umbrella.is(); } /// Add a top-level header associated with this module. diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h index 6827408f10a3..f6423e5b4258 100644 --- a/clang/include/clang/Lex/ModuleMap.h +++ b/clang/include/clang/Lex/ModuleMap.h @@ -14,7 +14,6 @@ #ifndef LLVM_CLANG_LEX_MODULEMAP_H #define LLVM_CLANG_LEX_MODULEMAP_H -#include "clang/Basic/FileEntry.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/Module.h" @@ -38,6 +37,7 @@ namespace clang { class DiagnosticsEngine; class DirectoryEntry; +class FileEntry; class FileManager; class HeaderSearch; class SourceManager; @@ -648,12 +648,12 @@ class ModuleMap { /// Sets the umbrella header of the given module to the given /// header. - void setUmbrellaHeader(Module *Mod, FileEntryRef UmbrellaHeader, + void setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader, Twine NameAsWritten); /// Sets the umbrella directory of the given module to the given /// directory. - void setUmbrellaDir(Module *Mod, DirectoryEntryRef UmbrellaDir, + void setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir, Twine NameAsWritten); /// Adds this header to the given module. diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp index 2dd53b05d442..8730a5d5f4e7 100644 --- a/clang/lib/Basic/Module.cpp +++ b/clang/lib/Basic/Module.cpp @@ -247,10 +247,7 @@ Module::DirectoryName Module::getUmbrellaDir() const { if (Header U = getUmbrellaHeader()) return {"", U.Entry->getDir()}; - if (auto *ME = Umbrella.dyn_cast()) -return {UmbrellaAsWritten, DirectoryEntryRef(*ME)}; - - return {"", None}; + return {UmbrellaAsWritten, Umbrella.dyn_cast()}; } void Module::addTopHeader(const FileEntry *File) { diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 060cec23acc4..38b6f753134c 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++
[clang] ba5628f - ADT: Use 'using' to inherit assign and append in SmallString
Author: Duncan P. N. Exon Smith Date: 2021-01-22T16:17:58-08:00 New Revision: ba5628f2c2a9de049b80b3e276f7e05f481c49e7 URL: https://github.com/llvm/llvm-project/commit/ba5628f2c2a9de049b80b3e276f7e05f481c49e7 DIFF: https://github.com/llvm/llvm-project/commit/ba5628f2c2a9de049b80b3e276f7e05f481c49e7.diff LOG: ADT: Use 'using' to inherit assign and append in SmallString Rather than reimplement, use a `using` declaration to bring in `SmallVectorImpl`'s assign and append implementations in `SmallString`. The `SmallString` versions were missing reference invalidation assertions from `SmallVector`. This patch also fixes a bug in `llvm::FileCollector::addFileImpl`, which was a copy/paste from `clang::ModuleDependencyCollector::copyToRoot`, both caught by the no-longer-skipped assertions. As a drive-by, this also sinks the `const SmallVectorImpl&` versions of these methods down into `SmallVectorImpl`, since I imagine they'd be useful elsewhere. Differential Revision: https://reviews.llvm.org/D95202 Added: Modified: clang/lib/Frontend/ModuleDependencyCollector.cpp llvm/include/llvm/ADT/SmallString.h llvm/include/llvm/ADT/SmallVector.h llvm/lib/Support/FileCollector.cpp llvm/unittests/ADT/SmallVectorTest.cpp Removed: diff --git a/clang/lib/Frontend/ModuleDependencyCollector.cpp b/clang/lib/Frontend/ModuleDependencyCollector.cpp index b54eb97d6c47..2b981224c7e0 100644 --- a/clang/lib/Frontend/ModuleDependencyCollector.cpp +++ b/clang/lib/Frontend/ModuleDependencyCollector.cpp @@ -190,17 +190,17 @@ std::error_code ModuleDependencyCollector::copyToRoot(StringRef Src, // Canonicalize src to a native path to avoid mixed separator styles. path::native(AbsoluteSrc); // Remove redundant leading "./" pieces and consecutive separators. - AbsoluteSrc = path::remove_leading_dotslash(AbsoluteSrc); + StringRef TrimmedAbsoluteSrc = path::remove_leading_dotslash(AbsoluteSrc); // Canonicalize the source path by removing "..", "." components. - SmallString<256> VirtualPath = AbsoluteSrc; + SmallString<256> VirtualPath = TrimmedAbsoluteSrc; path::remove_dots(VirtualPath, /*remove_dot_dot=*/true); // If a ".." component is present after a symlink component, remove_dots may // lead to the wrong real destination path. Let the source be canonicalized // like that but make sure we always use the real path for the destination. SmallString<256> CopyFrom; - if (!getRealPath(AbsoluteSrc, CopyFrom)) + if (!getRealPath(TrimmedAbsoluteSrc, CopyFrom)) CopyFrom = VirtualPath; SmallString<256> CacheDst = getDest(); diff --git a/llvm/include/llvm/ADT/SmallString.h b/llvm/include/llvm/ADT/SmallString.h index c0e8fcd29461..5a56321ae492 100644 --- a/llvm/include/llvm/ADT/SmallString.h +++ b/llvm/include/llvm/ADT/SmallString.h @@ -40,35 +40,15 @@ class SmallString : public SmallVector { template SmallString(ItTy S, ItTy E) : SmallVector(S, E) {} - // Note that in order to add new overloads for append & assign, we have to - // duplicate the inherited versions so as not to inadvertently hide them. - /// @} /// @name String Assignment /// @{ - /// Assign from a repeated element. - void assign(size_t NumElts, char Elt) { -this->SmallVectorImpl::assign(NumElts, Elt); - } - - /// Assign from an iterator pair. - template - void assign(in_iter S, in_iter E) { -this->clear(); -SmallVectorImpl::append(S, E); - } + using SmallVector::assign; /// Assign from a StringRef. void assign(StringRef RHS) { -this->clear(); -SmallVectorImpl::append(RHS.begin(), RHS.end()); - } - - /// Assign from a SmallVector. - void assign(const SmallVectorImpl &RHS) { -this->clear(); -SmallVectorImpl::append(RHS.begin(), RHS.end()); +SmallVectorImpl::assign(RHS.begin(), RHS.end()); } /// Assign from a list of StringRefs. @@ -81,26 +61,13 @@ class SmallString : public SmallVector { /// @name String Concatenation /// @{ - /// Append from an iterator pair. - template - void append(in_iter S, in_iter E) { -SmallVectorImpl::append(S, E); - } - - void append(size_t NumInputs, char Elt) { -SmallVectorImpl::append(NumInputs, Elt); - } + using SmallVector::append; /// Append from a StringRef. void append(StringRef RHS) { SmallVectorImpl::append(RHS.begin(), RHS.end()); } - /// Append from a SmallVector. - void append(const SmallVectorImpl &RHS) { -SmallVectorImpl::append(RHS.begin(), RHS.end()); - } - /// Append from a list of StringRefs. void append(std::initializer_list Refs) { size_t SizeNeeded = this->size(); diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h index dd72937c19e2..e960b272db04 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -664,6 +664,8 @@ class SmallVectorImpl : public SmallVecto
[clang] 3ee43ad - Basic: Add native support for stdin to SourceManager and FileManager
Author: Duncan P. N. Exon Smith Date: 2020-12-23T15:18:50-08:00 New Revision: 3ee43adfb20d5dc56b7043b314bd22f457c55483 URL: https://github.com/llvm/llvm-project/commit/3ee43adfb20d5dc56b7043b314bd22f457c55483 DIFF: https://github.com/llvm/llvm-project/commit/3ee43adfb20d5dc56b7043b314bd22f457c55483.diff LOG: Basic: Add native support for stdin to SourceManager and FileManager Add support for stdin to SourceManager and FileManager. Adds FileManager::getSTDIN, which adds a FileEntryRef for `` and reads the MemoryBuffer, which is stored as `FileEntry::Content`. Eventually the other buffers in `ContentCache` will sink to here as well -- we probably usually want to load/save a MemoryBuffer eagerly -- but it's happening early for stdin to get rid of CompilerInstance::InitializeSourceManager's final call to `SourceManager::overrideFileContents`. clang/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.export/p1.cpp relies on building a module from stdin; supporting that requires setting ContentCache::BufferOverridden. Differential Revision: https://reviews.llvm.org/D93148 Added: Modified: clang/include/clang/Basic/FileEntry.h clang/include/clang/Basic/FileManager.h clang/lib/Basic/FileEntry.cpp clang/lib/Basic/FileManager.cpp clang/lib/Basic/SourceManager.cpp clang/lib/Frontend/CompilerInstance.cpp Removed: diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index aa7bedec44ac..6e91b42e18b7 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -25,6 +25,9 @@ #include "llvm/Support/FileSystem/UniqueID.h" namespace llvm { + +class MemoryBuffer; + namespace vfs { class File; @@ -67,6 +70,7 @@ class FileEntryRef { inline unsigned getUID() const; inline const llvm::sys::fs::UniqueID &getUniqueID() const; inline time_t getModificationTime() const; + inline bool isNamedPipe() const; inline void closeFile() const; /// Check if the underlying FileEntry is the same, intentially ignoring @@ -339,6 +343,9 @@ class FileEntry { /// The open file, if it is owned by the \p FileEntry. mutable std::unique_ptr File; + /// The file content, if it is owned by the \p FileEntry. + std::unique_ptr Content; + // First access name for this FileEntry. // // This is Optional only to allow delayed construction (FileEntryRef has no @@ -390,6 +397,8 @@ time_t FileEntryRef::getModificationTime() const { return getFileEntry().getModificationTime(); } +bool FileEntryRef::isNamedPipe() const { return getFileEntry().isNamedPipe(); } + void FileEntryRef::closeFile() const { getFileEntry().closeFile(); } } // end namespace clang diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index 449aec2b3541..974771a8f8f3 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -99,6 +99,9 @@ class FileManager : public RefCountedBase { std::unique_ptr>> SeenBypassFileEntries; + /// The file entry for stdin, if it has been accessed through the FileManager. + Optional STDIN; + /// The canonical names of files and directories . llvm::DenseMap CanonicalNames; @@ -217,6 +220,14 @@ class FileManager : public RefCountedBase { bool OpenFile = false, bool CacheFailure = true); + /// Get the FileEntryRef for stdin, returning an error if stdin cannot be + /// read. + /// + /// This reads and caches stdin before returning. Subsequent calls return the + /// same file entry, and a reference to the cached input is returned by calls + /// to getBufferForFile. + llvm::Expected getSTDIN(); + /// Get a FileEntryRef if it exists, without doing anything on error. llvm::Optional getOptionalFileRef(StringRef Filename, bool OpenFile = false, diff --git a/clang/lib/Basic/FileEntry.cpp b/clang/lib/Basic/FileEntry.cpp index 2efdcbbd46aa..5ee9bef9523e 100644 --- a/clang/lib/Basic/FileEntry.cpp +++ b/clang/lib/Basic/FileEntry.cpp @@ -12,6 +12,7 @@ //===--===// #include "clang/Basic/FileEntry.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/VirtualFileSystem.h" using namespace clang; diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index f3afe6dd5f48..6e9d5d7fb422 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -338,6 +338,25 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { return ReturnedRef; } +llvm::Expected FileManager::getSTDIN() { + // Only read stdin once. + if (STDIN) +return *STDIN; + + std::unique_ptr Content; + if (auto ContentOrError = llvm
[clang] 245218b - Basic: Support named pipes natively in SourceManager and FileManager
Author: Duncan P. N. Exon Smith Date: 2020-12-23T14:57:41-08:00 New Revision: 245218bb355599771ba43a0fe1449d1670f2666c URL: https://github.com/llvm/llvm-project/commit/245218bb355599771ba43a0fe1449d1670f2666c DIFF: https://github.com/llvm/llvm-project/commit/245218bb355599771ba43a0fe1449d1670f2666c.diff LOG: Basic: Support named pipes natively in SourceManager and FileManager Handle named pipes natively in SourceManager and FileManager, removing a call to `SourceManager::overrideFileContents` in `CompilerInstance::InitializeSourceManager` (removing a blocker for sinking the content cache to FileManager (which will incidently sink this new named pipe logic with it)). SourceManager usually checks if the file entry's size matches the eventually loaded buffer, but that's now skipped for named pipes since the `stat` won't reflect the full size. Since we can't trust `ContentsEntry->getSize()`, we also need shift the check for files that are too large until after the buffer is loaded... and load the buffer immediately in `createFileID` so that no client gets a bad value from `ContentCache::getSize`. `FileManager::getBufferForFile` also needs to treat these files as volatile when loading the buffer. Native support in SourceManager / FileManager means that named pipes can also be `#include`d, and clang/test/Misc/dev-fd-fs.c was expanded to check for that. This is a new version of 3b18a594c7717a328c33b9c1eba675e9f4bd367c, which was reverted in b34632201987eed369bb7ef4646f341b901c95b8 since it was missing the `SourceManager` changes. Differential Revision: https://reviews.llvm.org/D92531 Added: Modified: clang/lib/Basic/FileManager.cpp clang/lib/Basic/SourceManager.cpp clang/lib/Frontend/CompilerInstance.cpp clang/test/Misc/dev-fd-fs.c Removed: diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index c0d3685001ee..f3afe6dd5f48 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -489,7 +489,7 @@ FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile, uint64_t FileSize = Entry->getSize(); // If there's a high enough chance that the file have changed since we // got its size, force a stat before opening it. - if (isVolatile) + if (isVolatile || Entry->isNamedPipe()) FileSize = -1; StringRef Filename = Entry->getName(); diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index b71b2be0cc41..d2c0de5006c4 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -115,23 +115,6 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM, // return paths. IsBufferInvalid = true; - // Check that the file's size fits in an 'unsigned' (with room for a - // past-the-end value). This is deeply regrettable, but various parts of - // Clang (including elsewhere in this file!) use 'unsigned' to represent file - // offsets, line numbers, string literal lengths, and so on, and fail - // miserably on large source files. - if ((uint64_t)ContentsEntry->getSize() >= - std::numeric_limits::max()) { -if (Diag.isDiagnosticInFlight()) - Diag.SetDelayedDiagnostic(diag::err_file_too_large, -ContentsEntry->getName()); -else - Diag.Report(Loc, diag::err_file_too_large) -<< ContentsEntry->getName(); - -return None; - } - auto BufferOrError = FM.getBufferForFile(ContentsEntry, IsFileVolatile); // If we were unable to open the file, then we are in an inconsistent @@ -153,9 +136,31 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM, Buffer = std::move(*BufferOrError); - // Check that the file's size is the same as in the file entry (which may + // Check that the file's size fits in an 'unsigned' (with room for a + // past-the-end value). This is deeply regrettable, but various parts of + // Clang (including elsewhere in this file!) use 'unsigned' to represent file + // offsets, line numbers, string literal lengths, and so on, and fail + // miserably on large source files. + // + // Note: ContentsEntry could be a named pipe, in which case + // ContentsEntry::getSize() could have the wrong size. Use + // MemoryBuffer::getBufferSize() instead. + if (Buffer->getBufferSize() >= std::numeric_limits::max()) { +if (Diag.isDiagnosticInFlight()) + Diag.SetDelayedDiagnostic(diag::err_file_too_large, +ContentsEntry->getName()); +else + Diag.Report(Loc, diag::err_file_too_large) +<< ContentsEntry->getName(); + +return None; + } + + // Unless this is a named pipe (in which case we can handle a mismatch), + // check that the file's size is the same as in the file entry (which may // have come from a stat cache). - if (Buffer->getBufferSize() != (size_t)ContentsEntry->
Re: [PATCH] D92975: Lex: Migrate HeaderSearch::LoadedModuleMaps to FileEntryRef
Thanks for reverting; sorry I missed your email. > On 2020 Dec 14, at 19:27, Nico Weber via Phabricator > wrote: > > thakis added a comment. > > The revert helped, check-clang is no longer failing on Windows. > > > Repository: > rG LLVM Github Monorepo > > CHANGES SINCE LAST ACTION > https://reviews.llvm.org/D92975/new/ > > https://reviews.llvm.org/D92975 > ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 0eb4378 - Frontend: Fix confusing comment at call to clearOutputFiles, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-15T14:21:37-08:00 New Revision: 0eb4378290ffcd5da650217df3ac3b8c473d5ed6 URL: https://github.com/llvm/llvm-project/commit/0eb4378290ffcd5da650217df3ac3b8c473d5ed6 DIFF: https://github.com/llvm/llvm-project/commit/0eb4378290ffcd5da650217df3ac3b8c473d5ed6.diff LOG: Frontend: Fix confusing comment at call to clearOutputFiles, NFC Fix the comment in front of `compileModuleImpl`'s call to `CompilerInstance::clearOutputFiles`. The purpose of this call is to delete any stray temporary files after the module generation thread crashes. The comment is from f545f67de3a1bfdbbfad88acde5b540ce3b82f4f, and was associated with manually deleting a generated module map. Then 13afbf42d830dd43febbeb0855aa359ca9dbfbf9 added this `clearOutputFiles` call between the comment and the code it referenced. Finally, 1f76c4e8101b9beaf8f1b10a57faa80256ab2b05 started sending the generated module map directly to the SourceManager instead of putting it on disk, deleting the call that the comment referenced. No functionality change. Added: Modified: clang/lib/Frontend/CompilerInstance.cpp Removed: diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 17875a2ed85b..69e2e554d018 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1182,10 +1182,8 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, diag::remark_module_build_done) << ModuleName; - // Delete the temporary module map file. - // FIXME: Even though we're executing under crash protection, it would still - // be nice to do this with RemoveFileOnSignal when we can. However, that - // doesn't make sense for all clients, so clean this up manually. + // Delete any remaining temporary files related to Instance, in case the + // module generation thread crashed. Instance.clearOutputFiles(/*EraseFiles=*/true); return !Instance.getDiagnostics().hasErrorOccurred(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] b61f288 - Add comment to closing brace of anonymous namespace, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-14T14:38:12-08:00 New Revision: b61f288a58e40430a739900ab74df61e711a2c55 URL: https://github.com/llvm/llvm-project/commit/b61f288a58e40430a739900ab74df61e711a2c55 DIFF: https://github.com/llvm/llvm-project/commit/b61f288a58e40430a739900ab74df61e711a2c55.diff LOG: Add comment to closing brace of anonymous namespace, NFC Added: Modified: clang/unittests/Frontend/OutputStreamTest.cpp Removed: diff --git a/clang/unittests/Frontend/OutputStreamTest.cpp b/clang/unittests/Frontend/OutputStreamTest.cpp index 6a867bf053cb..5f23d782499b 100644 --- a/clang/unittests/Frontend/OutputStreamTest.cpp +++ b/clang/unittests/Frontend/OutputStreamTest.cpp @@ -100,4 +100,5 @@ TEST(FrontendOutputTests, TestVerboseOutputStreamOwned) { EXPECT_TRUE(!VerboseBuffer.empty()); EXPECT_TRUE(StringRef(VerboseBuffer.data()).contains("errors generated")); } -} + +} // anonymous namespace ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 90d056c - AST: Silence an instance of -Wsign-compare, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-14T14:36:59-08:00 New Revision: 90d056ceb97d5e3242a37dfc1c9f6bf11af9a053 URL: https://github.com/llvm/llvm-project/commit/90d056ceb97d5e3242a37dfc1c9f6bf11af9a053 DIFF: https://github.com/llvm/llvm-project/commit/90d056ceb97d5e3242a37dfc1c9f6bf11af9a053.diff LOG: AST: Silence an instance of -Wsign-compare, NFC Looks this this was added by 68f53960e17d93c3a2727164dac4e54140bd98ba. Added: Modified: clang/unittests/AST/ASTImporterTest.cpp Removed: diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 40340cb6f9bc..de0705d3019b 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -6096,7 +6096,7 @@ TEST_P(ASTImporterOptionSpecificTestBase, TypedefWithAttribute) { FirstDeclMatcher().match(TU, typedefDecl(hasName("X"))); auto *ToD = Import(FromD, Lang_CXX17); ASSERT_TRUE(ToD); - ASSERT_EQ(ToD->getAttrs().size(), 1); + ASSERT_EQ(ToD->getAttrs().size(), 1U); auto *ToAttr = dyn_cast(ToD->getAttrs()[0]); ASSERT_TRUE(ToAttr); EXPECT_EQ(ToAttr->getAnnotation(), "A"); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] a40db55 - Lex: Migrate HeaderSearch::LoadedModuleMaps to FileEntryRef
Author: Duncan P. N. Exon Smith Date: 2020-12-14T14:35:11-08:00 New Revision: a40db5502b2515a6f2f1676b5d7a655ae0f41179 URL: https://github.com/llvm/llvm-project/commit/a40db5502b2515a6f2f1676b5d7a655ae0f41179 DIFF: https://github.com/llvm/llvm-project/commit/a40db5502b2515a6f2f1676b5d7a655ae0f41179.diff LOG: Lex: Migrate HeaderSearch::LoadedModuleMaps to FileEntryRef Migrate `HeaderSearch::LoadedModuleMaps` and a number of APIs over to `FileEntryRef`. This should have no functionality change. Note that two `FileEntryRef`s hash the same if they point at the same `FileEntry`. Differential Revision: https://reviews.llvm.org/D92975 Added: Modified: clang-tools-extra/modularize/ModularizeUtilities.cpp clang/include/clang/Lex/HeaderSearch.h clang/include/clang/Lex/ModuleMap.h clang/lib/Frontend/FrontendAction.cpp clang/lib/Lex/HeaderSearch.cpp clang/lib/Lex/ModuleMap.cpp Removed: diff --git a/clang-tools-extra/modularize/ModularizeUtilities.cpp b/clang-tools-extra/modularize/ModularizeUtilities.cpp index 200370c135df..7470c324bbdb 100644 --- a/clang-tools-extra/modularize/ModularizeUtilities.cpp +++ b/clang-tools-extra/modularize/ModularizeUtilities.cpp @@ -258,22 +258,22 @@ std::error_code ModularizeUtilities::loadProblemHeaderList( std::error_code ModularizeUtilities::loadModuleMap( llvm::StringRef InputPath) { // Get file entry for module.modulemap file. - auto ModuleMapEntryOrErr = -SourceMgr->getFileManager().getFile(InputPath); + auto ExpectedModuleMapEntry = +SourceMgr->getFileManager().getFileRef(InputPath); // return error if not found. - if (!ModuleMapEntryOrErr) { + if (!ExpectedModuleMapEntry) { llvm::errs() << "error: File \"" << InputPath << "\" not found.\n"; -return ModuleMapEntryOrErr.getError(); +return errorToErrorCode(ExpectedModuleMapEntry.takeError()); } - const FileEntry *ModuleMapEntry = *ModuleMapEntryOrErr; + FileEntryRef ModuleMapEntry = *ExpectedModuleMapEntry; // Because the module map parser uses a ForwardingDiagnosticConsumer, // which doesn't forward the BeginSourceFile call, we do it explicitly here. DC.BeginSourceFile(*LangOpts, nullptr); // Figure out the home directory for the module map file. - const DirectoryEntry *Dir = ModuleMapEntry->getDir(); + const DirectoryEntry *Dir = ModuleMapEntry.getDir(); StringRef DirName(Dir->getName()); if (llvm::sys::path::filename(DirName) == "Modules") { DirName = llvm::sys::path::parent_path(DirName); diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index 93d6ea72270a..8ea81226cf77 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -239,7 +239,7 @@ class HeaderSearch { /// Set of module map files we've already loaded, and a flag indicating /// whether they were valid or not. - llvm::DenseMap LoadedModuleMaps; + llvm::DenseMap LoadedModuleMaps; /// Uniqued set of framework names, which is used to track which /// headers were included as framework headers. @@ -560,8 +560,8 @@ class HeaderSearch { /// Try to find a module map file in the given directory, returning /// \c nullptr if none is found. - const FileEntry *lookupModuleMapFile(const DirectoryEntry *Dir, - bool IsFramework); + Optional lookupModuleMapFile(const DirectoryEntry *Dir, + bool IsFramework); /// Determine whether there is a module map that may map the header /// with the given file name to a (sub)module. @@ -603,8 +603,8 @@ class HeaderSearch { ///used to resolve paths within the module (this is required when ///building the module from preprocessed source). /// \returns true if an error occurred, false otherwise. - bool loadModuleMapFile(const FileEntry *File, bool IsSystem, - FileID ID = FileID(), unsigned *Offset = nullptr, + bool loadModuleMapFile(FileEntryRef File, bool IsSystem, FileID ID = FileID(), + unsigned *Offset = nullptr, StringRef OriginalModuleMapFile = StringRef()); /// Collect the set of all known, top-level modules. @@ -794,8 +794,7 @@ class HeaderSearch { LMM_InvalidModuleMap }; - LoadModuleMapResult loadModuleMapFileImpl(const FileEntry *File, -bool IsSystem, + LoadModuleMapResult loadModuleMapFileImpl(FileEntryRef File, bool IsSystem, const DirectoryEntry *Dir, FileID ID = FileID(), unsigned *Offset = nullptr); diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h index 6827408f10a3..1d7ce5fc2320 100644 --- a/clan
[clang] e095959 - Fixup for 8c86197de3cba4257f26133e837d64e5f8ece210 to avoid making it platform-dependent
Author: Duncan P. N. Exon Smith Date: 2020-12-11T17:34:00-08:00 New Revision: e095959e0c23e250d6ad1dbe3612291736d12e1a URL: https://github.com/llvm/llvm-project/commit/e095959e0c23e250d6ad1dbe3612291736d12e1a DIFF: https://github.com/llvm/llvm-project/commit/e095959e0c23e250d6ad1dbe3612291736d12e1a.diff LOG: Fixup for 8c86197de3cba4257f26133e837d64e5f8ece210 to avoid making it platform-dependent Added: Modified: clang/tools/clang-import-test/clang-import-test.cpp Removed: diff --git a/clang/tools/clang-import-test/clang-import-test.cpp b/clang/tools/clang-import-test/clang-import-test.cpp index 5e84c5f97851..df173cf49f35 100644 --- a/clang/tools/clang-import-test/clang-import-test.cpp +++ b/clang/tools/clang-import-test/clang-import-test.cpp @@ -291,9 +291,9 @@ llvm::Error ParseSource(const std::string &Path, CompilerInstance &CI, SourceManager &SM = CI.getSourceManager(); auto FE = CI.getFileManager().getFileRef(Path); if (!FE) { +llvm::consumeError(FE.takeError()); return llvm::make_error( -llvm::Twine(llvm::toString(FE.takeError())) + ": " + Path, -std::error_code()); +llvm::Twine("No such file or directory: ", Path), std::error_code()); } SM.setMainFileID(SM.createFileID(*FE, SourceLocation(), SrcMgr::C_User)); ParseAST(CI.getPreprocessor(), &Consumer, CI.getASTContext()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 8c86197 - clang-import-test: Clean up error output for files that cannot be found
Author: Duncan P. N. Exon Smith Date: 2020-12-11T17:07:58-08:00 New Revision: 8c86197de3cba4257f26133e837d64e5f8ece210 URL: https://github.com/llvm/llvm-project/commit/8c86197de3cba4257f26133e837d64e5f8ece210 DIFF: https://github.com/llvm/llvm-project/commit/8c86197de3cba4257f26133e837d64e5f8ece210.diff LOG: clang-import-test: Clean up error output for files that cannot be found Pass on the filesystem error string `FileManager::getFileRef` in `clang-import-test`'s `ParseSource` function. Also include "error:" and a newline in the output. As a side effect, migrate to the `FileEntryRef` overload of `SourceManager::createFileID`. No real functionality change here, just slightly better output on error. Differential Revision: https://reviews.llvm.org/D92971 Added: Modified: clang/test/Import/missing-import/test.c clang/tools/clang-import-test/clang-import-test.cpp Removed: diff --git a/clang/test/Import/missing-import/test.c b/clang/test/Import/missing-import/test.c index acf6389cc5fc..9a16c2bf4ac8 100644 --- a/clang/test/Import/missing-import/test.c +++ b/clang/test/Import/missing-import/test.c @@ -1,5 +1,5 @@ // RUN: not clang-import-test -import %S/Inputs/S.c -expression %s 2>&1 | FileCheck %s -// CHECK: {{.*}}Couldn't open{{.*}}Inputs/S.c{{.*}} +// CHECK: error: No such file or directory: {{.*}}Inputs/S.c{{$}} void expr() { struct S MyS; void *MyPtr = &MyS; diff --git a/clang/tools/clang-import-test/clang-import-test.cpp b/clang/tools/clang-import-test/clang-import-test.cpp index eca3012957a3..5e84c5f97851 100644 --- a/clang/tools/clang-import-test/clang-import-test.cpp +++ b/clang/tools/clang-import-test/clang-import-test.cpp @@ -289,10 +289,11 @@ CIAndOrigins BuildIndirect(CIAndOrigins &CI) { llvm::Error ParseSource(const std::string &Path, CompilerInstance &CI, ASTConsumer &Consumer) { SourceManager &SM = CI.getSourceManager(); - auto FE = CI.getFileManager().getFile(Path); + auto FE = CI.getFileManager().getFileRef(Path); if (!FE) { return llvm::make_error( -llvm::Twine("Couldn't open ", Path), std::error_code()); +llvm::Twine(llvm::toString(FE.takeError())) + ": " + Path, +std::error_code()); } SM.setMainFileID(SM.createFileID(*FE, SourceLocation(), SrcMgr::C_User)); ParseAST(CI.getPreprocessor(), &Consumer, CI.getASTContext()); @@ -360,7 +361,7 @@ int main(int argc, const char **argv) { for (auto I : Imports) { llvm::Expected ImportCI = Parse(I, {}, false, false); if (auto E = ImportCI.takeError()) { - llvm::errs() << llvm::toString(std::move(E)); + llvm::errs() << "error: " << llvm::toString(std::move(E)) << "\n"; exit(-1); } ImportCIs.push_back(std::move(*ImportCI)); @@ -379,7 +380,7 @@ int main(int argc, const char **argv) { Parse(Expression, (Direct && !UseOrigins) ? ImportCIs : IndirectCIs, DumpAST, DumpIR); if (auto E = ExpressionCI.takeError()) { -llvm::errs() << llvm::toString(std::move(E)); +llvm::errs() << "error: " << llvm::toString(std::move(E)) << "\n"; exit(-1); } Forget(*ExpressionCI, (Direct && !UseOrigins) ? ImportCIs : IndirectCIs); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] a600432 - Frontend: Migrate to FileEntryRef in TextDiagnosticTest, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-11T17:06:28-08:00 New Revision: a60043219907b8f370263b7d3d4827b83388d8cf URL: https://github.com/llvm/llvm-project/commit/a60043219907b8f370263b7d3d4827b83388d8cf DIFF: https://github.com/llvm/llvm-project/commit/a60043219907b8f370263b7d3d4827b83388d8cf.diff LOG: Frontend: Migrate to FileEntryRef in TextDiagnosticTest, NFC Migrate over to the `FileEntryRef` overloads of `SourceManager::createFileID` and `overrideFileContents` (using `getVirtualFileRef`) in `TextDiagnostic`'s `ShowLine` test. No functionality change. Differential Revision: https://reviews.llvm.org/D92968 Added: Modified: clang/unittests/Frontend/TextDiagnosticTest.cpp Removed: diff --git a/clang/unittests/Frontend/TextDiagnosticTest.cpp b/clang/unittests/Frontend/TextDiagnosticTest.cpp index 1e05104d9388..220cff6643d5 100644 --- a/clang/unittests/Frontend/TextDiagnosticTest.cpp +++ b/clang/unittests/Frontend/TextDiagnosticTest.cpp @@ -46,7 +46,7 @@ TEST(TextDiagnostic, ShowLine) { // Create a dummy file with some contents to produce a test SourceLocation. const llvm::StringRef file_path = "main.cpp"; const llvm::StringRef main_file_contents = "some\nsource\ncode\n"; - const clang::FileEntry &fe = *FileMgr.getVirtualFile( + const clang::FileEntryRef fe = FileMgr.getVirtualFileRef( file_path, /*Size=*/static_cast(main_file_contents.size()), /*ModificationTime=*/0); @@ -55,11 +55,11 @@ TEST(TextDiagnostic, ShowLine) { buffer.append(main_file_contents.begin(), main_file_contents.end()); auto file_contents = std::make_unique( std::move(buffer), file_path); - SrcMgr.overrideFileContents(&fe, std::move(file_contents)); + SrcMgr.overrideFileContents(fe, std::move(file_contents)); // Create the actual file id and use it as the main file. clang::FileID fid = - SrcMgr.createFileID(&fe, SourceLocation(), clang::SrcMgr::C_User); + SrcMgr.createFileID(fe, SourceLocation(), clang::SrcMgr::C_User); SrcMgr.setMainFileID(fid); // Create the source location for the test diagnostic. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 494aacd - Tooling: Migrate some tests to FileEntryRef, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-10T18:05:03-08:00 New Revision: 494aacd72c6a85a6d586fa58a8481e13b68acf24 URL: https://github.com/llvm/llvm-project/commit/494aacd72c6a85a6d586fa58a8481e13b68acf24 DIFF: https://github.com/llvm/llvm-project/commit/494aacd72c6a85a6d586fa58a8481e13b68acf24.diff LOG: Tooling: Migrate some tests to FileEntryRef, NFC Migrate to the `FileEntryRef` overload of `SourceManager::createFileID` (using `FileManager::getOptionalFileRef`) in RefactoringTest.cpp and RewriterTestContext.h. No functionality change. Differential Revision: https://reviews.llvm.org/D92967 Added: Modified: clang/unittests/Tooling/RefactoringTest.cpp clang/unittests/Tooling/RewriterTestContext.h Removed: diff --git a/clang/unittests/Tooling/RefactoringTest.cpp b/clang/unittests/Tooling/RefactoringTest.cpp index 97a26a71deec..d239aba31d1d 100644 --- a/clang/unittests/Tooling/RefactoringTest.cpp +++ b/clang/unittests/Tooling/RefactoringTest.cpp @@ -608,7 +608,7 @@ class FlushRewrittenFilesTest : public ::testing::Test { llvm::raw_fd_ostream OutStream(FD, true); OutStream << Content; OutStream.close(); -auto File = Context.Files.getFile(Path); +auto File = Context.Files.getOptionalFileRef(Path); assert(File); StringRef Found = diff --git a/clang/unittests/Tooling/RewriterTestContext.h b/clang/unittests/Tooling/RewriterTestContext.h index ae2d2baa0fdc..a618ebd3a865 100644 --- a/clang/unittests/Tooling/RewriterTestContext.h +++ b/clang/unittests/Tooling/RewriterTestContext.h @@ -70,7 +70,7 @@ class RewriterTestContext { llvm::MemoryBuffer::getMemBuffer(Content); InMemoryFileSystem->addFile(Name, 0, std::move(Source)); -auto Entry = Files.getFile(Name); +auto Entry = Files.getOptionalFileRef(Name); assert(Entry); return Sources.createFileID(*Entry, SourceLocation(), SrcMgr::C_User); } @@ -87,7 +87,7 @@ class RewriterTestContext { llvm::raw_fd_ostream OutStream(FD, true); OutStream << Content; OutStream.close(); -auto File = Files.getFile(Path); +auto File = Files.getOptionalFileRef(Path); assert(File); StringRef Found = ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 0978c83 - Basic: Initialize FileEntry's fields inline, almost NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-10T13:57:21-08:00 New Revision: 0978c83e6fcc7a8aea18e24eb3b2ad5523581757 URL: https://github.com/llvm/llvm-project/commit/0978c83e6fcc7a8aea18e24eb3b2ad5523581757 DIFF: https://github.com/llvm/llvm-project/commit/0978c83e6fcc7a8aea18e24eb3b2ad5523581757.diff LOG: Basic: Initialize FileEntry's fields inline, almost NFC Initialize most of FileEntry's fields inline (all the ones that can be). The only functionality change is to avoid leaving some fields uninitialized. Added: Modified: clang/include/clang/Basic/FileEntry.h clang/lib/Basic/FileEntry.cpp clang/unittests/Basic/FileEntryTest.cpp Removed: diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 8db5446aa8d4..aa7bedec44ac 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -328,13 +328,13 @@ class FileEntry { friend class FileManager; std::string RealPathName; // Real path to the file; could be empty. - off_t Size; // File size in bytes. - time_t ModTime; // Modification time of file. - const DirectoryEntry *Dir; // Directory file lives in. + off_t Size = 0; // File size in bytes. + time_t ModTime = 0; // Modification time of file. + const DirectoryEntry *Dir = nullptr; // Directory file lives in. llvm::sys::fs::UniqueID UniqueID; - unsigned UID; // A unique (small) ID for the file. - bool IsNamedPipe; - bool IsValid; // Is this \c FileEntry initialized and valid? + unsigned UID = 0; // A unique (small) ID for the file. + bool IsNamedPipe = false; + bool IsValid = false; // Is this \c FileEntry initialized and valid? /// The open file, if it is owned by the \p FileEntry. mutable std::unique_ptr File; diff --git a/clang/lib/Basic/FileEntry.cpp b/clang/lib/Basic/FileEntry.cpp index 29218c7e0ec8..2efdcbbd46aa 100644 --- a/clang/lib/Basic/FileEntry.cpp +++ b/clang/lib/Basic/FileEntry.cpp @@ -16,7 +16,7 @@ using namespace clang; -FileEntry::FileEntry() : UniqueID(0, 0), IsNamedPipe(false), IsValid(false) {} +FileEntry::FileEntry() : UniqueID(0, 0) {} FileEntry::~FileEntry() = default; diff --git a/clang/unittests/Basic/FileEntryTest.cpp b/clang/unittests/Basic/FileEntryTest.cpp index 3cc01870b800..a3e03e6c7c29 100644 --- a/clang/unittests/Basic/FileEntryTest.cpp +++ b/clang/unittests/Basic/FileEntryTest.cpp @@ -55,6 +55,17 @@ struct RefMaps { } }; +TEST(FileEntryTest, Constructor) { + FileEntry FE; + EXPECT_EQ(0U, FE.getSize()); + EXPECT_EQ(0, FE.getModificationTime()); + EXPECT_EQ(nullptr, FE.getDir()); + EXPECT_EQ(0U, FE.getUniqueID().getDevice()); + EXPECT_EQ(0U, FE.getUniqueID().getFile()); + EXPECT_EQ(false, FE.isNamedPipe()); + EXPECT_EQ(false, FE.isValid()); +} + TEST(FileEntryTest, FileEntryRef) { RefMaps Refs; FileEntryRef R1 = Refs.addFile("1"); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 028e55d - clangd: Migrate to FileEntryRef in TweakTests, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-09T17:00:42-08:00 New Revision: 028e55d2d411f19e193e3d5df589162a317ab5f1 URL: https://github.com/llvm/llvm-project/commit/028e55d2d411f19e193e3d5df589162a317ab5f1 DIFF: https://github.com/llvm/llvm-project/commit/028e55d2d411f19e193e3d5df589162a317ab5f1.diff LOG: clangd: Migrate to FileEntryRef in TweakTests, NFC Added: Modified: clang-tools-extra/clangd/unittests/tweaks/TweakTests.cpp Removed: diff --git a/clang-tools-extra/clangd/unittests/tweaks/TweakTests.cpp b/clang-tools-extra/clangd/unittests/tweaks/TweakTests.cpp index cb0b38dc99ec..8c8dc5530e09 100644 --- a/clang-tools-extra/clangd/unittests/tweaks/TweakTests.cpp +++ b/clang-tools-extra/clangd/unittests/tweaks/TweakTests.cpp @@ -53,7 +53,7 @@ TEST(FileEdits, AbsolutePath) { SourceManager SM(DE, FM); for (const auto *Path : RelPaths) { -auto FID = SM.createFileID(*FM.getFile(Path), SourceLocation(), +auto FID = SM.createFileID(*FM.getOptionalFileRef(Path), SourceLocation(), clang::SrcMgr::C_User); auto Res = Tweak::Effect::fileEdit(SM, FID, tooling::Replacements()); ASSERT_THAT_EXPECTED(Res, llvm::Succeeded()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 2ea8c69 - Tooling: Migrate to FileEntryRef in clang::tooling::applyAllReplacements, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-09T16:31:38-08:00 New Revision: 2ea8c69eff07c491c7cb14dd46afd30529b89d91 URL: https://github.com/llvm/llvm-project/commit/2ea8c69eff07c491c7cb14dd46afd30529b89d91 DIFF: https://github.com/llvm/llvm-project/commit/2ea8c69eff07c491c7cb14dd46afd30529b89d91.diff LOG: Tooling: Migrate to FileEntryRef in clang::tooling::applyAllReplacements, NFC Migrate to the `FileEntryRef` overload of `SourceManager::createFileID`. Added: Modified: clang/lib/Tooling/Core/Replacement.cpp Removed: diff --git a/clang/lib/Tooling/Core/Replacement.cpp b/clang/lib/Tooling/Core/Replacement.cpp index ab8e20539559..30e1923bf1cb 100644 --- a/clang/lib/Tooling/Core/Replacement.cpp +++ b/clang/lib/Tooling/Core/Replacement.cpp @@ -591,7 +591,7 @@ llvm::Expected applyAllReplacements(StringRef Code, Rewriter Rewrite(SourceMgr, LangOptions()); InMemoryFileSystem->addFile( "", 0, llvm::MemoryBuffer::getMemBuffer(Code, "")); - FileID ID = SourceMgr.createFileID(*Files.getFile(""), + FileID ID = SourceMgr.createFileID(*Files.getOptionalFileRef(""), SourceLocation(), clang::SrcMgr::C_User); for (auto I = Replaces.rbegin(), E = Replaces.rend(); I != E; ++I) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 347e1f6 - Frontend: Use a getVirtualFileRef for a named pipe main file, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-09T16:17:14-08:00 New Revision: 347e1f621355d9b58901f3579fde91783c24ca29 URL: https://github.com/llvm/llvm-project/commit/347e1f621355d9b58901f3579fde91783c24ca29 DIFF: https://github.com/llvm/llvm-project/commit/347e1f621355d9b58901f3579fde91783c24ca29.diff LOG: Frontend: Use a getVirtualFileRef for a named pipe main file, NFC Added: Modified: clang/lib/Frontend/CompilerInstance.cpp Removed: diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 92e5208b193b..17875a2ed85b 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -868,8 +868,8 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input, FileMgr.getBufferForFile(&File.getFileEntry(), /*isVolatile=*/true); if (MB) { // Create a new virtual file that will have the correct size. -const FileEntry *FE = -FileMgr.getVirtualFile(InputFile, (*MB)->getBufferSize(), 0); +FileEntryRef FE = +FileMgr.getVirtualFileRef(InputFile, (*MB)->getBufferSize(), 0); SourceMgr.overrideFileContents(FE, std::move(*MB)); SourceMgr.setMainFileID( SourceMgr.createFileID(FE, SourceLocation(), Kind)); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 75a95bc - clang-format: Migrate createInMemoryFile to FileEntryRef, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-09T15:00:53-08:00 New Revision: 75a95bc80eae0c539b342f2cb19a92a0de02d2e1 URL: https://github.com/llvm/llvm-project/commit/75a95bc80eae0c539b342f2cb19a92a0de02d2e1 DIFF: https://github.com/llvm/llvm-project/commit/75a95bc80eae0c539b342f2cb19a92a0de02d2e1.diff LOG: clang-format: Migrate createInMemoryFile to FileEntryRef, NFC Added: Modified: clang/tools/clang-format/ClangFormat.cpp Removed: diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp index 121c9626b261..a1b42a6d0940 100644 --- a/clang/tools/clang-format/ClangFormat.cpp +++ b/clang/tools/clang-format/ClangFormat.cpp @@ -178,7 +178,7 @@ static FileID createInMemoryFile(StringRef FileName, MemoryBufferRef Source, SourceManager &Sources, FileManager &Files, llvm::vfs::InMemoryFileSystem *MemFS) { MemFS->addFileNoOwn(FileName, 0, Source); - auto File = Files.getFile(FileName); + auto File = Files.getOptionalFileRef(FileName); assert(File && "File not added to MemFS?"); return Sources.createFileID(*File, SourceLocation(), SrcMgr::C_User); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] c3ff993 - Remove RemappedFiles param from ASTUnit::LoadFromASTFile, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-09T14:44:31-08:00 New Revision: c3ff9939bf7efeb11da49f100a277b4d8bbeff9f URL: https://github.com/llvm/llvm-project/commit/c3ff9939bf7efeb11da49f100a277b4d8bbeff9f DIFF: https://github.com/llvm/llvm-project/commit/c3ff9939bf7efeb11da49f100a277b4d8bbeff9f.diff LOG: Remove RemappedFiles param from ASTUnit::LoadFromASTFile, NFC This parameter is always set to `None`. Remove it. Differential Revision: https://reviews.llvm.org/D90889 Added: Modified: clang/include/clang/Frontend/ASTUnit.h clang/lib/Frontend/ASTUnit.cpp clang/tools/c-index-test/core_main.cpp clang/tools/libclang/CIndex.cpp Removed: diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h index 5bee57042ca6..6cf9f3ff936f 100644 --- a/clang/include/clang/Frontend/ASTUnit.h +++ b/clang/include/clang/Frontend/ASTUnit.h @@ -688,14 +688,15 @@ class ASTUnit { /// lifetime is expected to extend past that of the returned ASTUnit. /// /// \returns - The initialized ASTUnit or null if the AST failed to load. - static std::unique_ptr LoadFromASTFile( - const std::string &Filename, const PCHContainerReader &PCHContainerRdr, - WhatToLoad ToLoad, IntrusiveRefCntPtr Diags, - const FileSystemOptions &FileSystemOpts, bool UseDebugInfo = false, - bool OnlyLocalDecls = false, ArrayRef RemappedFiles = None, - CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None, - bool AllowASTWithCompilerErrors = false, - bool UserFilesAreVolatile = false); + static std::unique_ptr + LoadFromASTFile(const std::string &Filename, + const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad, + IntrusiveRefCntPtr Diags, + const FileSystemOptions &FileSystemOpts, + bool UseDebugInfo = false, bool OnlyLocalDecls = false, + CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None, + bool AllowASTWithCompilerErrors = false, + bool UserFilesAreVolatile = false); private: /// Helper function for \c LoadFromCompilerInvocation() and diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index d9154e9b459e..51851a5bac83 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -758,9 +758,8 @@ std::unique_ptr ASTUnit::LoadFromASTFile( const std::string &Filename, const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad, IntrusiveRefCntPtr Diags, const FileSystemOptions &FileSystemOpts, bool UseDebugInfo, -bool OnlyLocalDecls, ArrayRef RemappedFiles, -CaptureDiagsKind CaptureDiagnostics, bool AllowASTWithCompilerErrors, -bool UserFilesAreVolatile) { +bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics, +bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) { std::unique_ptr AST(new ASTUnit(true)); // Recover resources if we crash before exiting this method. @@ -793,9 +792,6 @@ std::unique_ptr ASTUnit::LoadFromASTFile( /*Target=*/nullptr)); AST->PPOpts = std::make_shared(); - for (const auto &RemappedFile : RemappedFiles) -AST->PPOpts->addRemappedFile(RemappedFile.first, RemappedFile.second); - // Gather Info for preprocessor construction later on. HeaderSearch &HeaderInfo = *AST->HeaderInfo; diff --git a/clang/tools/c-index-test/core_main.cpp b/clang/tools/c-index-test/core_main.cpp index c6d59d703d17..ed0d99b9d199 100644 --- a/clang/tools/c-index-test/core_main.cpp +++ b/clang/tools/c-index-test/core_main.cpp @@ -262,7 +262,7 @@ static bool printSourceSymbolsFromModule(StringRef modulePath, std::unique_ptr AU = ASTUnit::LoadFromASTFile( std::string(modulePath), *pchRdr, ASTUnit::LoadASTOnly, Diags, FileSystemOpts, /*UseDebugInfo=*/false, - /*OnlyLocalDecls=*/true, None, CaptureDiagsKind::None, + /*OnlyLocalDecls=*/true, CaptureDiagsKind::None, /*AllowASTWithCompilerErrors=*/true, /*UserFilesAreVolatile=*/false); if (!AU) { diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 95ff9aa35bfa..aa888a380048 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -3475,7 +3475,7 @@ enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx, std::unique_ptr AU = ASTUnit::LoadFromASTFile( ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(), ASTUnit::LoadEverything, Diags, FileSystemOpts, /*UseDebugInfo=*/false, - CXXIdx->getOnlyLocalDecls(), None, CaptureDiagsKind::All, + CXXIdx->getOnlyLocalDecls(), CaptureDiagsKind::All, /*AllowASTWithCompilerErrors=*/true, /*UserFilesAreVolatile=*/true); *out_TU = MakeCXTranslationUnit(CXXIdx, std::move(AU)); ___
[clang] 898d61b - ARCMigrate: Migrate ObjCMT.cpp over to FileEntryRef
Author: Duncan P. N. Exon Smith Date: 2020-12-09T14:16:05-08:00 New Revision: 898d61b3cff5d79870d964c76d82764fef73efbb URL: https://github.com/llvm/llvm-project/commit/898d61b3cff5d79870d964c76d82764fef73efbb DIFF: https://github.com/llvm/llvm-project/commit/898d61b3cff5d79870d964c76d82764fef73efbb.diff LOG: ARCMigrate: Migrate ObjCMT.cpp over to FileEntryRef Migrate ObjCMT.cpp from using `const FileEntry*` to `FileEntryRef`. This is one of the blockers for changing `SourceManager` to use `FileEntryRef`. This adds an initial version of `SourceManager::getFileEntryRefForID`, which uses to `FileEntry::getLastRef`; after `SourceManager` switches, `SourceManager::getFileEntryForID` will need to call this function. This also adds uses of `FileEntryRef` as a key in a `DenseMap`, and a call to `hash_value(Optional)` in `DenseMapInfo`; support for these were added in prep commits. Differential Revision: https://reviews.llvm.org/D92678 Added: Modified: clang/include/clang/Basic/SourceManager.h clang/lib/ARCMigrate/ObjCMT.cpp Removed: diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index e067cd8fad83..a43b47662180 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -1033,6 +1033,13 @@ class SourceManager : public RefCountedBase { return nullptr; } + /// Returns the FileEntryRef for the provided FileID. + Optional getFileEntryRefForID(FileID FID) const { +if (auto *Entry = getFileEntryForID(FID)) + return Entry->getLastRef(); +return None; + } + /// Returns the filename for the provided FileID, unless it's a built-in /// buffer that's not represented by a filename. /// diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index dfc0d9353165..68a51a49c718 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -156,7 +156,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer { return WhiteListFilenames.find(llvm::sys::path::filename(Path)) != WhiteListFilenames.end(); } - bool canModifyFile(const FileEntry *FE) { + bool canModifyFile(Optional FE) { if (!FE) return false; return canModifyFile(FE->getName()); @@ -164,7 +164,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer { bool canModifyFile(FileID FID) { if (FID.isInvalid()) return false; -return canModifyFile(PP.getSourceManager().getFileEntryForID(FID)); +return canModifyFile(PP.getSourceManager().getFileEntryRefForID(FID)); } bool canModify(const Decl *D) { @@ -1964,7 +1964,7 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) { FileID FID = I->first; RewriteBuffer &buf = I->second; -const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID); +Optional file = Ctx.getSourceManager().getFileEntryRefForID(FID); assert(file); SmallString<512> newText; llvm::raw_svector_ostream vecOS(newText); @@ -2034,7 +2034,7 @@ MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { namespace { struct EditEntry { - const FileEntry *File = nullptr; + Optional File; unsigned Offset = 0; unsigned RemoveLen = 0; std::string Text; @@ -2127,9 +2127,8 @@ class RemapFileParser { StringRef Val = ValueString->getValue(ValueStorage); if (Key == "file") { -auto FE = FileMgr.getFile(Val); -if (FE) - Entry.File = *FE; +if (auto File = FileMgr.getOptionalFileRef(Val)) + Entry.File = File; else Ignore = true; } else if (Key == "offset") { @@ -2155,7 +2154,7 @@ static bool reportDiag(const Twine &Err, DiagnosticsEngine &Diag) { return true; } -static std::string applyEditsToTemp(const FileEntry *FE, +static std::string applyEditsToTemp(FileEntryRef FE, ArrayRef Edits, FileManager &FileMgr, DiagnosticsEngine &Diag) { @@ -2199,8 +2198,8 @@ static std::string applyEditsToTemp(const FileEntry *FE, SmallString<64> TempPath; int FD; - if (fs::createTemporaryFile(path::filename(FE->getName()), - path::extension(FE->getName()).drop_front(), FD, + if (fs::createTemporaryFile(path::filename(FE.getName()), + path::extension(FE.getName()).drop_front(), FD, TempPath)) { reportDiag("Could not create file: " + TempPath.str(), Diag); return std::string(); @@ -2228,7 +2227,7 @@ bool arcmt::getFileRemappingsFromFileList( new DiagnosticsEngine(DiagID, new DiagnosticOptions, DiagClient, /*ShouldOwnClient=*/false)
[clang] a5c89bb - Frontend: Migrate to FileEntryRef in CompilerInstance::InitializeSourceManager, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-09T13:28:29-08:00 New Revision: a5c89bb02195a97aa71a406d9864098c764f URL: https://github.com/llvm/llvm-project/commit/a5c89bb02195a97aa71a406d9864098c764f DIFF: https://github.com/llvm/llvm-project/commit/a5c89bb02195a97aa71a406d9864098c764f.diff LOG: Frontend: Migrate to FileEntryRef in CompilerInstance::InitializeSourceManager, NFC Use `FileManager::getVirtualFileRef` to get the virtual file for stdin, and add an overload of `SourceManager::overrideFileContents` that takes a `FileEntryRef`, migrating `CompilerInstance::InitializeSourceManager`. Differential Revision: https://reviews.llvm.org/D92680 Added: Modified: clang/include/clang/Basic/SourceManager.h clang/lib/Frontend/CompilerInstance.cpp Removed: diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index 05edc98f9ec8..e067cd8fad83 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -958,6 +958,10 @@ class SourceManager : public RefCountedBase { /// data in the given source file. void overrideFileContents(const FileEntry *SourceFile, std::unique_ptr Buffer); + void overrideFileContents(FileEntryRef SourceFile, +std::unique_ptr Buffer) { +overrideFileContents(&SourceFile.getFileEntry(), std::move(Buffer)); + } /// Override the given source file with another one. /// diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index fa3d50aeedfe..92e5208b193b 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -891,8 +891,8 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input, } std::unique_ptr SB = std::move(SBOrErr.get()); -const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(), - SB->getBufferSize(), 0); +FileEntryRef File = FileMgr.getVirtualFileRef(SB->getBufferIdentifier(), + SB->getBufferSize(), 0); SourceMgr.setMainFileID( SourceMgr.createFileID(File, SourceLocation(), Kind)); SourceMgr.overrideFileContents(File, std::move(SB)); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 8278922 - Frontend: Migrate to FileEntryRef in VerifyDiagnosticConsumer.cpp, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-09T11:51:43-08:00 New Revision: 82789228c65317ceea3fdcc08c573c5ca780021e URL: https://github.com/llvm/llvm-project/commit/82789228c65317ceea3fdcc08c573c5ca780021e DIFF: https://github.com/llvm/llvm-project/commit/82789228c65317ceea3fdcc08c573c5ca780021e.diff LOG: Frontend: Migrate to FileEntryRef in VerifyDiagnosticConsumer.cpp, NFC Add a `FileEntryRef` overload of `SourceManager::translateFile`, and migrate `ParseDirective` in VerifyDiagnosticConsumer.cpp to use it and the corresponding overload of `createFileID`. No functionality change here. Differential Revision: https://reviews.llvm.org/D92699 Added: Modified: clang/include/clang/Basic/SourceManager.h clang/lib/Frontend/VerifyDiagnosticConsumer.cpp Removed: diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index 459bd088f0d7..05edc98f9ec8 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -1582,6 +1582,9 @@ class SourceManager : public RefCountedBase { /// If the source file is included multiple times, the FileID will be the /// first inclusion. FileID translateFile(const FileEntry *SourceFile) const; + FileID translateFile(FileEntryRef SourceFile) const { +return translateFile(&SourceFile.getFileEntry()); + } /// Get the source location in \p FID for the given line:col. /// Returns null location if \p FID is not a file SLocEntry. diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp index a10a3dd8a446..0503ae46a15f 100644 --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -554,10 +554,9 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM, continue; } - const FileEntry *FE = &File->getFileEntry(); - FileID FID = SM.translateFile(FE); + FileID FID = SM.translateFile(*File); if (FID.isInvalid()) -FID = SM.createFileID(FE, Pos, SrcMgr::C_User); +FID = SM.createFileID(*File, Pos, SrcMgr::C_User); if (PH.Next(Line) && Line > 0) ExpectedLoc = SM.translateLineCol(FID, Line, 1); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 2878e96 - Basic: Add hashing support for FileEntryRef and DirectoryEntryRef
Author: Duncan P. N. Exon Smith Date: 2020-12-08T18:10:53-08:00 New Revision: 2878e965af27ce037378a4f0409e89039108c09f URL: https://github.com/llvm/llvm-project/commit/2878e965af27ce037378a4f0409e89039108c09f DIFF: https://github.com/llvm/llvm-project/commit/2878e965af27ce037378a4f0409e89039108c09f.diff LOG: Basic: Add hashing support for FileEntryRef and DirectoryEntryRef Allow hashing FileEntryRef and DirectoryEntryRef via `hash_value`, and use that to implement `DenseMapInfo`. This hash should be equal whenever the entry is the same (the name used to reference it is not relevant). Also add `DirectoryEntryRef::isSameRef` to simplify the implementation and facilitate testing. Differential Revision: https://reviews.llvm.org/D92627 Added: Modified: clang/include/clang/Basic/DirectoryEntry.h clang/include/clang/Basic/FileEntry.h clang/unittests/Basic/FileEntryTest.cpp Removed: diff --git a/clang/include/clang/Basic/DirectoryEntry.h b/clang/include/clang/Basic/DirectoryEntry.h index 4e229962bdcc..e0f4ae28321a 100644 --- a/clang/include/clang/Basic/DirectoryEntry.h +++ b/clang/include/clang/Basic/DirectoryEntry.h @@ -15,6 +15,8 @@ #define LLVM_CLANG_BASIC_DIRECTORYENTRY_H #include "clang/Basic/LLVM.h" +#include "llvm/ADT/DenseMapInfo.h" +#include "llvm/ADT/Hashing.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/ErrorOr.h" @@ -46,10 +48,19 @@ class DirectoryEntryRef { StringRef getName() const { return ME->getKey(); } + /// Hash code is based on the DirectoryEntry, not the specific named + /// reference. + friend llvm::hash_code hash_value(DirectoryEntryRef Ref) { +return llvm::hash_value(&Ref.getDirEntry()); + } + using MapEntry = llvm::StringMapEntry>; const MapEntry &getMapEntry() const { return *ME; } + /// Check if RHS referenced the file in exactly the same way. + bool isSameRef(DirectoryEntryRef RHS) const { return ME == RHS.ME; } + DirectoryEntryRef() = delete; DirectoryEntryRef(const MapEntry &ME) : ME(&ME) {} @@ -80,6 +91,20 @@ class DirectoryEntryRef { DirectoryEntryRef(optional_none_tag) : ME(nullptr) {} bool hasOptionalValue() const { return ME; } + friend struct llvm::DenseMapInfo; + struct dense_map_empty_tag {}; + struct dense_map_tombstone_tag {}; + + // Private constructors for use by DenseMapInfo. + DirectoryEntryRef(dense_map_empty_tag) + : ME(llvm::DenseMapInfo::getEmptyKey()) {} + DirectoryEntryRef(dense_map_tombstone_tag) + : ME(llvm::DenseMapInfo::getTombstoneKey()) {} + bool isSpecialDenseMapKey() const { +return isSameRef(DirectoryEntryRef(dense_map_empty_tag())) || + isSameRef(DirectoryEntryRef(dense_map_tombstone_tag())); + } + const MapEntry *ME; }; @@ -164,6 +189,38 @@ static_assert( "Optional should be trivially copyable"); } // end namespace optional_detail + +/// Specialisation of DenseMapInfo for DirectoryEntryRef. +template <> struct DenseMapInfo { + static inline clang::DirectoryEntryRef getEmptyKey() { +return clang::DirectoryEntryRef( +clang::DirectoryEntryRef::dense_map_empty_tag()); + } + + static inline clang::DirectoryEntryRef getTombstoneKey() { +return clang::DirectoryEntryRef( +clang::DirectoryEntryRef::dense_map_tombstone_tag()); + } + + static unsigned getHashValue(clang::DirectoryEntryRef Val) { +return hash_value(Val); + } + + static bool isEqual(clang::DirectoryEntryRef LHS, + clang::DirectoryEntryRef RHS) { +// Catch the easy cases: both empty, both tombstone, or the same ref. +if (LHS.isSameRef(RHS)) + return true; + +// Confirm LHS and RHS are valid. +if (LHS.isSpecialDenseMapKey() || RHS.isSpecialDenseMapKey()) + return false; + +// It's safe to use operator==. +return LHS == RHS; + } +}; + } // end namespace llvm namespace clang { diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 75158d44bf5a..8db5446aa8d4 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -16,6 +16,8 @@ #include "clang/Basic/DirectoryEntry.h" #include "clang/Basic/LLVM.h" +#include "llvm/ADT/DenseMapInfo.h" +#include "llvm/ADT/Hashing.h" #include "llvm/ADT/PointerUnion.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" @@ -88,6 +90,12 @@ class FileEntryRef { return !(LHS == RHS); } + /// Hash code is based on the FileEntry, not the specific named reference, + /// just like operator==. + friend llvm::hash_code hash_value(FileEntryRef Ref) { +return llvm::hash_value(&Ref.getFileEntry()); + } + struct MapValue; /// Type used in the StringMap. @@ -154,6 +162,20 @@ class FileEntryRef { FileEntryRef(optional_none_tag) : ME(nullptr) {} bool hasOptionalValue() const { return ME; } + friend struct l
[clang-tools-extra] 5207f19 - ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-08T17:33:19-08:00 New Revision: 5207f19d103dc3e0ec974fa64d2c031d84d497a8 URL: https://github.com/llvm/llvm-project/commit/5207f19d103dc3e0ec974fa64d2c031d84d497a8 DIFF: https://github.com/llvm/llvm-project/commit/5207f19d103dc3e0ec974fa64d2c031d84d497a8.diff LOG: ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC Allow a `std::unique_ptr` to be moved into the an `IntrusiveRefCntPtr`, and remove a couple of now-unnecessary `release()` calls. Differential Revision: https://reviews.llvm.org/D92888 Added: Modified: clang-tools-extra/clangd/support/ThreadsafeFS.cpp clang/lib/Tooling/AllTUsExecution.cpp clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp llvm/include/llvm/ADT/IntrusiveRefCntPtr.h llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp Removed: diff --git a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp index cadda8efa095..ae9450f17411 100644 --- a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp +++ b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp @@ -87,8 +87,7 @@ RealThreadsafeFS::viewImpl() const { // Avoid using memory-mapped files. // FIXME: Try to use a similar approach in Sema instead of relying on //propagation of the 'isVolatile' flag through all layers. - return new VolatileFileSystem( - llvm::vfs::createPhysicalFileSystem().release()); + return new VolatileFileSystem(llvm::vfs::createPhysicalFileSystem()); } } // namespace clangd } // namespace clang diff --git a/clang/lib/Tooling/AllTUsExecution.cpp b/clang/lib/Tooling/AllTUsExecution.cpp index 7707c99c21d0..5565da9b548a 100644 --- a/clang/lib/Tooling/AllTUsExecution.cpp +++ b/clang/lib/Tooling/AllTUsExecution.cpp @@ -124,7 +124,7 @@ llvm::Error AllTUsToolExecutor::execute( // Each thread gets an indepent copy of a VFS to allow diff erent // concurrent working directories. IntrusiveRefCntPtr FS = -llvm::vfs::createPhysicalFileSystem().release(); +llvm::vfs::createPhysicalFileSystem(); ClangTool Tool(Compilations, {Path}, std::make_shared(), FS); Tool.appendArgumentsAdjuster(Action.second); diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp index f10b60252715..63264b0dda2d 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -154,7 +154,7 @@ DependencyScanningWorker::DependencyScanningWorker( : Format(Service.getFormat()) { DiagOpts = new DiagnosticOptions(); PCHContainerOps = std::make_shared(); - RealFS = llvm::vfs::createPhysicalFileSystem().release(); + RealFS = llvm::vfs::createPhysicalFileSystem(); if (Service.canSkipExcludedPPRanges()) PPSkipMappings = std::make_unique(); diff --git a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h index 173fad3aeafa..dcd35253c5f2 100644 --- a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h +++ b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h @@ -58,6 +58,7 @@ #include #include #include +#include namespace llvm { @@ -175,6 +176,11 @@ template class IntrusiveRefCntPtr { S.Obj = nullptr; } + template + IntrusiveRefCntPtr(std::unique_ptr S) : Obj(S.release()) { +retain(); + } + template IntrusiveRefCntPtr(const IntrusiveRefCntPtr &S) : Obj(S.get()) { retain(); diff --git a/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp b/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp index 3d8041fcbf48..f69239162e3a 100644 --- a/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp +++ b/llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp @@ -42,6 +42,17 @@ TYPED_TEST(IntrusiveRefCntPtrTest, RefCountedBaseCopyDoesNotLeak) { EXPECT_EQ(0, NumInstances); } +TYPED_TEST(IntrusiveRefCntPtrTest, InteropsWithUniquePtr) { + EXPECT_EQ(0, NumInstances); + { +auto S1 = std::make_unique(); +IntrusiveRefCntPtr R1 = std::move(S1); +EXPECT_EQ(1, NumInstances); +EXPECT_EQ(S1, nullptr); + } + EXPECT_EQ(0, NumInstances); +} + struct InterceptRefCounted : public RefCountedBase { InterceptRefCounted(bool *Released, bool *Retained) : Released(Released), Retained(Retained) {} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] b85c6e5 - ARCMigrate: Use hash_combine in the DenseMapInfo for EditEntry
Author: Duncan P. N. Exon Smith Date: 2020-12-08T13:46:21-08:00 New Revision: b85c6e5bcd1a9de941c318f9a5dc742818752a56 URL: https://github.com/llvm/llvm-project/commit/b85c6e5bcd1a9de941c318f9a5dc742818752a56 DIFF: https://github.com/llvm/llvm-project/commit/b85c6e5bcd1a9de941c318f9a5dc742818752a56.diff LOG: ARCMigrate: Use hash_combine in the DenseMapInfo for EditEntry Simplify the DenseMapInfo for `EditEntry` by migrating from `FoldingSetNodeID` to `llvm::hash_combine`. Besides the cleanup, this reduces the diff for a future patch which changes the type of one of the fields. There should be no real functionality change here, although I imagine the hash value will churn since its a different hashing infrastructure. Differential Revision: https://reviews.llvm.org/D92630 Added: Modified: clang/lib/ARCMigrate/ObjCMT.cpp Removed: diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index ef2985d16d23..dfc0d9353165 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -2054,12 +2054,8 @@ template<> struct DenseMapInfo { return Entry; } static unsigned getHashValue(const EditEntry& Val) { -llvm::FoldingSetNodeID ID; -ID.AddPointer(Val.File); -ID.AddInteger(Val.Offset); -ID.AddInteger(Val.RemoveLen); -ID.AddString(Val.Text); -return ID.ComputeHash(); +return (unsigned)llvm::hash_combine(Val.File, Val.Offset, Val.RemoveLen, +Val.Text); } static bool isEqual(const EditEntry &LHS, const EditEntry &RHS) { return LHS.File == RHS.File && ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 51f3432 - Frontend: Clarify logic for using the preamble in ASTUnit::CodeComplete, almost NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-08T12:52:17-08:00 New Revision: 51f3432f4b5217b35dc2694c6e46d6cfc7defad6 URL: https://github.com/llvm/llvm-project/commit/51f3432f4b5217b35dc2694c6e46d6cfc7defad6 DIFF: https://github.com/llvm/llvm-project/commit/51f3432f4b5217b35dc2694c6e46d6cfc7defad6.diff LOG: Frontend: Clarify logic for using the preamble in ASTUnit::CodeComplete, almost NFC Clarify the logic for using the preamble (and overriding the main file buffer) in `ASTUnit::CodeComplete` by factoring out a couple of lambdas (`getUniqueID` and `hasSameUniqueID`). While refactoring the logic, hoist the check for `Line > 1` and locally check if the filenames are equal (both to avoid unnecessary `stat` calls) and skip copying out the filenames to `std::string`. Besides fewer calls to `stat`, there's no functionality change here. Differential Revision: https://reviews.llvm.org/D91296 Added: Modified: clang/lib/Frontend/ASTUnit.cpp Removed: diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index c8ac7eaa9ab8..d9154e9b459e 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -2237,28 +2237,30 @@ void ASTUnit::CodeComplete( = new AugmentedCodeCompleteConsumer(*this, Consumer, CodeCompleteOpts); Clang->setCodeCompletionConsumer(AugmentedConsumer); + auto getUniqueID = + [&FileMgr](StringRef Filename) -> Optional { +if (auto Status = FileMgr.getVirtualFileSystem().status(Filename)) + return Status->getUniqueID(); +return None; + }; + + auto hasSameUniqueID = [getUniqueID](StringRef LHS, StringRef RHS) { +if (LHS == RHS) + return true; +if (auto LHSID = getUniqueID(LHS)) + if (auto RHSID = getUniqueID(RHS)) +return *LHSID == *RHSID; +return false; + }; + // If we have a precompiled preamble, try to use it. We only allow // the use of the precompiled preamble if we're if the completion // point is within the main file, after the end of the precompiled // preamble. std::unique_ptr OverrideMainBuffer; - if (Preamble) { -std::string CompleteFilePath(File); - -auto &VFS = FileMgr.getVirtualFileSystem(); -auto CompleteFileStatus = VFS.status(CompleteFilePath); -if (CompleteFileStatus) { - llvm::sys::fs::UniqueID CompleteFileID = CompleteFileStatus->getUniqueID(); - - std::string MainPath(OriginalSourceFile); - auto MainStatus = VFS.status(MainPath); - if (MainStatus) { -llvm::sys::fs::UniqueID MainID = MainStatus->getUniqueID(); -if (CompleteFileID == MainID && Line > 1) - OverrideMainBuffer = getMainBufferWithPrecompiledPreamble( - PCHContainerOps, Inv, &VFS, false, Line - 1); - } -} + if (Preamble && Line > 1 && hasSameUniqueID(File, OriginalSourceFile)) { +OverrideMainBuffer = getMainBufferWithPrecompiledPreamble( +PCHContainerOps, Inv, &FileMgr.getVirtualFileSystem(), false, Line - 1); } // If the main file has been overridden due to the use of a preamble, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] d126943 - Index: Remove unused internal header SimpleFormatContext.h, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-04T15:10:27-08:00 New Revision: d126943251d0cd77e572bced5ab6c23595acd468 URL: https://github.com/llvm/llvm-project/commit/d126943251d0cd77e572bced5ab6c23595acd468 DIFF: https://github.com/llvm/llvm-project/commit/d126943251d0cd77e572bced5ab6c23595acd468.diff LOG: Index: Remove unused internal header SimpleFormatContext.h, NFC Looks like nothing has included this header since d21485d2f5ffacf7b726c741ee409b3682045255 / r286279 in 2016. Delete the dead code. Added: Modified: clang/lib/Index/CMakeLists.txt llvm/utils/gn/secondary/clang/lib/Index/BUILD.gn Removed: clang/lib/Index/SimpleFormatContext.h diff --git a/clang/lib/Index/CMakeLists.txt b/clang/lib/Index/CMakeLists.txt index 68ebb5b7ede3..68c689b01969 100644 --- a/clang/lib/Index/CMakeLists.txt +++ b/clang/lib/Index/CMakeLists.txt @@ -16,7 +16,6 @@ add_clang_library(clangIndex ADDITIONAL_HEADERS IndexingContext.h - SimpleFormatContext.h LINK_LIBS clangAST diff --git a/clang/lib/Index/SimpleFormatContext.h b/clang/lib/Index/SimpleFormatContext.h deleted file mode 100644 index 17793154a3ae.. --- a/clang/lib/Index/SimpleFormatContext.h +++ /dev/null @@ -1,72 +0,0 @@ -//===--- SimpleFormatContext.h --*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===--===// -// -/// \file -/// -/// Defines a utility class for use of clang-format in libclang -// -//===--===// - -#ifndef LLVM_CLANG_LIB_INDEX_SIMPLEFORMATCONTEXT_H -#define LLVM_CLANG_LIB_INDEX_SIMPLEFORMATCONTEXT_H - -#include "clang/Basic/Diagnostic.h" -#include "clang/Basic/DiagnosticOptions.h" -#include "clang/Basic/FileManager.h" -#include "clang/Basic/LangOptions.h" -#include "clang/Basic/SourceManager.h" -#include "clang/Rewrite/Core/Rewriter.h" -#include "llvm/Support/FileSystem.h" -#include "llvm/Support/Path.h" -#include "llvm/Support/raw_ostream.h" - -namespace clang { -namespace index { - -/// A small class to be used by libclang clients to format -/// a declaration string in memory. This object is instantiated once -/// and used each time a formatting is needed. -class SimpleFormatContext { -public: - SimpleFormatContext(LangOptions Options) - : DiagOpts(new DiagnosticOptions()), -Diagnostics(new DiagnosticsEngine(new DiagnosticIDs, DiagOpts.get())), -InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem), -Files(FileSystemOptions(), InMemoryFileSystem), -Sources(*Diagnostics, Files), Rewrite(Sources, Options) { -Diagnostics->setClient(new IgnoringDiagConsumer, true); - } - - FileID createInMemoryFile(StringRef Name, StringRef Content) { -InMemoryFileSystem->addFile(Name, 0, -llvm::MemoryBuffer::getMemBuffer(Content)); -const FileEntry *Entry = Files.getFile(Name); -assert(Entry != nullptr); -return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User); - } - - std::string getRewrittenText(FileID ID) { -std::string Result; -llvm::raw_string_ostream OS(Result); -Rewrite.getEditBuffer(ID).write(OS); -OS.flush(); -return Result; - } - - IntrusiveRefCntPtr DiagOpts; - IntrusiveRefCntPtr Diagnostics; - IntrusiveRefCntPtr InMemoryFileSystem; - FileManager Files; - SourceManager Sources; - Rewriter Rewrite; -}; - -} // end namespace index -} // end namespace clang - -#endif diff --git a/llvm/utils/gn/secondary/clang/lib/Index/BUILD.gn b/llvm/utils/gn/secondary/clang/lib/Index/BUILD.gn index ef15a55ff9d3..942b4047b8b5 100644 --- a/llvm/utils/gn/secondary/clang/lib/Index/BUILD.gn +++ b/llvm/utils/gn/secondary/clang/lib/Index/BUILD.gn @@ -22,7 +22,6 @@ static_library("Index") { "IndexingAction.cpp", "IndexingContext.cpp", "IndexingContext.h", -"SimpleFormatContext.h", "USRGeneration.cpp", ] } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] b4f4fc6 - ASTImporter: Migrate to the FileEntryRef overload of SourceManager::createFileID, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-04T14:45:59-08:00 New Revision: b4f4fc6872fbe4e296d3270d297a0e4afbda6670 URL: https://github.com/llvm/llvm-project/commit/b4f4fc6872fbe4e296d3270d297a0e4afbda6670 DIFF: https://github.com/llvm/llvm-project/commit/b4f4fc6872fbe4e296d3270d297a0e4afbda6670.diff LOG: ASTImporter: Migrate to the FileEntryRef overload of SourceManager::createFileID, NFC Migrate `ASTImporter::Import` over to using the `FileEntryRef` overload of `SourceManager::createFileID`. No functionality change here. Differential Revision: https://reviews.llvm.org/D92529 Added: Modified: clang/lib/AST/ASTImporter.cpp Removed: diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index a74e316f688e6..50632efc281ff 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -8719,7 +8719,7 @@ Expected ASTImporter::Import(FileID FromID, bool IsBuiltin) { // FIXME: We definitely want to re-use the existing MemoryBuffer, rather // than mmap the files several times. auto Entry = -ToFileManager.getFile(Cache->OrigEntry->getName()); +ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName()); // FIXME: The filename may be a virtual name that does probably not // point to a valid file and we get no Entry here. In this case try with // the memory buffer below. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 9ae0a46 - ARCMigrate: Initialize fields in EditEntry inline, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-04T14:43:22-08:00 New Revision: 9ae0a46f2bbff5c0eb962c5a6225a2b469d1802f URL: https://github.com/llvm/llvm-project/commit/9ae0a46f2bbff5c0eb962c5a6225a2b469d1802f DIFF: https://github.com/llvm/llvm-project/commit/9ae0a46f2bbff5c0eb962c5a6225a2b469d1802f.diff LOG: ARCMigrate: Initialize fields in EditEntry inline, NFC Initialize the fields inline instead of having to manually write out a default constructor. Differential Revision: https://reviews.llvm.org/D92597 Added: Modified: clang/lib/ARCMigrate/ObjCMT.cpp Removed: diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index 51c4a460cc25..ef2985d16d23 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -2034,12 +2034,10 @@ MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { namespace { struct EditEntry { - const FileEntry *File; - unsigned Offset; - unsigned RemoveLen; + const FileEntry *File = nullptr; + unsigned Offset = 0; + unsigned RemoveLen = 0; std::string Text; - - EditEntry() : File(), Offset(), RemoveLen() {} }; } // end anonymous namespace ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 1b023f5 - Frontend: Use translateLineCol instead of translateFileLineCol, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-04T14:37:48-08:00 New Revision: 1b023f54b61737552242868bdfc385487f1c3e74 URL: https://github.com/llvm/llvm-project/commit/1b023f54b61737552242868bdfc385487f1c3e74 DIFF: https://github.com/llvm/llvm-project/commit/1b023f54b61737552242868bdfc385487f1c3e74.diff LOG: Frontend: Use translateLineCol instead of translateFileLineCol, NFC `ParseDirective` in VerifyDiagnosticConsumer.cpp is already calling `translateFile`, so use the `FileID` returned by that to call `translateLineCol` instead of using the more heavyweight `translateFileLineCol`. No functionality change here. Added: Modified: clang/lib/Frontend/VerifyDiagnosticConsumer.cpp Removed: diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp index 35f95ecfec68..a10a3dd8a446 100644 --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -555,14 +555,15 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM, } const FileEntry *FE = &File->getFileEntry(); - if (SM.translateFile(FE).isInvalid()) -SM.createFileID(FE, Pos, SrcMgr::C_User); + FileID FID = SM.translateFile(FE); + if (FID.isInvalid()) +FID = SM.createFileID(FE, Pos, SrcMgr::C_User); if (PH.Next(Line) && Line > 0) -ExpectedLoc = SM.translateFileLineCol(FE, Line, 1); +ExpectedLoc = SM.translateLineCol(FID, Line, 1); else if (PH.Next("*")) { MatchAnyLine = true; -ExpectedLoc = SM.translateFileLineCol(FE, 1, 1); +ExpectedLoc = SM.translateLineCol(FID, 1, 1); } } } else if (PH.Next("*")) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] d10f986 - ADT: Migrate users of AlignedCharArrayUnion to std::aligned_union_t, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-04T12:34:49-08:00 New Revision: d10f9863a5ac1cb681af07719650c44b48f289ce URL: https://github.com/llvm/llvm-project/commit/d10f9863a5ac1cb681af07719650c44b48f289ce DIFF: https://github.com/llvm/llvm-project/commit/d10f9863a5ac1cb681af07719650c44b48f289ce.diff LOG: ADT: Migrate users of AlignedCharArrayUnion to std::aligned_union_t, NFC Prepare to delete `AlignedCharArrayUnion` by migrating its users over to `std::aligned_union_t`. I will delete `AlignedCharArrayUnion` and its tests in a follow-up commit so that it's easier to revert in isolation in case some downstream wants to keep using it. Differential Revision: https://reviews.llvm.org/D92516 Added: Modified: clang/include/clang/AST/APValue.h clang/include/clang/AST/ASTContext.h clang/include/clang/AST/ASTTypeTraits.h clang/include/clang/AST/ParentMapContext.h clang/include/clang/Frontend/PrecompiledPreamble.h clang/include/clang/Sema/Overload.h clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp clang/lib/Lex/PPDirectives.cpp llvm/include/llvm/ADT/DenseMap.h llvm/include/llvm/ADT/IntervalMap.h llvm/include/llvm/CodeGen/DIE.h llvm/include/llvm/CodeGen/SelectionDAGNodes.h llvm/include/llvm/Support/Error.h llvm/include/llvm/Support/ErrorOr.h llvm/include/llvm/Support/JSON.h llvm/include/llvm/Support/TrailingObjects.h llvm/include/llvm/Support/YAMLTraits.h llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp Removed: diff --git a/clang/include/clang/AST/APValue.h b/clang/include/clang/AST/APValue.h index eded34808ad7..d6a33c13b096 100644 --- a/clang/include/clang/AST/APValue.h +++ b/clang/include/clang/AST/APValue.h @@ -20,7 +20,7 @@ #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/PointerUnion.h" -#include "llvm/Support/AlignOf.h" +#include namespace clang { class AddrLabelExpr; @@ -286,9 +286,10 @@ class APValue { struct MemberPointerData; // We ensure elsewhere that Data is big enough for LV and MemberPointerData. - typedef llvm::AlignedCharArrayUnion DataType; + typedef std::aligned_union_t<1, void *, APSInt, APFloat, ComplexAPSInt, + ComplexAPFloat, Vec, Arr, StructData, UnionData, + AddrLabelDiffData> + DataType; static const size_t DataSize = sizeof(DataType); DataType Data; diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 8c0930237583..7d58b426a3df 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -57,7 +57,6 @@ #include "llvm/ADT/TinyPtrVector.h" #include "llvm/ADT/Triple.h" #include "llvm/ADT/iterator_range.h" -#include "llvm/Support/AlignOf.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" diff --git a/clang/include/clang/AST/ASTTypeTraits.h b/clang/include/clang/AST/ASTTypeTraits.h index 8791e41b9ac3..ea3da8d90c5b 100644 --- a/clang/include/clang/AST/ASTTypeTraits.h +++ b/clang/include/clang/AST/ASTTypeTraits.h @@ -22,7 +22,7 @@ #include "clang/AST/TypeLoc.h" #include "clang/Basic/LLVM.h" #include "llvm/ADT/DenseMapInfo.h" -#include "llvm/Support/AlignOf.h" +#include namespace llvm { @@ -456,9 +456,8 @@ class DynTypedNode { /// \c QualTypes, \c NestedNameSpecifierLocs, \c TypeLocs, /// \c TemplateArguments and \c TemplateArgumentLocs on the other hand do not /// have storage or unique pointers and thus need to be stored by value. - llvm::AlignedCharArrayUnion + std::aligned_union_t<1, const void *, TemplateArgument, TemplateArgumentLoc, + NestedNameSpecifierLoc, QualType, TypeLoc> Storage; }; diff --git a/clang/include/clang/AST/ParentMapContext.h b/clang/include/clang/AST/ParentMapContext.h index a0412380a864..a15790605a3d 100644 --- a/clang/include/clang/AST/ParentMapContext.h +++ b/clang/include/clang/AST/ParentMapContext.h @@ -89,7 +89,7 @@ class TraversalKindScope { /// Container for either a single DynTypedNode or for an ArrayRef to /// DynTypedNode. For use with ParentMap. class DynTypedNodeList { - llvm::AlignedCharArrayUnion> Storage; + std::aligned_union_t<1, DynTypedNode, ArrayRef> Storage; bool IsSingleNode; public: diff --git a/clang/include/clang/Frontend/PrecompiledPreamble.h b/clang/include/clang/Frontend/PrecompiledPreamble.h index cea39bfec95d..1f768310d0b2 100644 --- a/clang/include/clang/Frontend/PrecompiledPreamble.h +++ b/clang/include/clang/Frontend/PrecompiledPreamble.h @@ -17,7 +17,6 @@ #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Support/AlignOf.h" #include "llvm/Support/MD5.h" #i
[clang] 5b267fb - ADT: Stop peeking inside AlignedCharArrayUnion, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-04T11:07:42-08:00 New Revision: 5b267fb7966157e0d79ea85cbc1d07f92f840d3c URL: https://github.com/llvm/llvm-project/commit/5b267fb7966157e0d79ea85cbc1d07f92f840d3c DIFF: https://github.com/llvm/llvm-project/commit/5b267fb7966157e0d79ea85cbc1d07f92f840d3c.diff LOG: ADT: Stop peeking inside AlignedCharArrayUnion, NFC Update all the users of `AlignedCharArrayUnion` to stop peeking inside (to look at `buffer`) so that a follow-up patch can replace it with an alias to `std::aligned_union_t`. This was reviewed as part of https://reviews.llvm.org/D92512, but I'm splitting this bit out to commit first to reduce churn in case the change to `AlignedCharArrayUnion` needs to be reverted for some unexpected reason. Added: Modified: clang/include/clang/AST/APValue.h clang/include/clang/AST/ASTTypeTraits.h clang/include/clang/AST/ParentMapContext.h clang/lib/AST/APValue.cpp clang/lib/AST/ASTImporter.cpp clang/lib/Frontend/PrecompiledPreamble.cpp llvm/include/llvm/ADT/DenseMap.h llvm/include/llvm/ADT/IntervalMap.h llvm/include/llvm/CodeGen/DIE.h llvm/include/llvm/Support/Error.h llvm/include/llvm/Support/ErrorOr.h llvm/include/llvm/Support/JSON.h llvm/lib/Support/JSON.cpp llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp Removed: diff --git a/clang/include/clang/AST/APValue.h b/clang/include/clang/AST/APValue.h index d921a106b9f1..eded34808ad7 100644 --- a/clang/include/clang/AST/APValue.h +++ b/clang/include/clang/AST/APValue.h @@ -402,7 +402,7 @@ class APValue { APSInt &getInt() { assert(isInt() && "Invalid accessor"); -return *(APSInt*)(char*)Data.buffer; +return *(APSInt *)(char *)&Data; } const APSInt &getInt() const { return const_cast(this)->getInt(); @@ -416,7 +416,7 @@ class APValue { APFloat &getFloat() { assert(isFloat() && "Invalid accessor"); -return *(APFloat*)(char*)Data.buffer; +return *(APFloat *)(char *)&Data; } const APFloat &getFloat() const { return const_cast(this)->getFloat(); @@ -424,7 +424,7 @@ class APValue { APFixedPoint &getFixedPoint() { assert(isFixedPoint() && "Invalid accessor"); -return *(APFixedPoint *)(char *)Data.buffer; +return *(APFixedPoint *)(char *)&Data; } const APFixedPoint &getFixedPoint() const { return const_cast(this)->getFixedPoint(); @@ -432,7 +432,7 @@ class APValue { APSInt &getComplexIntReal() { assert(isComplexInt() && "Invalid accessor"); -return ((ComplexAPSInt*)(char*)Data.buffer)->Real; +return ((ComplexAPSInt *)(char *)&Data)->Real; } const APSInt &getComplexIntReal() const { return const_cast(this)->getComplexIntReal(); @@ -440,7 +440,7 @@ class APValue { APSInt &getComplexIntImag() { assert(isComplexInt() && "Invalid accessor"); -return ((ComplexAPSInt*)(char*)Data.buffer)->Imag; +return ((ComplexAPSInt *)(char *)&Data)->Imag; } const APSInt &getComplexIntImag() const { return const_cast(this)->getComplexIntImag(); @@ -448,7 +448,7 @@ class APValue { APFloat &getComplexFloatReal() { assert(isComplexFloat() && "Invalid accessor"); -return ((ComplexAPFloat*)(char*)Data.buffer)->Real; +return ((ComplexAPFloat *)(char *)&Data)->Real; } const APFloat &getComplexFloatReal() const { return const_cast(this)->getComplexFloatReal(); @@ -456,7 +456,7 @@ class APValue { APFloat &getComplexFloatImag() { assert(isComplexFloat() && "Invalid accessor"); -return ((ComplexAPFloat*)(char*)Data.buffer)->Imag; +return ((ComplexAPFloat *)(char *)&Data)->Imag; } const APFloat &getComplexFloatImag() const { return const_cast(this)->getComplexFloatImag(); @@ -477,20 +477,20 @@ class APValue { APValue &getVectorElt(unsigned I) { assert(isVector() && "Invalid accessor"); assert(I < getVectorLength() && "Index out of range"); -return ((Vec*)(char*)Data.buffer)->Elts[I]; +return ((Vec *)(char *)&Data)->Elts[I]; } const APValue &getVectorElt(unsigned I) const { return const_cast(this)->getVectorElt(I); } unsigned getVectorLength() const { assert(isVector() && "Invalid accessor"); -return ((const Vec*)(const void *)Data.buffer)->NumElts; +return ((const Vec *)(const void *)&Data)->NumElts; } APValue &getArrayInitializedElt(unsigned I) { assert(isArray() && "Invalid accessor"); assert(I < getArrayInitializedElts() && "Index out of range"); -return ((Arr*)(char*)Data.buffer)->Elts[I]; +return ((Arr *)(char *)&Data)->Elts[I]; } const APValue &getArrayInitializedElt(unsigned I) const { return const_cast(this)->getArrayInitializedElt(I); @@ -501,35 +501,35 @@ class APValue { APValue &getArrayFiller() { assert(isArray() && "Invalid accessor"); assert(hasArrayFiller() && "No array filler"); -
[clang] e763e03 - Support: Change InMemoryFileSystem::addFileNoOwn to take a MemoryBufferRef, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-03T18:09:52-08:00 New Revision: e763e032f8bbf5a4da60d099b1df4cd16e44e139 URL: https://github.com/llvm/llvm-project/commit/e763e032f8bbf5a4da60d099b1df4cd16e44e139 DIFF: https://github.com/llvm/llvm-project/commit/e763e032f8bbf5a4da60d099b1df4cd16e44e139.diff LOG: Support: Change InMemoryFileSystem::addFileNoOwn to take a MemoryBufferRef, NFC Found this by chance when looking at the InMemoryFileSystem API, seems like an easy cleanup. Differential Revision: https://reviews.llvm.org/D90893 Added: Modified: clang/tools/clang-format/ClangFormat.cpp llvm/include/llvm/Support/VirtualFileSystem.h llvm/lib/Support/VirtualFileSystem.cpp llvm/unittests/Support/VirtualFileSystemTest.cpp Removed: diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp index 3a7247deab46..121c9626b261 100644 --- a/clang/tools/clang-format/ClangFormat.cpp +++ b/clang/tools/clang-format/ClangFormat.cpp @@ -174,7 +174,7 @@ static cl::list FileNames(cl::Positional, cl::desc("[ ...]"), namespace clang { namespace format { -static FileID createInMemoryFile(StringRef FileName, MemoryBuffer *Source, +static FileID createInMemoryFile(StringRef FileName, MemoryBufferRef Source, SourceManager &Sources, FileManager &Files, llvm::vfs::InMemoryFileSystem *MemFS) { MemFS->addFileNoOwn(FileName, 0, Source); @@ -201,7 +201,7 @@ static bool fillRanges(MemoryBuffer *Code, IntrusiveRefCntPtr(new DiagnosticIDs), new DiagnosticOptions); SourceManager Sources(Diagnostics, Files); - FileID ID = createInMemoryFile("", Code, Sources, Files, + FileID ID = createInMemoryFile("", *Code, Sources, Files, InMemoryFileSystem.get()); if (!LineRanges.empty()) { if (!Offsets.empty() || !Lengths.empty()) { @@ -427,7 +427,7 @@ static bool format(StringRef FileName) { IntrusiveRefCntPtr(new DiagnosticIDs), new DiagnosticOptions); SourceManager Sources(Diagnostics, Files); -FileID ID = createInMemoryFile(AssumedFileName, Code.get(), Sources, Files, +FileID ID = createInMemoryFile(AssumedFileName, *Code, Sources, Files, InMemoryFileSystem.get()); Rewriter Rewrite(Sources, LangOptions()); tooling::applyAllReplacements(Replaces, Rewrite); diff --git a/llvm/include/llvm/Support/VirtualFileSystem.h b/llvm/include/llvm/Support/VirtualFileSystem.h index 055c0e5dd86f..714bd7ed3050 100644 --- a/llvm/include/llvm/Support/VirtualFileSystem.h +++ b/llvm/include/llvm/Support/VirtualFileSystem.h @@ -37,6 +37,7 @@ namespace llvm { class MemoryBuffer; +class MemoryBufferRef; class Twine; namespace vfs { @@ -463,7 +464,8 @@ class InMemoryFileSystem : public FileSystem { /// false if the file or directory already exists in the file system with /// diff erent contents. bool addFileNoOwn(const Twine &Path, time_t ModificationTime, -llvm::MemoryBuffer *Buffer, Optional User = None, +const llvm::MemoryBufferRef &Buffer, +Optional User = None, Optional Group = None, Optional Type = None, Optional Perms = None); diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index bbde44c30caa..697383d55d88 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -792,14 +792,12 @@ bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime, } bool InMemoryFileSystem::addFileNoOwn(const Twine &P, time_t ModificationTime, - llvm::MemoryBuffer *Buffer, + const llvm::MemoryBufferRef &Buffer, Optional User, Optional Group, Optional Type, Optional Perms) { - return addFile(P, ModificationTime, - llvm::MemoryBuffer::getMemBuffer( - Buffer->getBuffer(), Buffer->getBufferIdentifier()), + return addFile(P, ModificationTime, llvm::MemoryBuffer::getMemBuffer(Buffer), std::move(User), std::move(Group), std::move(Type), std::move(Perms)); } diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp index 64982b9e2160..4cc209de1a50 100644 --- a/llvm/unittests/Support/VirtualFileSystemTest.cpp +++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -939,7 +939,7 @@ TEST_F(InMemoryFileSystemTest, OverlayFile) { TEST_F(InMemoryFileSystemTest, OverlayFileNoOwn) { auto Buf = MemoryBuffer::getMemBuffer("a"
[clang] 99b823c - Frontend: Remove redundant call to CompilerInstance::setFileManager, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-03T16:10:59-08:00 New Revision: 99b823c2eba391877a0fcd6bc5f03f0d9f0077cb URL: https://github.com/llvm/llvm-project/commit/99b823c2eba391877a0fcd6bc5f03f0d9f0077cb DIFF: https://github.com/llvm/llvm-project/commit/99b823c2eba391877a0fcd6bc5f03f0d9f0077cb.diff LOG: Frontend: Remove redundant call to CompilerInstance::setFileManager, NFC `ASTUnit::Parse` sets up the `FileManager` earlier in the same function, ensuring `ASTUnit::getFileManager()` matches `Clang->getFileManager()`. Remove the later call to `setFileManager(getFileManager())` since it does nothing. Differential Revision: https://reviews.llvm.org/D90888 Added: Modified: clang/lib/Frontend/ASTUnit.cpp Removed: diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index c2aba4102361..c8ac7eaa9ab8 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -1186,9 +1186,6 @@ bool ASTUnit::Parse(std::shared_ptr PCHContainerOps, TopLevelDeclsInPreamble.clear(); } - // Create a file manager object to provide access to and cache the filesystem. - Clang->setFileManager(&getFileManager()); - // Create the source manager. Clang->setSourceManager(&getSourceManager()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] b346322 - Revert "Frontend: Sink named pipe logic from CompilerInstance down to FileManager"
Author: Duncan P. N. Exon Smith Date: 2020-12-02T17:36:20-08:00 New Revision: b34632201987eed369bb7ef4646f341b901c95b8 URL: https://github.com/llvm/llvm-project/commit/b34632201987eed369bb7ef4646f341b901c95b8 DIFF: https://github.com/llvm/llvm-project/commit/b34632201987eed369bb7ef4646f341b901c95b8.diff LOG: Revert "Frontend: Sink named pipe logic from CompilerInstance down to FileManager" This reverts commit 3b18a594c7717a328c33b9c1eba675e9f4bd367c, since apparently this doesn't work everywhere. E.g., clang-x86_64-debian-fast/3889 (http://lab.llvm.org:8011/#/builders/109/builds/3889) gives me: ``` + : 'RUN: at line 8' + /b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -x c /dev/fd/0 -E + cat /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Misc/dev-fd-fs.c fatal error: file '/dev/fd/0' modified since it was first processed 1 error generated. ``` Added: Modified: clang/lib/Basic/FileManager.cpp clang/lib/Frontend/CompilerInstance.cpp Removed: diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index f3afe6dd5f48..c0d3685001ee 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -489,7 +489,7 @@ FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile, uint64_t FileSize = Entry->getSize(); // If there's a high enough chance that the file have changed since we // got its size, force a stat before opening it. - if (isVolatile || Entry->isNamedPipe()) + if (isVolatile) FileSize = -1; StringRef Filename = Entry->getName(); diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index e3018b218b76..5c82878d8e21 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -858,8 +858,30 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input, } FileEntryRef File = *FileOrErr; -SourceMgr.setMainFileID( -SourceMgr.createFileID(File, SourceLocation(), Kind)); +// The natural SourceManager infrastructure can't currently handle named +// pipes, but we would at least like to accept them for the main +// file. Detect them here, read them with the volatile flag so FileMgr will +// pick up the correct size, and simply override their contents as we do for +// STDIN. +if (File.getFileEntry().isNamedPipe()) { + auto MB = + FileMgr.getBufferForFile(&File.getFileEntry(), /*isVolatile=*/true); + if (MB) { +// Create a new virtual file that will have the correct size. +const FileEntry *FE = +FileMgr.getVirtualFile(InputFile, (*MB)->getBufferSize(), 0); +SourceMgr.overrideFileContents(FE, std::move(*MB)); +SourceMgr.setMainFileID( +SourceMgr.createFileID(FE, SourceLocation(), Kind)); + } else { +Diags.Report(diag::err_cannot_open_file) << InputFile + << MB.getError().message(); +return false; + } +} else { + SourceMgr.setMainFileID( + SourceMgr.createFileID(File, SourceLocation(), Kind)); +} } else { llvm::ErrorOr> SBOrErr = llvm::MemoryBuffer::getSTDIN(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 3b18a59 - Frontend: Sink named pipe logic from CompilerInstance down to FileManager
Author: Duncan P. N. Exon Smith Date: 2020-12-02T17:14:27-08:00 New Revision: 3b18a594c7717a328c33b9c1eba675e9f4bd367c URL: https://github.com/llvm/llvm-project/commit/3b18a594c7717a328c33b9c1eba675e9f4bd367c DIFF: https://github.com/llvm/llvm-project/commit/3b18a594c7717a328c33b9c1eba675e9f4bd367c.diff LOG: Frontend: Sink named pipe logic from CompilerInstance down to FileManager Remove compilicated logic from CompilerInstance::InitializeSourceManager to deal with named pipes, updating FileManager::getBufferForFile to handle it in a more straightforward way. The existing test at clang/test/Misc/dev-fd-fs.c covers the new behaviour (just like it did the old behaviour). Differential Revision: https://reviews.llvm.org/D90733 Added: Modified: clang/lib/Basic/FileManager.cpp clang/lib/Frontend/CompilerInstance.cpp Removed: diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index c0d3685001ee..f3afe6dd5f48 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -489,7 +489,7 @@ FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile, uint64_t FileSize = Entry->getSize(); // If there's a high enough chance that the file have changed since we // got its size, force a stat before opening it. - if (isVolatile) + if (isVolatile || Entry->isNamedPipe()) FileSize = -1; StringRef Filename = Entry->getName(); diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 5c82878d8e21..e3018b218b76 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -858,30 +858,8 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input, } FileEntryRef File = *FileOrErr; -// The natural SourceManager infrastructure can't currently handle named -// pipes, but we would at least like to accept them for the main -// file. Detect them here, read them with the volatile flag so FileMgr will -// pick up the correct size, and simply override their contents as we do for -// STDIN. -if (File.getFileEntry().isNamedPipe()) { - auto MB = - FileMgr.getBufferForFile(&File.getFileEntry(), /*isVolatile=*/true); - if (MB) { -// Create a new virtual file that will have the correct size. -const FileEntry *FE = -FileMgr.getVirtualFile(InputFile, (*MB)->getBufferSize(), 0); -SourceMgr.overrideFileContents(FE, std::move(*MB)); -SourceMgr.setMainFileID( -SourceMgr.createFileID(FE, SourceLocation(), Kind)); - } else { -Diags.Report(diag::err_cannot_open_file) << InputFile - << MB.getError().message(); -return false; - } -} else { - SourceMgr.setMainFileID( - SourceMgr.createFileID(File, SourceLocation(), Kind)); -} +SourceMgr.setMainFileID( +SourceMgr.createFileID(File, SourceLocation(), Kind)); } else { llvm::ErrorOr> SBOrErr = llvm::MemoryBuffer::getSTDIN(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] dcc4f7f - ARCMigrate: Stop abusing PreprocessorOptions for passing back file remappings, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-02T16:28:33-08:00 New Revision: dcc4f7f3c4b4442710ae73d6f73cded665426678 URL: https://github.com/llvm/llvm-project/commit/dcc4f7f3c4b4442710ae73d6f73cded665426678 DIFF: https://github.com/llvm/llvm-project/commit/dcc4f7f3c4b4442710ae73d6f73cded665426678.diff LOG: ARCMigrate: Stop abusing PreprocessorOptions for passing back file remappings, NFC As part of reducing use of PreprocessorOptions::RemappedFileBuffers, stop abusing it to pass information around remapped files in `ARCMigrate`. This simplifies an eventual follow-up to switch to using an `InMemoryFileSystem` for this. Differential Revision: https://reviews.llvm.org/D90887 Added: Modified: clang/include/clang/ARCMigrate/FileRemapper.h clang/lib/ARCMigrate/ARCMT.cpp clang/lib/ARCMigrate/FileRemapper.cpp clang/tools/arcmt-test/arcmt-test.cpp Removed: diff --git a/clang/include/clang/ARCMigrate/FileRemapper.h b/clang/include/clang/ARCMigrate/FileRemapper.h index 76b65b2f6884..4da68a678be2 100644 --- a/clang/include/clang/ARCMigrate/FileRemapper.h +++ b/clang/include/clang/ARCMigrate/FileRemapper.h @@ -12,11 +12,13 @@ #include "clang/Basic/LLVM.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/PointerUnion.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include namespace llvm { class MemoryBuffer; + class MemoryBufferRef; } namespace clang { @@ -55,6 +57,12 @@ class FileRemapper { void applyMappings(PreprocessorOptions &PPOpts) const; + /// Iterate through all the mappings. + void forEachMapping( + llvm::function_ref CaptureFile, + llvm::function_ref + CaptureBuffer) const; + void clear(StringRef outputDir = StringRef()); private: diff --git a/clang/lib/ARCMigrate/ARCMT.cpp b/clang/lib/ARCMigrate/ARCMT.cpp index e18def8a0b19..36fbe90e1e3a 100644 --- a/clang/lib/ARCMigrate/ARCMT.cpp +++ b/clang/lib/ARCMigrate/ARCMT.cpp @@ -416,9 +416,11 @@ bool arcmt::getFileRemappings(std::vector > & if (err) return true; - PreprocessorOptions PPOpts; - remapper.applyMappings(PPOpts); - remap = PPOpts.RemappedFiles; + remapper.forEachMapping( + [&](StringRef From, StringRef To) { +remap.push_back(std::make_pair(From.str(), To.str())); + }, + [](StringRef, const llvm::MemoryBufferRef &) {}); return false; } diff --git a/clang/lib/ARCMigrate/FileRemapper.cpp b/clang/lib/ARCMigrate/FileRemapper.cpp index 0222583c015b..f536af1795ed 100644 --- a/clang/lib/ARCMigrate/FileRemapper.cpp +++ b/clang/lib/ARCMigrate/FileRemapper.cpp @@ -190,6 +190,21 @@ bool FileRemapper::overwriteOriginal(DiagnosticsEngine &Diag, return false; } +void FileRemapper::forEachMapping( +llvm::function_ref CaptureFile, +llvm::function_ref +CaptureBuffer) const { + for (auto &Mapping : FromToMappings) { +if (const FileEntry *FE = Mapping.second.dyn_cast()) { + CaptureFile(Mapping.first->getName(), FE->getName()); + continue; +} +CaptureBuffer( +Mapping.first->getName(), +Mapping.second.get()->getMemBufferRef()); + } +} + void FileRemapper::applyMappings(PreprocessorOptions &PPOpts) const { for (MappingsTy::const_iterator I = FromToMappings.begin(), E = FromToMappings.end(); I != E; ++I) { diff --git a/clang/tools/arcmt-test/arcmt-test.cpp b/clang/tools/arcmt-test/arcmt-test.cpp index c4ba12d4f7cf..940e622b8a68 100644 --- a/clang/tools/arcmt-test/arcmt-test.cpp +++ b/clang/tools/arcmt-test/arcmt-test.cpp @@ -139,11 +139,10 @@ static bool checkForMigration(StringRef resourcesPath, } static void printResult(FileRemapper &remapper, raw_ostream &OS) { - PreprocessorOptions PPOpts; - remapper.applyMappings(PPOpts); - // The changed files will be in memory buffers, print them. - for (const auto &RB : PPOpts.RemappedFileBuffers) -OS << RB.second->getBuffer(); + remapper.forEachMapping([](StringRef, StringRef) {}, + [&](StringRef, const llvm::MemoryBufferRef &Buffer) { +OS << Buffer.getBuffer(); + }); } static bool performTransformations(StringRef resourcesPath, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 32c501d - Module: Use FileEntryRef and DirectoryEntryRef in Umbrella, Header, and DirectoryName, NFC
Author: Duncan P. N. Exon Smith Date: 2020-12-02T14:07:23-08:00 New Revision: 32c501dd88b62787d3a5ffda7aabcf4650dbe3cd URL: https://github.com/llvm/llvm-project/commit/32c501dd88b62787d3a5ffda7aabcf4650dbe3cd DIFF: https://github.com/llvm/llvm-project/commit/32c501dd88b62787d3a5ffda7aabcf4650dbe3cd.diff LOG: Module: Use FileEntryRef and DirectoryEntryRef in Umbrella, Header, and DirectoryName, NFC Push `FileEntryRef` and `DirectoryEntryRef` further, using it them `Module::Umbrella`, `Module::Header::Entry`, and `Module::DirectoryName::Entry`. - Add `DirectoryEntryRef::operator const DirectoryEntry *` and `OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr`, to get the same "degrades to `DirectoryEntry*` behaviour `FileEntryRef` enjoys (this avoids a bunch of churn in various clang tools). - Fix the `DirectoryEntryRef` constructor from `MapEntry` to take it by `const&`. Note that we cannot get rid of the `...AsWritten` names leveraging the new classes, since these need to be as written in the `ModuleMap` file and the module directory path is preprended for the lookup in the `FileManager`. Differential Revision: https://reviews.llvm.org/D90497 Added: Modified: clang/include/clang/Basic/DirectoryEntry.h clang/include/clang/Basic/Module.h clang/include/clang/Lex/ModuleMap.h clang/lib/Basic/Module.cpp clang/lib/Frontend/FrontendActions.cpp clang/lib/Lex/ModuleMap.cpp clang/lib/Serialization/ASTReader.cpp Removed: diff --git a/clang/include/clang/Basic/DirectoryEntry.h b/clang/include/clang/Basic/DirectoryEntry.h index a6ec5f89aa28..4e229962bdcc 100644 --- a/clang/include/clang/Basic/DirectoryEntry.h +++ b/clang/include/clang/Basic/DirectoryEntry.h @@ -51,7 +51,26 @@ class DirectoryEntryRef { const MapEntry &getMapEntry() const { return *ME; } DirectoryEntryRef() = delete; - DirectoryEntryRef(MapEntry &ME) : ME(&ME) {} + DirectoryEntryRef(const MapEntry &ME) : ME(&ME) {} + + /// Allow DirectoryEntryRef to degrade into 'const DirectoryEntry*' to + /// facilitate incremental adoption. + /// + /// The goal is to avoid code churn due to dances like the following: + /// \code + /// // Old code. + /// lvalue = rvalue; + /// + /// // Temporary code from an incremental patch. + /// lvalue = &rvalue.getDirectoryEntry(); + /// + /// // Final code. + /// lvalue = rvalue; + /// \endcode + /// + /// FIXME: Once DirectoryEntryRef is "everywhere" and DirectoryEntry::getName + /// has been deleted, delete this implicit conversion. + operator const DirectoryEntry *() const { return &getDirEntry(); } private: friend class FileMgr::MapEntryOptionalStorage; @@ -147,4 +166,76 @@ static_assert( } // end namespace optional_detail } // end namespace llvm +namespace clang { + +/// Wrapper around Optional that degrades to 'const +/// DirectoryEntry*', facilitating incremental patches to propagate +/// DirectoryEntryRef. +/// +/// This class can be used as return value or field where it's convenient for +/// an Optional to degrade to a 'const DirectoryEntry*'. The +/// purpose is to avoid code churn due to dances like the following: +/// \code +/// // Old code. +/// lvalue = rvalue; +/// +/// // Temporary code from an incremental patch. +/// Optional MaybeF = rvalue; +/// lvalue = MaybeF ? &MaybeF.getDirectoryEntry() : nullptr; +/// +/// // Final code. +/// lvalue = rvalue; +/// \endcode +/// +/// FIXME: Once DirectoryEntryRef is "everywhere" and DirectoryEntry::LastRef +/// and DirectoryEntry::getName have been deleted, delete this class and +/// replace instances with Optional. +class OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr +: public Optional { +public: + OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr() = default; + OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr( + OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &&) = default; + OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr( + const OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &) = default; + OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr & + operator=(OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &&) = default; + OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr & + operator=(const OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &) = default; + + OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(llvm::NoneType) {} + OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(DirectoryEntryRef Ref) + : Optional(Ref) {} + OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(Optional MaybeRef) + : Optional(MaybeRef) {} + + OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &operator=(llvm::NoneType) { +Optional::operator=(None); +return *this; + } + OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &operator=(DirectoryEntryRef Ref) { +Optional::operator=(Ref); +return *this; + } +
[clang] f85db7f - Lex: Update Module::findHeader to return FileEntryRef, NFC
Author: Duncan P. N. Exon Smith Date: 2020-11-30T17:13:03-08:00 New Revision: f85db7f7ba683b2450892fde247311d7a48adbd0 URL: https://github.com/llvm/llvm-project/commit/f85db7f7ba683b2450892fde247311d7a48adbd0 DIFF: https://github.com/llvm/llvm-project/commit/f85db7f7ba683b2450892fde247311d7a48adbd0.diff LOG: Lex: Update Module::findHeader to return FileEntryRef, NFC Update `Module::findHeader` to return `Optional` and fix its one caller. Differential Revision: https://reviews.llvm.org/D90485 Added: Modified: clang/include/clang/Lex/ModuleMap.h clang/lib/Lex/ModuleMap.cpp Removed: diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h index 5b164039080b..f6423e5b4258 100644 --- a/clang/include/clang/Lex/ModuleMap.h +++ b/clang/include/clang/Lex/ModuleMap.h @@ -328,10 +328,9 @@ class ModuleMap { /// \param NeedsFramework If M is not a framework but a missing header would ///be found in case M was, set it to true. False otherwise. /// \return The resolved file, if any. - const FileEntry *findHeader(Module *M, - const Module::UnresolvedHeaderDirective &Header, - SmallVectorImpl &RelativePathName, - bool &NeedsFramework); + Optional + findHeader(Module *M, const Module::UnresolvedHeaderDirective &Header, + SmallVectorImpl &RelativePathName, bool &NeedsFramework); /// Resolve the given header directive. /// diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index cb49173757d8..28dd7ed969ad 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -171,23 +171,23 @@ static void appendSubframeworkPaths(Module *Mod, llvm::sys::path::append(Path, "Frameworks", Paths[I-1] + ".framework"); } -const FileEntry *ModuleMap::findHeader( +Optional ModuleMap::findHeader( Module *M, const Module::UnresolvedHeaderDirective &Header, SmallVectorImpl &RelativePathName, bool &NeedsFramework) { // Search for the header file within the module's home directory. auto *Directory = M->Directory; SmallString<128> FullPathName(Directory->getName()); - auto GetFile = [&](StringRef Filename) -> const FileEntry * { -auto File = SourceMgr.getFileManager().getFile(Filename); -if (!File || -(Header.Size && (*File)->getSize() != *Header.Size) || -(Header.ModTime && (*File)->getModificationTime() != *Header.ModTime)) - return nullptr; + auto GetFile = [&](StringRef Filename) -> Optional { +auto File = +expectedToOptional(SourceMgr.getFileManager().getFileRef(Filename)); +if (!File || (Header.Size && File->getSize() != *Header.Size) || +(Header.ModTime && File->getModificationTime() != *Header.ModTime)) + return None; return *File; }; - auto GetFrameworkFile = [&]() -> const FileEntry * { + auto GetFrameworkFile = [&]() -> Optional { unsigned FullPathLength = FullPathName.size(); appendSubframeworkPaths(M, RelativePathName); unsigned RelativePathLength = RelativePathName.size(); @@ -195,7 +195,7 @@ const FileEntry *ModuleMap::findHeader( // Check whether this file is in the public headers. llvm::sys::path::append(RelativePathName, "Headers", Header.FileName); llvm::sys::path::append(FullPathName, RelativePathName); -if (auto *File = GetFile(FullPathName)) +if (auto File = GetFile(FullPathName)) return File; // Check whether this file is in the private headers. @@ -227,7 +227,7 @@ const FileEntry *ModuleMap::findHeader( // Lookup for normal headers. llvm::sys::path::append(RelativePathName, Header.FileName); llvm::sys::path::append(FullPathName, RelativePathName); - auto *NormalHdrFile = GetFile(FullPathName); + auto NormalHdrFile = GetFile(FullPathName); if (!NormalHdrFile && Directory->getName().endswith(".framework")) { // The lack of 'framework' keyword in a module declaration it's a simple @@ -241,7 +241,7 @@ const FileEntry *ModuleMap::findHeader( << Header.FileName << M->getFullModuleName(); NeedsFramework = true; } -return nullptr; +return None; } return NormalHdrFile; @@ -251,18 +251,18 @@ void ModuleMap::resolveHeader(Module *Mod, const Module::UnresolvedHeaderDirective &Header, bool &NeedsFramework) { SmallString<128> RelativePathName; - if (const FileEntry *File = + if (Optional File = findHeader(Mod, Header, RelativePathName, NeedsFramework)) { if (Header.IsUmbrella) { - const DirectoryEntry *UmbrellaDir = File->getDir(); + const DirectoryEntry *UmbrellaDir = &File->getDir().getDirEntry(); if (Module *UmbrellaMod = UmbrellaDirs[UmbrellaDir]) Diags.Report(Header.FileNameLoc, diag::err_mmap_umbrella_clash)
[clang] 94f537c - Remove dead code added in ac49500cd0484e1b2dcf37fa4c0dade6f113c2c9, NFC
Author: Duncan P. N. Exon Smith Date: 2020-11-30T14:50:46-08:00 New Revision: 94f537c6b2bb55c8e058a9989d02ab0d68a0c61a URL: https://github.com/llvm/llvm-project/commit/94f537c6b2bb55c8e058a9989d02ab0d68a0c61a DIFF: https://github.com/llvm/llvm-project/commit/94f537c6b2bb55c8e058a9989d02ab0d68a0c61a.diff LOG: Remove dead code added in ac49500cd0484e1b2dcf37fa4c0dade6f113c2c9, NFC This was a copy/paste bug; `M0` is never referenced later. Added: Modified: clang/unittests/Basic/FileEntryTest.cpp Removed: diff --git a/clang/unittests/Basic/FileEntryTest.cpp b/clang/unittests/Basic/FileEntryTest.cpp index b759d3ea36d6..f2619a21def7 100644 --- a/clang/unittests/Basic/FileEntryTest.cpp +++ b/clang/unittests/Basic/FileEntryTest.cpp @@ -92,7 +92,6 @@ TEST(FileEntryTest, equals) { EXPECT_NE(&R2.getFileEntry(), R1); EXPECT_NE(R1, R2); - OptionalFileEntryRefDegradesToFileEntryPtr M0; OptionalFileEntryRefDegradesToFileEntryPtr M1 = R1; EXPECT_EQ(M1, &R1.getFileEntry()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 1b042de - FileManager: Add FileEntryRef::getDir, returning DirectoryEntryRef
Author: Duncan P. N. Exon Smith Date: 2020-11-30T14:50:46-08:00 New Revision: 1b042de5b29af4869a77ecbc632029fba0313dec URL: https://github.com/llvm/llvm-project/commit/1b042de5b29af4869a77ecbc632029fba0313dec DIFF: https://github.com/llvm/llvm-project/commit/1b042de5b29af4869a77ecbc632029fba0313dec.diff LOG: FileManager: Add FileEntryRef::getDir, returning DirectoryEntryRef Add `FileEntryRef::getDir`, which returns a `DirectoryEntryRef`. This includes a few changes: - Customize `OptionalStorage` so that `Optional` is pointer-sized (like the change made to `Optional`). Factored out a common class, `FileMgr::MapEntryOptionalStorage`, to reduce the code duplication. - Store an `Optional` in `FileEntryRef::MapValue`. This is set if and only if `MapValue` has a real `FileEntry`. - Change `FileManager::getFileRef` and `getVirtualFileRef` to use `getDirectoryRef` and store it in the `StringMap` for `FileEntryRef`. Differential Revision: https://reviews.llvm.org/D90484 Added: Modified: clang/include/clang/Basic/DirectoryEntry.h clang/include/clang/Basic/FileEntry.h clang/lib/Basic/FileManager.cpp clang/unittests/Basic/FileEntryTest.cpp Removed: diff --git a/clang/include/clang/Basic/DirectoryEntry.h b/clang/include/clang/Basic/DirectoryEntry.h index 7c634709ca9b..a6ec5f89aa28 100644 --- a/clang/include/clang/Basic/DirectoryEntry.h +++ b/clang/include/clang/Basic/DirectoryEntry.h @@ -20,6 +20,11 @@ #include "llvm/Support/ErrorOr.h" namespace clang { +namespace FileMgr { + +template class MapEntryOptionalStorage; + +} // end namespace FileMgr /// Cached information about one directory (either on disk or in /// the virtual file system). @@ -37,20 +42,109 @@ class DirectoryEntry { /// as it was accessed by the FileManager's client. class DirectoryEntryRef { public: - const DirectoryEntry &getDirEntry() const { return *Entry->getValue(); } + const DirectoryEntry &getDirEntry() const { return *ME->getValue(); } + + StringRef getName() const { return ME->getKey(); } + + using MapEntry = llvm::StringMapEntry>; - StringRef getName() const { return Entry->getKey(); } + const MapEntry &getMapEntry() const { return *ME; } + + DirectoryEntryRef() = delete; + DirectoryEntryRef(MapEntry &ME) : ME(&ME) {} private: - friend class FileManager; + friend class FileMgr::MapEntryOptionalStorage; + struct optional_none_tag {}; - DirectoryEntryRef( - llvm::StringMapEntry> *Entry) - : Entry(Entry) {} + // Private constructor for use by OptionalStorage. + DirectoryEntryRef(optional_none_tag) : ME(nullptr) {} + bool hasOptionalValue() const { return ME; } - const llvm::StringMapEntry> *Entry; + const MapEntry *ME; }; +namespace FileMgr { + +/// Customized storage for refs derived from map entires in FileManager, using +/// the private optional_none_tag to keep it to the size of a single pointer. +template class MapEntryOptionalStorage { + using optional_none_tag = typename RefTy::optional_none_tag; + RefTy MaybeRef; + +public: + MapEntryOptionalStorage() : MaybeRef(optional_none_tag()) {} + + template + explicit MapEntryOptionalStorage(llvm::optional_detail::in_place_t, + ArgTypes &&...Args) + : MaybeRef(std::forward(Args)...) {} + + void reset() { MaybeRef = optional_none_tag(); } + + bool hasValue() const { return MaybeRef.hasOptionalValue(); } + + RefTy &getValue() LLVM_LVALUE_FUNCTION { +assert(hasValue()); +return MaybeRef; + } + RefTy const &getValue() const LLVM_LVALUE_FUNCTION { +assert(hasValue()); +return MaybeRef; + } +#if LLVM_HAS_RVALUE_REFERENCE_THIS + RefTy &&getValue() && { +assert(hasValue()); +return std::move(MaybeRef); + } +#endif + + template void emplace(Args &&...args) { +MaybeRef = RefTy(std::forward(args)...); + } + + MapEntryOptionalStorage &operator=(RefTy Ref) { +MaybeRef = Ref; +return *this; + } +}; + +} // end namespace FileMgr } // end namespace clang +namespace llvm { +namespace optional_detail { + +/// Customize OptionalStorage to use DirectoryEntryRef and +/// its optional_none_tag to keep it the size of a single pointer. +template <> +class OptionalStorage +: public clang::FileMgr::MapEntryOptionalStorage { + using StorageImpl = + clang::FileMgr::MapEntryOptionalStorage; + +public: + OptionalStorage() = default; + + template + explicit OptionalStorage(in_place_t, ArgTypes &&...Args) + : StorageImpl(in_place_t{}, std::forward(Args)...) {} + + OptionalStorage &operator=(clang::DirectoryEntryRef Ref) { +StorageImpl::operator=(Ref); +return *this; + } +}; + +static_assert(sizeof(Optional) == + sizeof(clang::DirectoryEntryRef), + "Optional must avoid size overhead"); + +static_assert( +std::is_trivially_copyable>::value, +"Optional should be trivially copyable"); +
[clang] ac40a2d - Serialization: Change InputFile to use FileEntryRef and add getVirtualFileRef, NFC
Author: Duncan P. N. Exon Smith Date: 2020-11-30T14:04:48-08:00 New Revision: ac40a2d8f16b8a8c68fc811d67f647740e965cb8 URL: https://github.com/llvm/llvm-project/commit/ac40a2d8f16b8a8c68fc811d67f647740e965cb8 DIFF: https://github.com/llvm/llvm-project/commit/ac40a2d8f16b8a8c68fc811d67f647740e965cb8.diff LOG: Serialization: Change InputFile to use FileEntryRef and add getVirtualFileRef, NFC Change the `InputFile` class to store `Optional` instead of `FileEntry*`. This paged in a few API changes: - Added `FileManager::getVirtualFileRef`, and converted `getVirtualFile` to a wrapper of it. - Updated `SourceManager::bypassFileContentsOverride` to take `FileEntryRef` and return `Optional` (`ASTReader::getInputFile` is the only caller). Differential Revision: https://reviews.llvm.org/D90053 Added: Modified: clang/include/clang/Basic/FileManager.h clang/include/clang/Basic/SourceManager.h clang/include/clang/Serialization/ModuleFile.h clang/lib/Basic/FileManager.cpp clang/lib/Basic/SourceManager.cpp clang/lib/Serialization/ASTReader.cpp Removed: diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index d7135a4f0ac3..449aec2b3541 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -239,6 +239,9 @@ class FileManager : public RefCountedBase { /// if there were a file with the given name on disk. /// /// The file itself is not accessed. + FileEntryRef getVirtualFileRef(StringRef Filename, off_t Size, + time_t ModificationTime); + const FileEntry *getVirtualFile(StringRef Filename, off_t Size, time_t ModificationTime); diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index b231644330ed..459bd088f0d7 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -35,6 +35,7 @@ #define LLVM_CLANG_BASIC_SOURCEMANAGER_H #include "clang/Basic/Diagnostic.h" +#include "clang/Basic/FileEntry.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/BitVector.h" @@ -60,8 +61,6 @@ namespace clang { class ASTReader; class ASTWriter; class FileManager; -class FileEntry; -class FileEntryRef; class LineTableInfo; class SourceManager; @@ -982,11 +981,11 @@ class SourceManager : public RefCountedBase { } /// Bypass the overridden contents of a file. This creates a new FileEntry - /// and initializes the content cache for it. Returns nullptr if there is no + /// and initializes the content cache for it. Returns None if there is no /// such file in the filesystem. /// /// This should be called before parsing has begun. - const FileEntry *bypassFileContentsOverride(const FileEntry &File); + Optional bypassFileContentsOverride(FileEntryRef File); /// Specify that a file is transient. void setFileIsTransient(const FileEntry *SourceFile); diff --git a/clang/include/clang/Serialization/ModuleFile.h b/clang/include/clang/Serialization/ModuleFile.h index a309c1143350..a641a26661ae 100644 --- a/clang/include/clang/Serialization/ModuleFile.h +++ b/clang/include/clang/Serialization/ModuleFile.h @@ -67,13 +67,13 @@ class InputFile { OutOfDate = 2, NotFound = 3 }; - llvm::PointerIntPair Val; + llvm::PointerIntPair Val; public: InputFile() = default; - InputFile(const FileEntry *File, -bool isOverridden = false, bool isOutOfDate = false) { + InputFile(FileEntryRef File, bool isOverridden = false, +bool isOutOfDate = false) { assert(!(isOverridden && isOutOfDate) && "an overridden cannot be out-of-date"); unsigned intVal = 0; @@ -81,7 +81,7 @@ class InputFile { intVal = Overridden; else if (isOutOfDate) intVal = OutOfDate; -Val.setPointerAndInt(File, intVal); +Val.setPointerAndInt(&File.getMapEntry(), intVal); } static InputFile getNotFound() { @@ -90,7 +90,11 @@ class InputFile { return File; } - const FileEntry *getFile() const { return Val.getPointer(); } + OptionalFileEntryRefDegradesToFileEntryPtr getFile() const { +if (auto *P = Val.getPointer()) + return FileEntryRef(*P); +return None; + } bool isOverridden() const { return Val.getInt() == Overridden; } bool isOutOfDate() const { return Val.getInt() == OutOfDate; } bool isNotFound() const { return Val.getInt() == NotFound; } diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 38d9403eadb9..ef0c69ae0107 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -335,9 +335,13 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { return ReturnedRef; } -const FileEntry * -Fil
[clang] cfde3ed - Frontend: Remove unused parameter from ASTUnit::LoadFromCompilerInvocationAction, NFC
Author: Duncan P. N. Exon Smith Date: 2020-11-13T17:47:17-05:00 New Revision: cfde3edeae4730aa44642c4835bcfa5a857ea8d4 URL: https://github.com/llvm/llvm-project/commit/cfde3edeae4730aa44642c4835bcfa5a857ea8d4 DIFF: https://github.com/llvm/llvm-project/commit/cfde3edeae4730aa44642c4835bcfa5a857ea8d4.diff LOG: Frontend: Remove unused parameter from ASTUnit::LoadFromCompilerInvocationAction, NFC Drop `IncludeBriefCommentsInCodeCompletion` since it is always `false`. Differential Revision: https://reviews.llvm.org/D91295 Added: Modified: clang/include/clang/Frontend/ASTUnit.h clang/lib/Frontend/ASTUnit.cpp clang/tools/libclang/Indexing.cpp Removed: diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h index 50ab86ebad97..5595b8c7bcae 100644 --- a/clang/include/clang/Frontend/ASTUnit.h +++ b/clang/include/clang/Frontend/ASTUnit.h @@ -756,7 +756,6 @@ class ASTUnit { CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None, unsigned PrecompilePreambleAfterNParses = 0, bool CacheCodeCompletionResults = false, - bool IncludeBriefCommentsInCodeCompletion = false, bool UserFilesAreVolatile = false, std::unique_ptr *ErrAST = nullptr); diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index e1aa3682a2b7..a112117d1c06 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -1520,8 +1520,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction( ASTUnit *Unit, bool Persistent, StringRef ResourceFilesPath, bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics, unsigned PrecompilePreambleAfterNParses, bool CacheCodeCompletionResults, -bool IncludeBriefCommentsInCodeCompletion, bool UserFilesAreVolatile, -std::unique_ptr *ErrAST) { +bool UserFilesAreVolatile, std::unique_ptr *ErrAST) { assert(CI && "A CompilerInvocation is required"); std::unique_ptr OwnAST; @@ -1544,8 +1543,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction( AST->PreambleRebuildCountdown = PrecompilePreambleAfterNParses; AST->TUKind = Action ? Action->getTranslationUnitKind() : TU_Complete; AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults; - AST->IncludeBriefCommentsInCodeCompletion -= IncludeBriefCommentsInCodeCompletion; + AST->IncludeBriefCommentsInCodeCompletion = false; // Recover resources if we crash before exiting this method. llvm::CrashRecoveryContextCleanupRegistrar diff --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp index f0303fdcd825..0e83ec6ca799 100644 --- a/clang/tools/libclang/Indexing.cpp +++ b/clang/tools/libclang/Indexing.cpp @@ -617,9 +617,7 @@ static CXErrorCode clang_indexSourceFile_Impl( std::move(CInvok), CXXIdx->getPCHContainerOperations(), Diags, IndexAction.get(), UPtr, Persistent, CXXIdx->getClangResourcesPath(), OnlyLocalDecls, CaptureDiagnostics, PrecompilePreambleAfterNParses, - CacheCodeCompletionResults, - /*IncludeBriefCommentsInCodeCompletion=*/false, - /*UserFilesAreVolatile=*/true); + CacheCodeCompletionResults, /*UserFilesAreVolatile=*/true); if (DiagTrap.hasErrorOccurred() && CXXIdx->getDisplayDiagnostics()) printDiagsToStderr(UPtr); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] a2f2c2f - Serialization: Merge three diagnostics to simplify ASTReader::getInputFile, NFC
Author: Duncan P. N. Exon Smith Date: 2020-11-13T16:23:04-05:00 New Revision: a2f2c2f3a46351bc5478acd290258d318af2cd88 URL: https://github.com/llvm/llvm-project/commit/a2f2c2f3a46351bc5478acd290258d318af2cd88 DIFF: https://github.com/llvm/llvm-project/commit/a2f2c2f3a46351bc5478acd290258d318af2cd88.diff LOG: Serialization: Merge three diagnostics to simplify ASTReader::getInputFile, NFC Clean up the logic for `err_fe_{pch,module,ast}_file_modified` to use a `select` like other ASTReader diagnostics. There should be no functionality change here, just a cleanup. Differential Revision: https://reviews.llvm.org/D91367 Added: Modified: clang/include/clang/Basic/DiagnosticSerializationKinds.td clang/lib/Serialization/ASTReader.cpp Removed: diff --git a/clang/include/clang/Basic/DiagnosticSerializationKinds.td b/clang/include/clang/Basic/DiagnosticSerializationKinds.td index 2720e85df6f5..ce48833a8703 100644 --- a/clang/include/clang/Basic/DiagnosticSerializationKinds.td +++ b/clang/include/clang/Basic/DiagnosticSerializationKinds.td @@ -17,17 +17,10 @@ def err_fe_pch_malformed : Error< "malformed or corrupted AST file: '%0'">, DefaultFatal; def err_fe_pch_malformed_block : Error< "malformed block record in PCH file: '%0'">, DefaultFatal; -def err_fe_pch_file_modified : Error< -"file '%0' has been modified since the precompiled header '%1' was built" -": %select{size|mtime|content}2 changed">, -DefaultFatal; -def err_fe_module_file_modified : Error< -"file '%0' has been modified since the module file '%1' was built" -": %select{size|mtime|content}2 changed">, -DefaultFatal; def err_fe_ast_file_modified : Error< -"file '%0' has been modified since the AST file '%1' was built" -": %select{size|mtime|content}2 changed">, +"file '%0' has been modified since the " +"%select{precompiled header|module file|AST file}1 '%2' was built" +": %select{size|mtime|content}3 changed">, DefaultFatal; def err_fe_pch_file_overridden : Error< "file '%0' from the precompiled header has been overridden">; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 31831b7a5bfe..600454399f68 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2397,17 +2397,9 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { // The top-level PCH is stale. StringRef TopLevelPCHName(ImportStack.back()->FileName); - unsigned DiagnosticKind = - moduleKindForDiagnostic(ImportStack.back()->Kind); - if (DiagnosticKind == 0) -Diag(diag::err_fe_pch_file_modified) -<< Filename << TopLevelPCHName << FileChange; - else if (DiagnosticKind == 1) -Diag(diag::err_fe_module_file_modified) -<< Filename << TopLevelPCHName << FileChange; - else -Diag(diag::err_fe_ast_file_modified) -<< Filename << TopLevelPCHName << FileChange; + Diag(diag::err_fe_ast_file_modified) + << Filename << moduleKindForDiagnostic(ImportStack.back()->Kind) + << TopLevelPCHName << FileChange; // Print the import stack. if (ImportStack.size() > 1) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] b764a62 - Serialization: Rename three AST diagnostics, NFC
Author: Duncan P. N. Exon Smith Date: 2020-11-13T14:09:00-05:00 New Revision: b764a62f02e146bed96cf2231bd1db2d9d4fb72c URL: https://github.com/llvm/llvm-project/commit/b764a62f02e146bed96cf2231bd1db2d9d4fb72c DIFF: https://github.com/llvm/llvm-project/commit/b764a62f02e146bed96cf2231bd1db2d9d4fb72c.diff LOG: Serialization: Rename three AST diagnostics, NFC All three diagnostics have a select between "PCH", "module", and "AST" in the text. The most generic of these is "AST", so rename them from `err_module_...` to `err_ast_...`. Differential Revision: https://reviews.llvm.org/D91436 Added: Modified: clang/include/clang/Basic/DiagnosticSerializationKinds.td clang/lib/Serialization/ASTReader.cpp Removed: diff --git a/clang/include/clang/Basic/DiagnosticSerializationKinds.td b/clang/include/clang/Basic/DiagnosticSerializationKinds.td index f46470c3f..2720e85df6f5f 100644 --- a/clang/include/clang/Basic/DiagnosticSerializationKinds.td +++ b/clang/include/clang/Basic/DiagnosticSerializationKinds.td @@ -63,12 +63,12 @@ def err_pch_with_compiler_errors : Error< def err_module_file_conflict : Error< "module '%0' is defined in both '%1' and '%2'">, DefaultFatal; -def err_module_file_not_found : Error< +def err_ast_file_not_found : Error< "%select{PCH|module|AST}0 file '%1' not found%select{|: %3}2">, DefaultFatal; -def err_module_file_out_of_date : Error< +def err_ast_file_out_of_date : Error< "%select{PCH|module|AST}0 file '%1' is out of date and " "needs to be rebuilt%select{|: %3}2">, DefaultFatal; -def err_module_file_invalid : Error< +def err_ast_file_invalid : Error< "file '%1' is not a valid precompiled %select{PCH|module|AST}0 file">, DefaultFatal; def note_module_file_imported_by : Note< "imported by %select{|module '%2' in }1'%0'">; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 6e09fa464940a..31831b7a5bfe2 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -4505,9 +4505,9 @@ ASTReader::ReadASTCore(StringRef FileName, return Missing; // Otherwise, return an error. -Diag(diag::err_module_file_not_found) << moduleKindForDiagnostic(Type) - << FileName << !ErrorStr.empty() - << ErrorStr; +Diag(diag::err_ast_file_not_found) +<< moduleKindForDiagnostic(Type) << FileName << !ErrorStr.empty() +<< ErrorStr; return Failure; case ModuleManager::OutOfDate: @@ -4517,9 +4517,9 @@ ASTReader::ReadASTCore(StringRef FileName, return OutOfDate; // Otherwise, return an error. -Diag(diag::err_module_file_out_of_date) << moduleKindForDiagnostic(Type) -<< FileName << !ErrorStr.empty() -<< ErrorStr; +Diag(diag::err_ast_file_out_of_date) +<< moduleKindForDiagnostic(Type) << FileName << !ErrorStr.empty() +<< ErrorStr; return Failure; } @@ -4540,7 +4540,7 @@ ASTReader::ReadASTCore(StringRef FileName, // Sniff for the signature. if (llvm::Error Err = doesntStartWithASTFileMagic(Stream)) { -Diag(diag::err_module_file_invalid) +Diag(diag::err_ast_file_invalid) << moduleKindForDiagnostic(Type) << FileName << std::move(Err); return Failure; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] d87fd09 - Serialization: Hoist the check for in-flight diagnostics in ASTReader::getInputFile, NFC
Author: Duncan P. N. Exon Smith Date: 2020-11-13T13:26:37-05:00 New Revision: d87fd096ac3eb27f376c0182ed5e3034ce240861 URL: https://github.com/llvm/llvm-project/commit/d87fd096ac3eb27f376c0182ed5e3034ce240861 DIFF: https://github.com/llvm/llvm-project/commit/d87fd096ac3eb27f376c0182ed5e3034ce240861.diff LOG: Serialization: Hoist the check for in-flight diagnostics in ASTReader::getInputFile, NFC This logic seems easier to follow without the `Error()` helper, and checking `DiagnosticsEngine::isDiagnosticInFlight` just once up front. Differential Revision: https://reviews.llvm.org/D91366 Added: Modified: clang/include/clang/Serialization/ASTReader.h clang/lib/Serialization/ASTReader.cpp Removed: diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index 29c4f15e57b0..94491e45b55b 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -1450,8 +1450,6 @@ class ASTReader void Error(StringRef Msg) const; void Error(unsigned DiagID, StringRef Arg1 = StringRef(), StringRef Arg2 = StringRef(), StringRef Arg3 = StringRef()) const; - void Error(unsigned DiagID, StringRef Arg1, StringRef Arg2, - unsigned Select) const; void Error(llvm::Error &&Err) const; public: diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index f3ecb1e51368..6e09fa464940 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1246,12 +1246,6 @@ void ASTReader::Error(unsigned DiagID, StringRef Arg1, StringRef Arg2, Diag(DiagID) << Arg1 << Arg2 << Arg3; } -void ASTReader::Error(unsigned DiagID, StringRef Arg1, StringRef Arg2, - unsigned Select) const { - if (!Diags.isDiagnosticInFlight()) -Diag(DiagID) << Arg1 << Arg2 << Select; -} - void ASTReader::Error(llvm::Error &&Err) const { Error(toString(std::move(Err))); } @@ -2395,7 +2389,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { auto FileChange = HasInputFileChanged(); // For an overridden file, there is nothing to validate. if (!Overridden && FileChange != ModificationType::None) { -if (Complain) { +if (Complain && !Diags.isDiagnosticInFlight()) { // Build a list of the PCH imports that got us here (in reverse). SmallVector ImportStack(1, &F); while (!ImportStack.back()->ImportedBy.empty()) @@ -2406,17 +2400,17 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { unsigned DiagnosticKind = moduleKindForDiagnostic(ImportStack.back()->Kind); if (DiagnosticKind == 0) -Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName, - (unsigned)FileChange); +Diag(diag::err_fe_pch_file_modified) +<< Filename << TopLevelPCHName << FileChange; else if (DiagnosticKind == 1) -Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName, - (unsigned)FileChange); +Diag(diag::err_fe_module_file_modified) +<< Filename << TopLevelPCHName << FileChange; else -Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName, - (unsigned)FileChange); +Diag(diag::err_fe_ast_file_modified) +<< Filename << TopLevelPCHName << FileChange; // Print the import stack. - if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) { + if (ImportStack.size() > 1) { Diag(diag::note_pch_required_by) << Filename << ImportStack[0]->FileName; for (unsigned I = 1; I < ImportStack.size(); ++I) @@ -2424,8 +2418,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { << ImportStack[I-1]->FileName << ImportStack[I]->FileName; } - if (!Diags.isDiagnosticInFlight()) -Diag(diag::note_pch_rebuild_required) << TopLevelPCHName; + Diag(diag::note_pch_rebuild_required) << TopLevelPCHName; } IsOutOfDate = true; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 4c55c3b - Frontend: Change ComputePreambleBounds to take MemoryBufferRef, NFC
Author: Duncan P. N. Exon Smith Date: 2020-11-11T17:19:51-05:00 New Revision: 4c55c3b66dea3a1d6058392e1e96e166d318a2ff URL: https://github.com/llvm/llvm-project/commit/4c55c3b66dea3a1d6058392e1e96e166d318a2ff DIFF: https://github.com/llvm/llvm-project/commit/4c55c3b66dea3a1d6058392e1e96e166d318a2ff.diff LOG: Frontend: Change ComputePreambleBounds to take MemoryBufferRef, NFC Avoid requiring an actual MemoryBuffer in ComputePreambleBounds, when a MemoryBufferRef will do just fine. Differential Revision: https://reviews.llvm.org/D90890 Added: Modified: clang-tools-extra/clangd/CodeComplete.cpp clang-tools-extra/clangd/Preamble.cpp clang/include/clang/Frontend/PrecompiledPreamble.h clang/lib/Frontend/ASTUnit.cpp clang/lib/Frontend/PrecompiledPreamble.cpp Removed: diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index 24678a3cc1bc..1d85439f53af 100644 --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -1104,7 +1104,7 @@ bool semaCodeComplete(std::unique_ptr Consumer, // overriding the preamble will break sema completion. Fortunately we can just // skip all includes in this case; these completions are really simple. PreambleBounds PreambleRegion = - ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0); + ComputePreambleBounds(*CI->getLangOpts(), *ContentsBuffer, 0); bool CompletingInPreamble = PreambleRegion.Size > Input.Offset; if (Input.Patch) Input.Patch->apply(*CI); diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp index 8e1ad7242eb0..f4f82be81cde 100644 --- a/clang-tools-extra/clangd/Preamble.cpp +++ b/clang-tools-extra/clangd/Preamble.cpp @@ -249,8 +249,7 @@ scanPreamble(llvm::StringRef Contents, const tooling::CompileCommand &Cmd) { // This means we're scanning (though not preprocessing) the preamble section // twice. However, it's important to precisely follow the preamble bounds used // elsewhere. - auto Bounds = - ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0); + auto Bounds = ComputePreambleBounds(*CI->getLangOpts(), *ContentsBuffer, 0); auto PreambleContents = llvm::MemoryBuffer::getMemBufferCopy(Contents.substr(0, Bounds.Size)); auto Clang = prepareCompilerInstance( @@ -322,8 +321,7 @@ buildPreamble(PathRef FileName, CompilerInvocation CI, // without those. auto ContentsBuffer = llvm::MemoryBuffer::getMemBuffer(Inputs.Contents, FileName); - auto Bounds = - ComputePreambleBounds(*CI.getLangOpts(), ContentsBuffer.get(), 0); + auto Bounds = ComputePreambleBounds(*CI.getLangOpts(), *ContentsBuffer, 0); trace::Span Tracer("BuildPreamble"); SPAN_ATTACH(Tracer, "File", FileName); @@ -376,8 +374,7 @@ bool isPreambleCompatible(const PreambleData &Preamble, const CompilerInvocation &CI) { auto ContentsBuffer = llvm::MemoryBuffer::getMemBuffer(Inputs.Contents, FileName); - auto Bounds = - ComputePreambleBounds(*CI.getLangOpts(), ContentsBuffer.get(), 0); + auto Bounds = ComputePreambleBounds(*CI.getLangOpts(), *ContentsBuffer, 0); auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory); return compileCommandsAreEqual(Inputs.CompileCommand, Preamble.CompileCommand) && diff --git a/clang/include/clang/Frontend/PrecompiledPreamble.h b/clang/include/clang/Frontend/PrecompiledPreamble.h index 99faf60f1a44..cea39bfec95d 100644 --- a/clang/include/clang/Frontend/PrecompiledPreamble.h +++ b/clang/include/clang/Frontend/PrecompiledPreamble.h @@ -41,7 +41,7 @@ class PCHContainerOperations; /// Runs lexer to compute suggested preamble bounds. PreambleBounds ComputePreambleBounds(const LangOptions &LangOpts, - const llvm::MemoryBuffer *Buffer, + const llvm::MemoryBufferRef &Buffer, unsigned MaxLines); class PreambleCallbacks; diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 0728fee49d78..e1aa3682a2b7 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -1317,9 +1317,8 @@ ASTUnit::getMainBufferWithPrecompiledPreamble( if (!MainFileBuffer) return nullptr; - PreambleBounds Bounds = - ComputePreambleBounds(*PreambleInvocationIn.getLangOpts(), -MainFileBuffer.get(), MaxLines); + PreambleBounds Bounds = ComputePreambleBounds( + *PreambleInvocationIn.getLangOpts(), *MainFileBuffer, MaxLines); if (!Bounds.Size) return nullptr; diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp index 87cd9169c78c..0f4259900ec2 100644 --- a/clang/lib/Frontend/PrecompiledPreamble
[clang] 4e9af3d - Frontend: Skip namespace around createVFSFromCompilerInvocation definition, NFC
Author: Duncan P. N. Exon Smith Date: 2020-11-11T16:15:06-05:00 New Revision: 4e9af3d47847c68b0ffa8a062ae029702b06214d URL: https://github.com/llvm/llvm-project/commit/4e9af3d47847c68b0ffa8a062ae029702b06214d DIFF: https://github.com/llvm/llvm-project/commit/4e9af3d47847c68b0ffa8a062ae029702b06214d.diff LOG: Frontend: Skip namespace around createVFSFromCompilerInvocation definition, NFC Qualify definitions with `clang::` rather than opening/closing a namespace. Differential Revision: https://reviews.llvm.org/D90957 Added: Modified: clang/lib/Frontend/CompilerInvocation.cpp Removed: diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index d3516f5bf1a4..b2ce88f6cf6b 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4024,16 +4024,15 @@ void CompilerInvocation::generateCC1CommandLine( #undef OPTION_WITH_MARSHALLING_FLAG } -namespace clang { - IntrusiveRefCntPtr -createVFSFromCompilerInvocation(const CompilerInvocation &CI, -DiagnosticsEngine &Diags) { +clang::createVFSFromCompilerInvocation(const CompilerInvocation &CI, + DiagnosticsEngine &Diags) { return createVFSFromCompilerInvocation(CI, Diags, llvm::vfs::getRealFileSystem()); } -IntrusiveRefCntPtr createVFSFromCompilerInvocation( +IntrusiveRefCntPtr +clang::createVFSFromCompilerInvocation( const CompilerInvocation &CI, DiagnosticsEngine &Diags, IntrusiveRefCntPtr BaseFS) { if (CI.getHeaderSearchOpts().VFSOverlayFiles.empty()) @@ -4061,5 +4060,3 @@ IntrusiveRefCntPtr createVFSFromCompilerInvocation( } return Result; } - -} // namespace clang ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] dbfa69c - Port some floating point options to new option marshalling infrastructure
Author: Jan Svoboda Date: 2020-11-09T18:00:10-05:00 New Revision: dbfa69c5024cfe58b8029a3766ec46c857cddb1e URL: https://github.com/llvm/llvm-project/commit/dbfa69c5024cfe58b8029a3766ec46c857cddb1e DIFF: https://github.com/llvm/llvm-project/commit/dbfa69c5024cfe58b8029a3766ec46c857cddb1e.diff LOG: Port some floating point options to new option marshalling infrastructure This ports a number of OpenCL and fast-math flags for floating point over to the new marshalling infrastructure. As part of this, `Opt{In,Out}FFlag` were enhanced to allow other flags to imply them, via `DefaultAnyOf<>`. For example: ``` defm signed_zeros : OptOutFFlag<"signed-zeros", ..., "LangOpts->NoSignedZero", DefaultAnyOf<[cl_no_signed_zeros, menable_unsafe_fp_math]>>; ``` defines `-fsigned-zeros` (`false`) and `-fno-signed-zeros` (`true`) linked to the keypath `LangOpts->NoSignedZero`, defaulting to `false`, but set to `true` implicitly if one of `-cl-no-signed-zeros` or `-menable-unsafe-fp-math` is on. Note that the initial patch was written Daniel Grumberg. Differential Revision: https://reviews.llvm.org/D82756 Added: llvm/unittests/Option/OptionMarshallingTest.cpp Modified: clang/include/clang/Basic/LangOptions.def clang/include/clang/Driver/Options.td clang/lib/Frontend/CompilerInvocation.cpp clang/unittests/Frontend/CompilerInvocationTest.cpp llvm/include/llvm/Option/OptParser.td llvm/unittests/Option/CMakeLists.txt llvm/unittests/Option/Opts.td llvm/utils/TableGen/OptParserEmitter.cpp Removed: diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 1d203f8489eb..3788ae87f6b9 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -274,6 +274,9 @@ BENIGN_LANGOPT(DebuggerObjCLiteral , 1, 0, "debugger Objective-C literals and su BENIGN_LANGOPT(SpellChecking , 1, 1, "spell-checking") LANGOPT(SinglePrecisionConstants , 1, 0, "treating double-precision floating point constants as single precision constants") LANGOPT(FastRelaxedMath , 1, 0, "OpenCL fast relaxed math") +BENIGN_LANGOPT(CLNoSignedZero , 1, 0, "Permit Floating Point optimization without regard to signed zeros") +COMPATIBLE_LANGOPT(CLUnsafeMath , 1, 0, "Unsafe Floating Point Math") +COMPATIBLE_LANGOPT(CLFiniteMathOnly , 1, 0, "__FINITE_MATH_ONLY__ predefined macro") /// FP_CONTRACT mode (on/off/fast). BENIGN_ENUM_LANGOPT(DefaultFPContractMode, FPModeKind, 2, FPM_Off, "FP contraction type") COMPATIBLE_LANGOPT(ExpStrictFP, 1, false, "Enable experimental strict floating point") diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 33cfa72c0888..e13946f98ea4 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -245,9 +245,11 @@ def clang_ignored_gcc_optimization_f_Group : OptionGroup< // Args.hasArg(OPT_ffoo) is used to check that the flag is enabled. // This is useful if the option is usually disabled. multiclass OptInFFlag flags=[]> { + string help="", list flags=[], code keypath="", + DefaultAnyOf defaults = DefaultAnyOf<[]>> { def f#NAME : Flag<["-"], "f"#name>, Flags, - Group, HelpText; + Group, HelpText, + MarshallingInfoFlag; def fno_#NAME : Flag<["-"], "fno-"#name>, Flags, Group, HelpText; } @@ -255,11 +257,13 @@ multiclass OptInFFlag flags=[]> { + string help="", list flags=[], code keypath="", + DefaultAnyOf defaults = DefaultAnyOf<[]>> { def f#NAME : Flag<["-"], "f"#name>, Flags, Group, HelpText; def fno_#NAME : Flag<["-"], "fno-"#name>, Flags, - Group, HelpText; + Group, HelpText, + MarshallingInfoFlag; } / @@ -563,27 +567,36 @@ def cl_opt_disable : Flag<["-"], "cl-opt-disable">, Group, Flags<[ def cl_strict_aliasing : Flag<["-"], "cl-strict-aliasing">, Group, Flags<[CC1Option]>, HelpText<"OpenCL only. This option is added for compatibility with OpenCL 1.0.">; def cl_single_precision_constant : Flag<["-"], "cl-single-precision-constant">, Group, Flags<[CC1Option]>, - HelpText<"OpenCL only. Treat double precision floating-point constant as single precision constant.">; + HelpText<"OpenCL only. Treat double precision floating-point constant as single precision constant.">, + MarshallingInfoFlag<"LangOpts->SinglePrecisionConstants">; def cl_finite_math_only : Flag<["-"], "cl-finite-math-only">, Group, Flags<[CC1Option]>, - HelpText<"OpenCL only. Allow floating-point optimizations that assume arguments and results are not NaNs or +-Inf.">; + HelpText<"OpenCL only. Allow floating-point optimizations that assume arguments and results are not NaNs or +-Inf.">, + MarshallingInfoFlag<"L
[clang] c56ec7b - Tooling: Remove dead code for ToolingInvocation::mapVirtualFile
Author: Duncan P. N. Exon Smith Date: 2020-11-09T15:45:35-05:00 New Revision: c56ec7bedeb8b90cfef4c3ea8db3addfa34fde68 URL: https://github.com/llvm/llvm-project/commit/c56ec7bedeb8b90cfef4c3ea8db3addfa34fde68 DIFF: https://github.com/llvm/llvm-project/commit/c56ec7bedeb8b90cfef4c3ea8db3addfa34fde68.diff LOG: Tooling: Remove dead code for ToolingInvocation::mapVirtualFile Follows through on c4cb3b10dc8c50e46c9fb1b7ae95e3c3c94975d3's FIXME dating back to 2015. Anyone using this should migrate to InMemoryFileSystem and/or ClangTool::mapVirtualFile. Differential Revision: https://reviews.llvm.org/D90885 Added: Modified: clang/include/clang/Tooling/Tooling.h clang/lib/Tooling/Tooling.cpp Removed: diff --git a/clang/include/clang/Tooling/Tooling.h b/clang/include/clang/Tooling/Tooling.h index 4fb0c18be95e..8b3b2e5ad002 100644 --- a/clang/include/clang/Tooling/Tooling.h +++ b/clang/include/clang/Tooling/Tooling.h @@ -265,21 +265,12 @@ class ToolInvocation { this->DiagConsumer = DiagConsumer; } - /// Map a virtual file to be used while running the tool. - /// - /// \param FilePath The path at which the content will be mapped. - /// \param Content A null terminated buffer of the file's content. - // FIXME: remove this when all users have migrated! - void mapVirtualFile(StringRef FilePath, StringRef Content); - /// Run the clang invocation. /// /// \returns True if there were no errors during execution. bool run(); private: - void addFileMappingsTo(SourceManager &SourceManager); - bool runInvocation(const char *BinaryName, driver::Compilation *Compilation, std::shared_ptr Invocation, @@ -290,8 +281,6 @@ class ToolInvocation { bool OwnsAction; FileManager *Files; std::shared_ptr PCHContainerOps; - // Maps -> . - llvm::StringMap MappedFileContents; DiagnosticConsumer *DiagConsumer = nullptr; }; diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp index b0d3f5caf67a..063f4df2da5f 100644 --- a/clang/lib/Tooling/Tooling.cpp +++ b/clang/lib/Tooling/Tooling.cpp @@ -319,12 +319,6 @@ ToolInvocation::~ToolInvocation() { delete Action; } -void ToolInvocation::mapVirtualFile(StringRef FilePath, StringRef Content) { - SmallString<1024> PathStorage; - llvm::sys::path::native(FilePath, PathStorage); - MappedFileContents[PathStorage] = Content; -} - bool ToolInvocation::run() { std::vector Argv; for (const std::string &Str : CommandLine) @@ -359,14 +353,6 @@ bool ToolInvocation::run() { return false; std::unique_ptr Invocation( newInvocation(&Diagnostics, *CC1Args, BinaryName)); - // FIXME: remove this when all users have migrated! - for (const auto &It : MappedFileContents) { -// Inject the code as the given file name into the preprocessor options. -std::unique_ptr Input = -llvm::MemoryBuffer::getMemBuffer(It.getValue()); -Invocation->getPreprocessorOpts().addRemappedFile(It.getKey(), - Input.release()); - } return runInvocation(BinaryName, Compilation.get(), std::move(Invocation), std::move(PCHContainerOps)); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6e73cfa - Basic: Change Module::Umbrella to a PointerUnion, NFC
Author: Duncan P. N. Exon Smith Date: 2020-11-04T16:19:39-05:00 New Revision: 6e73cfa8363d43689f77b0e4e4c2787ae6ae3fb6 URL: https://github.com/llvm/llvm-project/commit/6e73cfa8363d43689f77b0e4e4c2787ae6ae3fb6 DIFF: https://github.com/llvm/llvm-project/commit/6e73cfa8363d43689f77b0e4e4c2787ae6ae3fb6.diff LOG: Basic: Change Module::Umbrella to a PointerUnion, NFC Change `Module::Umbrella` from a `const void *` to a `PointerUnion` of `FileEntry` and `DirectoryEntry`. We can drop the `HasUmbrellaDir` bit (since `PointerUnion` includes that). This change makes it safer to update to `FileEntryRef` and `DirectoryEntryRef` in a future patch. Differential Revision: https://reviews.llvm.org/D90481 Added: Modified: clang/include/clang/Basic/Module.h clang/lib/Basic/Module.cpp clang/lib/Lex/ModuleMap.cpp Removed: diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h index 5a4975f25b72..82ea1f462949 100644 --- a/clang/include/clang/Basic/Module.h +++ b/clang/include/clang/Basic/Module.h @@ -15,6 +15,7 @@ #ifndef LLVM_CLANG_BASIC_MODULE_H #define LLVM_CLANG_BASIC_MODULE_H +#include "clang/Basic/DirectoryEntry.h" #include "clang/Basic/FileEntry.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/ArrayRef.h" @@ -44,8 +45,6 @@ class raw_ostream; namespace clang { -class DirectoryEntry; -class FileEntry; class FileManager; class LangOptions; class TargetInfo; @@ -134,7 +133,7 @@ class Module { std::string PresumedModuleMapFile; /// The umbrella header or directory. - const void *Umbrella = nullptr; + llvm::PointerUnion Umbrella; /// The module signature. ASTFileSignature Signature; @@ -303,9 +302,6 @@ class Module { /// to a regular (public) module map. unsigned ModuleMapIsPrivate : 1; - /// Whether Umbrella is a directory or header. - unsigned HasUmbrellaDir : 1; - /// Describes the visibility of the various names within a /// particular module. enum NameVisibilityKind { @@ -548,15 +544,16 @@ class Module { /// Retrieve the header that serves as the umbrella header for this /// module. Header getUmbrellaHeader() const { -if (!HasUmbrellaDir) - return Header{UmbrellaAsWritten, -static_cast(Umbrella)}; +if (auto *FE = Umbrella.dyn_cast()) + return Header{UmbrellaAsWritten, FE}; return Header{}; } /// Determine whether this module has an umbrella directory that is /// not based on an umbrella header. - bool hasUmbrellaDir() const { return Umbrella && HasUmbrellaDir; } + bool hasUmbrellaDir() const { +return Umbrella && Umbrella.is(); + } /// Add a top-level header associated with this module. void addTopHeader(const FileEntry *File); diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp index 68c1d0f77f22..8a8c400c9503 100644 --- a/clang/lib/Basic/Module.cpp +++ b/clang/lib/Basic/Module.cpp @@ -44,7 +44,7 @@ Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, InferSubmodules(false), InferExplicitSubmodules(false), InferExportWildcard(false), ConfigMacrosExhaustive(false), NoUndeclaredIncludes(false), ModuleMapIsPrivate(false), - HasUmbrellaDir(false), NameVisibility(Hidden) { + NameVisibility(Hidden) { if (Parent) { IsAvailable = Parent->isAvailable(); IsUnimportable = Parent->isUnimportable(); @@ -247,7 +247,7 @@ Module::DirectoryName Module::getUmbrellaDir() const { if (Header U = getUmbrellaHeader()) return {"", U.Entry->getDir()}; - return {UmbrellaAsWritten, static_cast(Umbrella)}; + return {UmbrellaAsWritten, Umbrella.dyn_cast()}; } void Module::addTopHeader(const FileEntry *File) { diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index c47a3a0f14c4..cb49173757d8 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -1125,7 +1125,6 @@ void ModuleMap::setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader, Twine NameAsWritten) { Headers[UmbrellaHeader].push_back(KnownHeader(Mod, NormalHeader)); Mod->Umbrella = UmbrellaHeader; - Mod->HasUmbrellaDir = false; Mod->UmbrellaAsWritten = NameAsWritten.str(); UmbrellaDirs[UmbrellaHeader->getDir()] = Mod; @@ -1137,7 +1136,6 @@ void ModuleMap::setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader, void ModuleMap::setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir, Twine NameAsWritten) { Mod->Umbrella = UmbrellaDir; - Mod->HasUmbrellaDir = true; Mod->UmbrellaAsWritten = NameAsWritten.str(); UmbrellaDirs[UmbrellaDir] = Mod; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 77a9e0a - Basic: Split out DirectoryEntry.h, NFC
Author: Duncan P. N. Exon Smith Date: 2020-11-04T14:11:57-05:00 New Revision: 77a9e0a4af5aea3795ed79a0db61ee5b19b837e4 URL: https://github.com/llvm/llvm-project/commit/77a9e0a4af5aea3795ed79a0db61ee5b19b837e4 DIFF: https://github.com/llvm/llvm-project/commit/77a9e0a4af5aea3795ed79a0db61ee5b19b837e4.diff LOG: Basic: Split out DirectoryEntry.h, NFC Move `DirectoryEntry` and `DirectoryEntryRef` into their own header, similar to the creation of FileEntry.h. No functionality change here, just preparing to include it in more places to allow wider adoption of `DirectoryEntryRef` without requiring all of `FileManager.h`. Differential Revision: https://reviews.llvm.org/D90478 Added: clang/include/clang/Basic/DirectoryEntry.h Modified: clang/include/clang/Basic/FileManager.h Removed: diff --git a/clang/include/clang/Basic/DirectoryEntry.h b/clang/include/clang/Basic/DirectoryEntry.h new file mode 100644 index ..7c634709ca9b --- /dev/null +++ b/clang/include/clang/Basic/DirectoryEntry.h @@ -0,0 +1,56 @@ +//===- clang/Basic/DirectoryEntry.h - Directory references --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +/// +/// \file +/// Defines interfaces for clang::DirectoryEntry and clang::DirectoryEntryRef. +/// +//===--===// + +#ifndef LLVM_CLANG_BASIC_DIRECTORYENTRY_H +#define LLVM_CLANG_BASIC_DIRECTORYENTRY_H + +#include "clang/Basic/LLVM.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/ErrorOr.h" + +namespace clang { + +/// Cached information about one directory (either on disk or in +/// the virtual file system). +class DirectoryEntry { + friend class FileManager; + + // FIXME: We should not be storing a directory entry name here. + StringRef Name; // Name of the directory. + +public: + StringRef getName() const { return Name; } +}; + +/// A reference to a \c DirectoryEntry that includes the name of the directory +/// as it was accessed by the FileManager's client. +class DirectoryEntryRef { +public: + const DirectoryEntry &getDirEntry() const { return *Entry->getValue(); } + + StringRef getName() const { return Entry->getKey(); } + +private: + friend class FileManager; + + DirectoryEntryRef( + llvm::StringMapEntry> *Entry) + : Entry(Entry) {} + + const llvm::StringMapEntry> *Entry; +}; + +} // end namespace clang + +#endif // LLVM_CLANG_BASIC_DIRECTORYENTRY_H diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index 224f87ffcb26..d7135a4f0ac3 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -14,6 +14,7 @@ #ifndef LLVM_CLANG_BASIC_FILEMANAGER_H #define LLVM_CLANG_BASIC_FILEMANAGER_H +#include "clang/Basic/DirectoryEntry.h" #include "clang/Basic/FileEntry.h" #include "clang/Basic/FileSystemOptions.h" #include "clang/Basic/LLVM.h" @@ -42,36 +43,6 @@ namespace clang { class FileSystemStatCache; -/// Cached information about one directory (either on disk or in -/// the virtual file system). -class DirectoryEntry { - friend class FileManager; - - // FIXME: We should not be storing a directory entry name here. - StringRef Name; // Name of the directory. - -public: - StringRef getName() const { return Name; } -}; - -/// A reference to a \c DirectoryEntry that includes the name of the directory -/// as it was accessed by the FileManager's client. -class DirectoryEntryRef { -public: - const DirectoryEntry &getDirEntry() const { return *Entry->getValue(); } - - StringRef getName() const { return Entry->getKey(); } - -private: - friend class FileManager; - - DirectoryEntryRef( - llvm::StringMapEntry> *Entry) - : Entry(Entry) {} - - const llvm::StringMapEntry> *Entry; -}; - /// Implements support for file system lookup, file system caching, /// and directory search management. /// ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 5cb8d93 - Fix build error on bots after 9f151df17800e1668c32e5314a290ae94c8f2dd3
Author: Duncan P. N. Exon Smith Date: 2020-11-02T15:55:13-05:00 New Revision: 5cb8d93205463f169ad4dd532829147fed2e38d0 URL: https://github.com/llvm/llvm-project/commit/5cb8d93205463f169ad4dd532829147fed2e38d0 DIFF: https://github.com/llvm/llvm-project/commit/5cb8d93205463f169ad4dd532829147fed2e38d0.diff LOG: Fix build error on bots after 9f151df17800e1668c32e5314a290ae94c8f2dd3 Attempt to fix build error on bots not seen locally. Added: Modified: clang/lib/Serialization/ASTReader.cpp Removed: diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index c06dee3d74b2..fb397246fd8d 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -3921,7 +3921,7 @@ ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, // Don't emit module relocation error if we have -fno-validate-pch if (!PP.getPreprocessorOpts().DisablePCHValidation && !ModMap) { if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) { -if (auto *ASTFE = M ? M->getASTFile() : nullptr) { +if (auto ASTFE = M ? M->getASTFile() : None) { // This module was defined by an imported (explicit) module. Diag(diag::err_module_file_conflict) << F.ModuleName << F.FileName << ASTFE->getName(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 9f151df - Change Module::ASTFile and ModuleFile::File => Optional, NFC
Author: Duncan P. N. Exon Smith Date: 2020-11-02T15:11:51-05:00 New Revision: 9f151df17800e1668c32e5314a290ae94c8f2dd3 URL: https://github.com/llvm/llvm-project/commit/9f151df17800e1668c32e5314a290ae94c8f2dd3 DIFF: https://github.com/llvm/llvm-project/commit/9f151df17800e1668c32e5314a290ae94c8f2dd3.diff LOG: Change Module::ASTFile and ModuleFile::File => Optional, NFC Change `Module::ASTFile` and `ModuleFile::File` to use `Optional` instead of `const FileEntry *`. One of many steps toward removing `FileEntry::getName`. Differential Revision: https://reviews.llvm.org/D89836 Added: Modified: clang/include/clang/Basic/FileEntry.h clang/include/clang/Basic/Module.h clang/include/clang/Serialization/ModuleFile.h clang/include/clang/Serialization/ModuleManager.h clang/lib/Basic/Module.cpp clang/lib/Sema/SemaModule.cpp clang/lib/Serialization/ModuleManager.cpp clang/tools/libclang/CIndex.cpp clang/tools/libclang/CXIndexDataConsumer.cpp Removed: diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 7f5efb1c48f3..e4c2e7e34db9 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -64,6 +64,7 @@ class FileEntryRef { inline unsigned getUID() const; inline const llvm::sys::fs::UniqueID &getUniqueID() const; inline time_t getModificationTime() const; + inline void closeFile() const; /// Check if the underlying FileEntry is the same, intentially ignoring /// whether the file was referenced with the same spelling of the filename. @@ -360,6 +361,8 @@ time_t FileEntryRef::getModificationTime() const { return getFileEntry().getModificationTime(); } +void FileEntryRef::closeFile() const { getFileEntry().closeFile(); } + } // end namespace clang #endif // LLVM_CLANG_BASIC_FILEENTRY_H diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h index ac33c7573f35..5a4975f25b72 100644 --- a/clang/include/clang/Basic/Module.h +++ b/clang/include/clang/Basic/Module.h @@ -15,6 +15,7 @@ #ifndef LLVM_CLANG_BASIC_MODULE_H #define LLVM_CLANG_BASIC_MODULE_H +#include "clang/Basic/FileEntry.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseSet.h" @@ -160,7 +161,7 @@ class Module { /// The AST file if this is a top-level module which has a /// corresponding serialized AST file, or null otherwise. - const FileEntry *ASTFile = nullptr; + Optional ASTFile; /// The top-level headers associated with this module. llvm::SmallSetVector TopHeaders; @@ -529,14 +530,14 @@ class Module { } /// The serialized AST file for this module, if one was created. - const FileEntry *getASTFile() const { + OptionalFileEntryRefDegradesToFileEntryPtr getASTFile() const { return getTopLevelModule()->ASTFile; } /// Set the serialized AST file for the top-level module of this module. - void setASTFile(const FileEntry *File) { -assert((File == nullptr || getASTFile() == nullptr || -getASTFile() == File) && "file path changed"); + void setASTFile(Optional File) { +assert((!File || !getASTFile() || getASTFile() == File) && + "file path changed"); getTopLevelModule()->ASTFile = File; } diff --git a/clang/include/clang/Serialization/ModuleFile.h b/clang/include/clang/Serialization/ModuleFile.h index 598e61210702..a309c1143350 100644 --- a/clang/include/clang/Serialization/ModuleFile.h +++ b/clang/include/clang/Serialization/ModuleFile.h @@ -159,7 +159,7 @@ class ModuleFile { bool DidReadTopLevelSubmodule = false; /// The file entry for the module file. - const FileEntry *File = nullptr; + OptionalFileEntryRefDegradesToFileEntryPtr File; /// The signature of the module file, which may be used instead of the size /// and modification time to identify this particular file. diff --git a/clang/include/clang/Serialization/ModuleManager.h b/clang/include/clang/Serialization/ModuleManager.h index 15ddb9875ff1..7081eedad4b4 100644 --- a/clang/include/clang/Serialization/ModuleManager.h +++ b/clang/include/clang/Serialization/ModuleManager.h @@ -307,10 +307,8 @@ class ModuleManager { /// \returns True if a file exists but does not meet the size/ /// modification time criteria, false if the file is either available and /// suitable, or is missing. - bool lookupModuleFile(StringRef FileName, -off_t ExpectedSize, -time_t ExpectedModTime, -const FileEntry *&File); + bool lookupModuleFile(StringRef FileName, off_t ExpectedSize, +time_t ExpectedModTime, Optional &File); /// View the graphviz representation of the module graph. void viewGraph(); diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp index b25248de6832..6
[clang] 814141f - Remove `noexcept` from ac49500cd0484e1b2dcf37fa4c0dade6f113c2c9 to fix bots
Author: Duncan P. N. Exon Smith Date: 2020-10-30T16:29:16-04:00 New Revision: 814141f9bd0a64bbedae05773972d140f04f654d URL: https://github.com/llvm/llvm-project/commit/814141f9bd0a64bbedae05773972d140f04f654d DIFF: https://github.com/llvm/llvm-project/commit/814141f9bd0a64bbedae05773972d140f04f654d.diff LOG: Remove `noexcept` from ac49500cd0484e1b2dcf37fa4c0dade6f113c2c9 to fix bots I'm having trouble with bots today. Remove more cargo-cult from the generic version of `OptionalStorage` that is failing on some (fewer) bots (but not locally). I expect this will fix: ``` FAILED: tools/clang/unittests/Basic/CMakeFiles/BasicTests.dir/FileEntryTest.cpp.o /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DGTEST_HAS_TR1_TUPLE=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/unittests/Basic -I/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/unittests/Basic -I/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/include -Itools/clang/include -Iinclude -I/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/include -I/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/utils/unittest/googletest/include -I/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/utils/unittest/googlemock/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -Wno-variadic-macros -fno-exceptions -fno-rtti -UNDEBUG -Wno-suggest-override -std=c++14 -MD -MT tools/clang/unittests/Basic/CMakeFiles/BasicTests.dir/FileEntryTest.cpp.o -MF tools/clang/unittests/Basic/CMakeFiles/BasicTests.dir/FileEntryTest.cpp.o.d -o tools/clang/unittests/Basic/CMakeFiles/BasicTests.dir/FileEntryTest.cpp.o -c /home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/unittests/Basic/FileEntryTest.cpp /home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/unittests/Basic/FileEntryTest.cpp: In member function ‘virtual void {anonymous}::FileEntryTest_OptionalFileEntryRefDegradesToFileEntryPtr_Test::TestBody()’: /home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/unittests/Basic/FileEntryTest.cpp:48:46: error: use of deleted function ‘constexpr clang::OptionalFileEntryRefDegradesToFileEntryPtr::OptionalFileEntryRefDegradesToFileEntryPtr()’ OptionalFileEntryRefDegradesToFileEntryPtr M0; ^~ In file included from /home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/unittests/Basic/FileEntryTest.cpp:9: /home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/include/clang/Basic/FileEntry.h:250:3: note: ‘constexpr clang::OptionalFileEntryRefDegradesToFileEntryPtr::OptionalFileEntryRefDegradesToFileEntryPtr() noexcept’ is implicitly deleted because its exception-specification does not match the implicit exception-specification ‘’ OptionalFileEntryRefDegradesToFileEntryPtr() noexcept = default; ^~ /home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/unittests/Basic/FileEntryTest.cpp: In member function ‘virtual void {anonymous}::FileEntryTest_equals_Test::TestBody()’: /home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/unittests/Basic/FileEntryTest.cpp:82:46: error: use of deleted function ‘constexpr clang::OptionalFileEntryRefDegradesToFileEntryPtr::OptionalFileEntryRefDegradesToFileEntryPtr()’ OptionalFileEntryRefDegradesToFileEntryPtr M0; ^~ ``` Added: Modified: clang/include/clang/Basic/FileEntry.h Removed: diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 2d7694ece999..7f5efb1c48f3 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -171,8 +171,7 @@ template <> class OptionalStorage { public: ~OptionalStorage() = default; - OptionalStorage() noexcept - : MaybeRef(clang::FileEntryRef::optional_none_tag()) {} + OptionalStorage() : MaybeRef(clang::FileEntryRef::optional_none_tag()) {} OptionalStorage(OptionalStorage const &Other) = default; OptionalStorage(OptionalStorage &&Other) = default; OptionalStorage &operator=(OptionalStor
[clang] ac49500 - Reapply "FileManager: Improve the FileEntryRef API and customize its OptionalStorage"
Author: Duncan P. N. Exon Smith Date: 2020-10-30T15:06:01-04:00 New Revision: ac49500cd0484e1b2dcf37fa4c0dade6f113c2c9 URL: https://github.com/llvm/llvm-project/commit/ac49500cd0484e1b2dcf37fa4c0dade6f113c2c9 DIFF: https://github.com/llvm/llvm-project/commit/ac49500cd0484e1b2dcf37fa4c0dade6f113c2c9.diff LOG: Reapply "FileManager: Improve the FileEntryRef API and customize its OptionalStorage" This reverts commit 940d0a310dca31ae97080b068cef92eadfee6367, effectively reapplying 84e8257937ec6a332aa0b688f4dce57016516ffd, after working around the compile errors on the bots that I wasn't seeing locally. I removed the `constexpr` from `OptionalStorage` that I had cargo-culted from the generic version, since `FileEntryRef` isn't relevant in `constexpr` contexts anyway. The original commit message follows: Make a few changes to the `FileEntryRef` API in preparation for propagating it enough to remove `FileEntry::getName()`. - Allow `FileEntryRef` to degrade implicitly to `const FileEntry*`. This allows functions currently returning `const FileEntry *` to be updated to return `FileEntryRef` without requiring all callers to be updated in the same patch. This helps avoid both (a) massive patches where many fields and locals are updated simultaneously and (b) noisy incremental patches where the first patch adds `getFileEntry()` at call sites and the second patch removes it. (Once `FileEntryRef` is everywhere, we should remove this API.) - Change `operator==` to compare the underlying `FileEntry*`, ignoring any difference in the spelling of the filename. There were 0 users of the existing function because it's not useful. In case comparing the exact named reference becomes important, add/test `isSameRef`. - Add `==` comparisons between `FileEntryRef` and `const FileEntry *` (compares the `FileEntry*`). - Customize `OptionalStorage` to be pointer-sized. Add a private constructor that initializes with `nullptr` and specialize `OptionalStorage` to use it. This unblocks updating fields in size-sensitive data structures that currently use `const FileEntry *`. - Add `OptionalFileEntryRefDegradesToFileEntryPtr`, a wrapper around `Optional` that degrades to `const FileEntry*`. This facilitates future incremental patches, like the same operator on `FileEntryRef`. (Once `FileEntryRef` is everywhere, we should remove this class.) - Remove the unncessary `const` from the by-value return of `FileEntryRef::getName`. - Delete the unused function `FileEntry::isOpenForTests`. Note that there are still `FileEntry` APIs that aren't wrapped and I plan to deal with these separately / incrementally, as they are needed. Differential Revision: https://reviews.llvm.org/D89834 Added: clang/unittests/Basic/FileEntryTest.cpp Modified: clang/include/clang/Basic/FileEntry.h clang/unittests/Basic/CMakeLists.txt clang/unittests/Basic/FileManagerTest.cpp Removed: diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 65149569bb59..2d7694ece999 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -31,6 +31,22 @@ class File; namespace clang { +class FileEntryRef; + +} // namespace clang + +namespace llvm { +namespace optional_detail { + +/// Forward declare a template specialization for OptionalStorage. +template <> +class OptionalStorage; + +} // namespace optional_detail +} // namespace llvm + +namespace clang { + class DirectoryEntry; class FileEntry; @@ -38,9 +54,9 @@ class FileEntry; /// accessed by the FileManager's client. class FileEntryRef { public: - const StringRef getName() const { return Entry->first(); } + StringRef getName() const { return ME->first(); } const FileEntry &getFileEntry() const { -return *Entry->second->V.get(); +return *ME->second->V.get(); } inline bool isValid() const; @@ -49,12 +65,26 @@ class FileEntryRef { inline const llvm::sys::fs::UniqueID &getUniqueID() const; inline time_t getModificationTime() const; + /// Check if the underlying FileEntry is the same, intentially ignoring + /// whether the file was referenced with the same spelling of the filename. friend bool operator==(const FileEntryRef &LHS, const FileEntryRef &RHS) { -return LHS.Entry == RHS.Entry; +return &LHS.getFileEntry() == &RHS.getFileEntry(); + } + friend bool operator==(const FileEntry *LHS, const FileEntryRef &RHS) { +return LHS == &RHS.getFileEntry(); + } + friend bool operator==(const FileEntryRef &LHS, const FileEntry *RHS) { +return &LHS.getFileEntry() == RHS; } friend bool operator!=(const FileEntryRef &LHS, const FileEntryRef &RHS) { return !(LHS == RHS); } + friend bool operator!=(const FileEntry *LHS, const FileEntryRef &RHS) { +return !(LHS == RHS); + } + friend bool operator!=(const FileEntryRef &LHS, const F
[clang] 940d0a3 - Revert "FileManager: Improve the FileEntryRef API and customize its OptionalStorage" and follow-ups
Author: Duncan P. N. Exon Smith Date: 2020-10-30T14:06:55-04:00 New Revision: 940d0a310dca31ae97080b068cef92eadfee6367 URL: https://github.com/llvm/llvm-project/commit/940d0a310dca31ae97080b068cef92eadfee6367 DIFF: https://github.com/llvm/llvm-project/commit/940d0a310dca31ae97080b068cef92eadfee6367.diff LOG: Revert "FileManager: Improve the FileEntryRef API and customize its OptionalStorage" and follow-ups This reverts commit 5530fb586f30da9dcb434f6be39198dbf016b866. This reverts commit 010238a296e61cbf6f4d7f4383e26cf00c4e4992. This reverts commit 84e8257937ec6a332aa0b688f4dce57016516ffd. Having trouble getting the bots compiling. Will try again later. Added: Modified: clang/include/clang/Basic/FileEntry.h clang/unittests/Basic/CMakeLists.txt clang/unittests/Basic/FileManagerTest.cpp Removed: clang/unittests/Basic/FileEntryTest.cpp diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 89788b1e68f9..65149569bb59 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -31,22 +31,6 @@ class File; namespace clang { -class FileEntryRef; - -} // namespace clang - -namespace llvm { -namespace optional_detail { - -/// Forward declare a template specialization for OptionalStorage. -template <> -class OptionalStorage; - -} // namespace optional_detail -} // namespace llvm - -namespace clang { - class DirectoryEntry; class FileEntry; @@ -54,9 +38,9 @@ class FileEntry; /// accessed by the FileManager's client. class FileEntryRef { public: - StringRef getName() const { return ME->first(); } + const StringRef getName() const { return Entry->first(); } const FileEntry &getFileEntry() const { -return *ME->second->V.get(); +return *Entry->second->V.get(); } inline bool isValid() const; @@ -65,26 +49,12 @@ class FileEntryRef { inline const llvm::sys::fs::UniqueID &getUniqueID() const; inline time_t getModificationTime() const; - /// Check if the underlying FileEntry is the same, intentially ignoring - /// whether the file was referenced with the same spelling of the filename. friend bool operator==(const FileEntryRef &LHS, const FileEntryRef &RHS) { -return &LHS.getFileEntry() == &RHS.getFileEntry(); - } - friend bool operator==(const FileEntry *LHS, const FileEntryRef &RHS) { -return LHS == &RHS.getFileEntry(); - } - friend bool operator==(const FileEntryRef &LHS, const FileEntry *RHS) { -return &LHS.getFileEntry() == RHS; +return LHS.Entry == RHS.Entry; } friend bool operator!=(const FileEntryRef &LHS, const FileEntryRef &RHS) { return !(LHS == RHS); } - friend bool operator!=(const FileEntry *LHS, const FileEntryRef &RHS) { -return !(LHS == RHS); - } - friend bool operator!=(const FileEntryRef &LHS, const FileEntry *RHS) { -return !(LHS == RHS); - } struct MapValue; @@ -108,191 +78,20 @@ class FileEntryRef { MapValue(MapEntry &ME) : V(&ME) {} }; - /// Check if RHS referenced the file in exactly the same way. - bool isSameRef(const FileEntryRef &RHS) const { return ME == RHS.ME; } - - /// Allow FileEntryRef to degrade into 'const FileEntry*' to facilitate - /// incremental adoption. - /// - /// The goal is to avoid code churn due to dances like the following: - /// \code - /// // Old code. - /// lvalue = rvalue; - /// - /// // Temporary code from an incremental patch. - /// lvalue = &rvalue.getFileEntry(); - /// - /// // Final code. - /// lvalue = rvalue; - /// \endcode - /// - /// FIXME: Once FileEntryRef is "everywhere" and FileEntry::LastRef and - /// FileEntry::getName have been deleted, delete this implicit conversion. - operator const FileEntry *() const { return &getFileEntry(); } - - FileEntryRef() = delete; - explicit FileEntryRef(const MapEntry &ME) : ME(&ME) { -assert(ME.second && "Expected payload"); -assert(ME.second->V && "Expected non-null"); -assert(ME.second->V.is() && "Expected FileEntry"); - } - - /// Expose the underlying MapEntry to simplify packing in a PointerIntPair or - /// PointerUnion and allow construction in Optional. - const clang::FileEntryRef::MapEntry &getMapEntry() const { return *ME; } - private: - friend class llvm::optional_detail::OptionalStorage< - FileEntryRef, /*is_trivially_copyable*/ true>; - struct optional_none_tag {}; - - // Private constructor for use by OptionalStorage. - FileEntryRef(optional_none_tag) : ME(nullptr) {} - constexpr bool hasOptionalValue() const { return ME; } - - const MapEntry *ME; -}; - -static_assert(sizeof(FileEntryRef) == sizeof(const FileEntry *), - "FileEntryRef must avoid size overhead"); - -static_assert(std::is_trivially_copyable::value, - "FileEntryRef must be trivially copyable"); - -} // end namespace clang - -namespace llvm { -namespace optional_detail { - -///
[clang] 5530fb5 - Speculative fix for bots after 84e8257937ec6a332aa0b688f4dce57016516ffd, v2
Author: Duncan P. N. Exon Smith Date: 2020-10-30T14:04:48-04:00 New Revision: 5530fb586f30da9dcb434f6be39198dbf016b866 URL: https://github.com/llvm/llvm-project/commit/5530fb586f30da9dcb434f6be39198dbf016b866 DIFF: https://github.com/llvm/llvm-project/commit/5530fb586f30da9dcb434f6be39198dbf016b866.diff LOG: Speculative fix for bots after 84e8257937ec6a332aa0b688f4dce57016516ffd, v2 Looks like some bots don't like the defaulted default constructor, try being explicit. Added: Modified: clang/include/clang/Basic/FileEntry.h Removed: diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 03697c584b0b..89788b1e68f9 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -167,11 +167,12 @@ namespace optional_detail { /// Customize OptionalStorage to use FileEntryRef and its /// optional_none_tag to keep it the size of a single pointer. template <> class OptionalStorage { - clang::FileEntryRef MaybeRef = clang::FileEntryRef::optional_none_tag{}; + clang::FileEntryRef MaybeRef; public: ~OptionalStorage() = default; - constexpr OptionalStorage() noexcept = default; + constexpr OptionalStorage() noexcept + : MaybeRef(clang::FileEntryRef::optional_none_tag) {} constexpr OptionalStorage(OptionalStorage const &Other) = default; constexpr OptionalStorage(OptionalStorage &&Other) = default; OptionalStorage &operator=(OptionalStorage const &Other) = default; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 010238a - Speculative fix for bots after 84e8257937ec6a332aa0b688f4dce57016516ffd
Author: Duncan P. N. Exon Smith Date: 2020-10-30T14:01:01-04:00 New Revision: 010238a296e61cbf6f4d7f4383e26cf00c4e4992 URL: https://github.com/llvm/llvm-project/commit/010238a296e61cbf6f4d7f4383e26cf00c4e4992 DIFF: https://github.com/llvm/llvm-project/commit/010238a296e61cbf6f4d7f4383e26cf00c4e4992.diff LOG: Speculative fix for bots after 84e8257937ec6a332aa0b688f4dce57016516ffd I'm not seeing an error locally, but many bots are having a problem with the call to `hasOptionalValue`. Try to fix it. Added: Modified: clang/include/clang/Basic/FileEntry.h Removed: diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 318aa2cdbb47..03697c584b0b 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -148,7 +148,7 @@ class FileEntryRef { // Private constructor for use by OptionalStorage. FileEntryRef(optional_none_tag) : ME(nullptr) {} - bool hasOptionalValue() const { return ME; } + constexpr bool hasOptionalValue() const { return ME; } const MapEntry *ME; }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 84e8257 - FileManager: Improve the FileEntryRef API and customize its OptionalStorage
Author: Duncan P. N. Exon Smith Date: 2020-10-30T13:25:46-04:00 New Revision: 84e8257937ec6a332aa0b688f4dce57016516ffd URL: https://github.com/llvm/llvm-project/commit/84e8257937ec6a332aa0b688f4dce57016516ffd DIFF: https://github.com/llvm/llvm-project/commit/84e8257937ec6a332aa0b688f4dce57016516ffd.diff LOG: FileManager: Improve the FileEntryRef API and customize its OptionalStorage Make a few changes to the `FileEntryRef` API in preparation for propagating it enough to remove `FileEntry::getName()`. - Allow `FileEntryRef` to degrade implicitly to `const FileEntry*`. This allows functions currently returning `const FileEntry *` to be updated to return `FileEntryRef` without requiring all callers to be updated in the same patch. This helps avoid both (a) massive patches where many fields and locals are updated simultaneously and (b) noisy incremental patches where the first patch adds `getFileEntry()` at call sites and the second patch removes it. (Once `FileEntryRef` is everywhere, we should remove this API.) - Change `operator==` to compare the underlying `FileEntry*`, ignoring any difference in the spelling of the filename. There were 0 users of the existing function because it's not useful. In case comparing the exact named reference becomes important, add/test `isSameRef`. - Add `==` comparisons between `FileEntryRef` and `const FileEntry *` (compares the `FileEntry*`). - Customize `OptionalStorage` to be pointer-sized. Add a private constructor that initializes with `nullptr` and specialize `OptionalStorage` to use it. This unblocks updating fields in size-sensitive data structures that currently use `const FileEntry *`. - Add `OptionalFileEntryRefDegradesToFileEntryPtr`, a wrapper around `Optional` that degrades to `const FileEntry*`. This facilitates future incremental patches, like the same operator on `FileEntryRef`. (Once `FileEntryRef` is everywhere, we should remove this class.) - Remove the unncessary `const` from the by-value return of `FileEntryRef::getName`. - Delete the unused function `FileEntry::isOpenForTests`. Note that there are still `FileEntry` APIs that aren't wrapped and I plan to deal with these separately / incrementally, as they are needed. Differential Revision: https://reviews.llvm.org/D89834 Added: clang/unittests/Basic/FileEntryTest.cpp Modified: clang/include/clang/Basic/FileEntry.h clang/unittests/Basic/CMakeLists.txt clang/unittests/Basic/FileManagerTest.cpp Removed: diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 65149569bb59..318aa2cdbb47 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -31,6 +31,22 @@ class File; namespace clang { +class FileEntryRef; + +} // namespace clang + +namespace llvm { +namespace optional_detail { + +/// Forward declare a template specialization for OptionalStorage. +template <> +class OptionalStorage; + +} // namespace optional_detail +} // namespace llvm + +namespace clang { + class DirectoryEntry; class FileEntry; @@ -38,9 +54,9 @@ class FileEntry; /// accessed by the FileManager's client. class FileEntryRef { public: - const StringRef getName() const { return Entry->first(); } + StringRef getName() const { return ME->first(); } const FileEntry &getFileEntry() const { -return *Entry->second->V.get(); +return *ME->second->V.get(); } inline bool isValid() const; @@ -49,12 +65,26 @@ class FileEntryRef { inline const llvm::sys::fs::UniqueID &getUniqueID() const; inline time_t getModificationTime() const; + /// Check if the underlying FileEntry is the same, intentially ignoring + /// whether the file was referenced with the same spelling of the filename. friend bool operator==(const FileEntryRef &LHS, const FileEntryRef &RHS) { -return LHS.Entry == RHS.Entry; +return &LHS.getFileEntry() == &RHS.getFileEntry(); + } + friend bool operator==(const FileEntry *LHS, const FileEntryRef &RHS) { +return LHS == &RHS.getFileEntry(); + } + friend bool operator==(const FileEntryRef &LHS, const FileEntry *RHS) { +return &LHS.getFileEntry() == RHS; } friend bool operator!=(const FileEntryRef &LHS, const FileEntryRef &RHS) { return !(LHS == RHS); } + friend bool operator!=(const FileEntry *LHS, const FileEntryRef &RHS) { +return !(LHS == RHS); + } + friend bool operator!=(const FileEntryRef &LHS, const FileEntry *RHS) { +return !(LHS == RHS); + } struct MapValue; @@ -78,20 +108,190 @@ class FileEntryRef { MapValue(MapEntry &ME) : V(&ME) {} }; -private: - friend class FileManager; + /// Check if RHS referenced the file in exactly the same way. + bool isSameRef(const FileEntryRef &RHS) const { return ME == RHS.ME; } + + /// Allow FileEntryRef to degrade into 'const FileEntry*' to facilitate + ///
[clang] 946406a - ModuleManager: Simplify lookupModuleFile by only setting the out parameter once, NFC
Author: Duncan P. N. Exon Smith Date: 2020-10-28T19:04:22-04:00 New Revision: 946406aebce298725b07097934cb39b1e5bee656 URL: https://github.com/llvm/llvm-project/commit/946406aebce298725b07097934cb39b1e5bee656 DIFF: https://github.com/llvm/llvm-project/commit/946406aebce298725b07097934cb39b1e5bee656.diff LOG: ModuleManager: Simplify lookupModuleFile by only setting the out parameter once, NFC Differential Revision: https://reviews.llvm.org/D89835 Added: Modified: clang/lib/Serialization/ModuleManager.cpp Removed: diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp index 542e75e77c3a..2c65c0be4074 100644 --- a/clang/lib/Serialization/ModuleManager.cpp +++ b/clang/lib/Serialization/ModuleManager.cpp @@ -462,19 +462,17 @@ bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize, time_t ExpectedModTime, const FileEntry *&File) { - if (FileName == "-") { -File = nullptr; + File = nullptr; + if (FileName == "-") return false; - } // Open the file immediately to ensure there is no race between stat'ing and // opening the file. auto FileOrErr = FileMgr.getFile(FileName, /*OpenFile=*/true, /*CacheFailure=*/false); - if (!FileOrErr) { -File = nullptr; + if (!FileOrErr) return false; - } + File = *FileOrErr; if ((ExpectedSize && ExpectedSize != File->getSize()) || ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 23ed570 - Split out llvm/Support/FileSystem/UniqueID.h and clang/Basic/FileEntry.h, NFC
Author: Duncan P. N. Exon Smith Date: 2020-10-28T16:38:32-04:00 New Revision: 23ed570af1cc165afea1b70a533a4a39d6656501 URL: https://github.com/llvm/llvm-project/commit/23ed570af1cc165afea1b70a533a4a39d6656501 DIFF: https://github.com/llvm/llvm-project/commit/23ed570af1cc165afea1b70a533a4a39d6656501.diff LOG: Split out llvm/Support/FileSystem/UniqueID.h and clang/Basic/FileEntry.h, NFC Split `FileEntry` and `FileEntryRef` out into a new file `clang/Basic/FileEntry.h`. This allows current users of a forward-declared `FileEntry` to transition to `FileEntryRef` without adding more includers of `FileManager.h`. Also split `UniqueID` out to llvm/Support/FileSystem/UniqueID.h, so `FileEntry.h` doesn't need to include all of `FileSystem.h` for just that type. Differential Revision: https://reviews.llvm.org/D89761 Added: clang/include/clang/Basic/FileEntry.h clang/lib/Basic/FileEntry.cpp llvm/include/llvm/Support/FileSystem/UniqueID.h Modified: clang/include/clang/Basic/FileManager.h clang/lib/Basic/CMakeLists.txt llvm/include/llvm/Support/FileSystem.h Removed: diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h new file mode 100644 index 0..65149569bb59d --- /dev/null +++ b/clang/include/clang/Basic/FileEntry.h @@ -0,0 +1,172 @@ +//===- clang/Basic/FileEntry.h - File references *- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +/// +/// \file +/// Defines interfaces for clang::FileEntry and clang::FileEntryRef. +/// +//===--===// + +#ifndef LLVM_CLANG_BASIC_FILEENTRY_H +#define LLVM_CLANG_BASIC_FILEENTRY_H + +#include "clang/Basic/LLVM.h" +#include "llvm/ADT/PointerUnion.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/ErrorOr.h" +#include "llvm/Support/FileSystem/UniqueID.h" + +namespace llvm { +namespace vfs { + +class File; + +} // namespace vfs +} // namespace llvm + +namespace clang { + +class DirectoryEntry; +class FileEntry; + +/// A reference to a \c FileEntry that includes the name of the file as it was +/// accessed by the FileManager's client. +class FileEntryRef { +public: + const StringRef getName() const { return Entry->first(); } + const FileEntry &getFileEntry() const { +return *Entry->second->V.get(); + } + + inline bool isValid() const; + inline off_t getSize() const; + inline unsigned getUID() const; + inline const llvm::sys::fs::UniqueID &getUniqueID() const; + inline time_t getModificationTime() const; + + friend bool operator==(const FileEntryRef &LHS, const FileEntryRef &RHS) { +return LHS.Entry == RHS.Entry; + } + friend bool operator!=(const FileEntryRef &LHS, const FileEntryRef &RHS) { +return !(LHS == RHS); + } + + struct MapValue; + + /// Type used in the StringMap. + using MapEntry = llvm::StringMapEntry>; + + /// Type stored in the StringMap. + struct MapValue { +/// The pointer at another MapEntry is used when the FileManager should +/// silently forward from one name to another, which occurs in Redirecting +/// VFSs that use external names. In that case, the \c FileEntryRef +/// returned by the \c FileManager will have the external name, and not the +/// name that was used to lookup the file. +/// +/// The second type is really a `const MapEntry *`, but that confuses +/// gcc5.3. Once that's no longer supported, change this back. +llvm::PointerUnion V; + +MapValue() = delete; +MapValue(FileEntry &FE) : V(&FE) {} +MapValue(MapEntry &ME) : V(&ME) {} + }; + +private: + friend class FileManager; + + FileEntryRef() = delete; + explicit FileEntryRef(const MapEntry &Entry) + : Entry(&Entry) { +assert(Entry.second && "Expected payload"); +assert(Entry.second->V && "Expected non-null"); +assert(Entry.second->V.is() && "Expected FileEntry"); + } + + const MapEntry *Entry; +}; + +/// Cached information about one file (either on disk +/// or in the virtual file system). +/// +/// If the 'File' member is valid, then this FileEntry has an open file +/// descriptor for the file. +class FileEntry { + friend class FileManager; + + std::string RealPathName; // Real path to the file; could be empty. + off_t Size; // File size in bytes. + time_t ModTime; // Modification time of file. + const DirectoryEntry *Dir; // Directory file lives in. + llvm::sys::fs::UniqueID UniqueID; + unsigned UID; // A unique (small) ID for the file. + bool IsNamedPipe; + bool IsValid; // Is this \c F
[clang] 917acac - FileManager: Shrink FileEntryRef to the size of a pointer
Author: Duncan P. N. Exon Smith Date: 2020-10-27T14:55:41-04:00 New Revision: 917acac960d40280ea02ea453e594034b1be1f6b URL: https://github.com/llvm/llvm-project/commit/917acac960d40280ea02ea453e594034b1be1f6b DIFF: https://github.com/llvm/llvm-project/commit/917acac960d40280ea02ea453e594034b1be1f6b.diff LOG: FileManager: Shrink FileEntryRef to the size of a pointer Shrink `FileEntryRef` to the size of a pointer, by having it directly reference the `StringMapEntry` the same way that `DirectoryEntryRef` does. This makes `FileEntryRef::FileEntryRef` private as a side effect (`FileManager` is a friend!). There are two helper types added within `FileEntryRef`: - `FileEntryRef::MapValue` is the type stored in `FileManager::SeenFileEntries`. It's a replacement for `SeenFileEntryOrRedirect`, where the second pointer type has been changed from `StringRef*` to `MapEntry*` (see next bullet). - `FileEntryRef::MapEntry` is the instantiation of `StringMapEntry<>` where `MapValue` is stored. This is what `FileEntryRef` has a pointer to, in order to grab the name in addition to the value. Differential Revision: https://reviews.llvm.org/D89488 Added: Modified: clang/include/clang/Basic/FileManager.h clang/lib/Basic/FileManager.cpp clang/lib/Basic/SourceManager.cpp clang/unittests/Basic/FileManagerTest.cpp Removed: diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index 8fcea2d5cbf3..d27b4260cca7 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -77,12 +77,10 @@ class FileEntry; /// accessed by the FileManager's client. class FileEntryRef { public: - FileEntryRef() = delete; - FileEntryRef(StringRef Name, const FileEntry &Entry) - : Name(Name), Entry(&Entry) {} - - const StringRef getName() const { return Name; } - const FileEntry &getFileEntry() const { return *Entry; } + const StringRef getName() const { return Entry->first(); } + const FileEntry &getFileEntry() const { +return *Entry->second->V.get(); + } inline bool isValid() const; inline off_t getSize() const; @@ -91,15 +89,43 @@ class FileEntryRef { inline time_t getModificationTime() const; friend bool operator==(const FileEntryRef &LHS, const FileEntryRef &RHS) { -return LHS.Entry == RHS.Entry && LHS.Name == RHS.Name; +return LHS.Entry == RHS.Entry; } friend bool operator!=(const FileEntryRef &LHS, const FileEntryRef &RHS) { return !(LHS == RHS); } + struct MapValue; + + /// Type used in the StringMap. + using MapEntry = llvm::StringMapEntry>; + + /// Type stored in the StringMap. + struct MapValue { +/// The pointer at another MapEntry is used when the FileManager should +/// silently forward from one name to another, which occurs in Redirecting +/// VFSs that use external names. In that case, the \c FileEntryRef +/// returned by the \c FileManager will have the external name, and not the +/// name that was used to lookup the file. +llvm::PointerUnion V; + +MapValue() = delete; +MapValue(FileEntry &FE) : V(&FE) {} +MapValue(MapEntry &ME) : V(&ME) {} + }; + private: - StringRef Name; - const FileEntry *Entry; + friend class FileManager; + + FileEntryRef() = delete; + explicit FileEntryRef(const MapEntry &Entry) + : Entry(&Entry) { +assert(Entry.second && "Expected payload"); +assert(Entry.second->V && "Expected non-null"); +assert(Entry.second->V.is() && "Expected FileEntry"); + } + + const MapEntry *Entry; }; /// Cached information about one file (either on disk @@ -110,7 +136,6 @@ class FileEntryRef { class FileEntry { friend class FileManager; - StringRef Name; // Name of the file. std::string RealPathName; // Real path to the file; could be empty. off_t Size; // File size in bytes. time_t ModTime; // Modification time of file. @@ -123,6 +148,14 @@ class FileEntry { /// The open file, if it is owned by the \p FileEntry. mutable std::unique_ptr File; + // First access name for this FileEntry. + // + // This is Optional only to allow delayed construction (FileEntryRef has no + // default constructor). It should always have a value in practice. + // + // TODO: remote this once everyone that needs a name uses FileEntryRef. + Optional LastRef; + public: FileEntry() : UniqueID(0, 0), IsNamedPipe(false), IsValid(false) @@ -131,7 +164,9 @@ class FileEntry { FileEntry(const FileEntry &) = delete; FileEntry &operator=(const FileEntry &) = delete; - StringRef getName() const { return Name; } + StringRef getName() const { return LastRef->getName(); } + FileEntryRef getLastRef() const { return *LastRef; } + StringRef tryGetRealPathName() const { return RealPathName; } bool isValid() const { return IsValid; } off_t ge
[clang] f057e6d - SourceManager: clang-format the SrcMgr namespace, NFC
Author: Duncan P. N. Exon Smith Date: 2020-10-26T21:58:52-04:00 New Revision: f057e6dc5e29751dbba700bc62d8c42c57a502b0 URL: https://github.com/llvm/llvm-project/commit/f057e6dc5e29751dbba700bc62d8c42c57a502b0 DIFF: https://github.com/llvm/llvm-project/commit/f057e6dc5e29751dbba700bc62d8c42c57a502b0.diff LOG: SourceManager: clang-format the SrcMgr namespace, NFC Added: Modified: clang/include/clang/Basic/SourceManager.h Removed: diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index 765cec465f9d..d8f17b3facdc 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -69,454 +69,453 @@ class SourceManager; /// SourceManager implementation. namespace SrcMgr { - /// Indicates whether a file or directory holds normal user code, - /// system code, or system code which is implicitly 'extern "C"' in C++ mode. +/// Indicates whether a file or directory holds normal user code, +/// system code, or system code which is implicitly 'extern "C"' in C++ mode. +/// +/// Entire directories can be tagged with this (this is maintained by +/// DirectoryLookup and friends) as can specific FileInfos when a \#pragma +/// system_header is seen or in various other cases. +/// +enum CharacteristicKind { + C_User, + C_System, + C_ExternCSystem, + C_User_ModuleMap, + C_System_ModuleMap +}; + +/// Determine whether a file / directory characteristic is for system code. +inline bool isSystem(CharacteristicKind CK) { + return CK != C_User && CK != C_User_ModuleMap; +} + +/// Determine whether a file characteristic is for a module map. +inline bool isModuleMap(CharacteristicKind CK) { + return CK == C_User_ModuleMap || CK == C_System_ModuleMap; +} + +/// Mapping of line offsets into a source file. This does not own the storage +/// for the line numbers. +class LineOffsetMapping { +public: + explicit operator bool() const { return Storage; } + unsigned size() const { +assert(Storage); +return Storage[0]; + } + ArrayRef getLines() const { +assert(Storage); +return ArrayRef(Storage + 1, Storage + 1 + size()); + } + const unsigned *begin() const { return getLines().begin(); } + const unsigned *end() const { return getLines().end(); } + const unsigned &operator[](int I) const { return getLines()[I]; } + + static LineOffsetMapping get(llvm::MemoryBufferRef Buffer, + llvm::BumpPtrAllocator &Alloc); + + LineOffsetMapping() = default; + LineOffsetMapping(ArrayRef LineOffsets, +llvm::BumpPtrAllocator &Alloc); + +private: + /// First element is the size, followed by elements at off-by-one indexes. + unsigned *Storage = nullptr; +}; + +/// One instance of this struct is kept for every file loaded or used. +/// +/// This object owns the MemoryBuffer object. +class alignas(8) ContentCache { + /// The actual buffer containing the characters from the input + /// file. + mutable std::unique_ptr Buffer; + +public: + /// Reference to the file entry representing this ContentCache. /// - /// Entire directories can be tagged with this (this is maintained by - /// DirectoryLookup and friends) as can specific FileInfos when a \#pragma - /// system_header is seen or in various other cases. + /// This reference does not own the FileEntry object. /// - enum CharacteristicKind { -C_User, C_System, C_ExternCSystem, C_User_ModuleMap, C_System_ModuleMap - }; + /// It is possible for this to be NULL if the ContentCache encapsulates + /// an imaginary text buffer. + /// + /// FIXME: Turn this into a FileEntryRef and remove Filename. + const FileEntry *OrigEntry; - /// Determine whether a file / directory characteristic is for system code. - inline bool isSystem(CharacteristicKind CK) { -return CK != C_User && CK != C_User_ModuleMap; - } + /// References the file which the contents were actually loaded from. + /// + /// Can be diff erent from 'Entry' if we overridden the contents of one file + /// with the contents of another file. + const FileEntry *ContentsEntry; + + /// The filename that is used to access OrigEntry. + /// + /// FIXME: Remove this once OrigEntry is a FileEntryRef with a stable name. + StringRef Filename; + + /// A bump pointer allocated array of offsets for each source line. + /// + /// This is lazily computed. The lines are owned by the SourceManager + /// BumpPointerAllocator object. + mutable LineOffsetMapping SourceLineCache; + + /// Indicates whether the buffer itself was provided to override + /// the actual file contents. + /// + /// When true, the original entry may be a virtual file that does not + /// exist. + unsigned BufferOverridden : 1; + + /// True if this content cache was initially created for a source file + /// considered to be volatile (likely to change between stat and open). + un
[clang] aab50af - SourceManager: Use the same fake SLocEntry whenever it fails to load
Author: Duncan P. N. Exon Smith Date: 2020-10-26T20:56:28-04:00 New Revision: aab50af8c18ab2eb2149bb516c8a0993ffc5abb7 URL: https://github.com/llvm/llvm-project/commit/aab50af8c18ab2eb2149bb516c8a0993ffc5abb7 DIFF: https://github.com/llvm/llvm-project/commit/aab50af8c18ab2eb2149bb516c8a0993ffc5abb7.diff LOG: SourceManager: Use the same fake SLocEntry whenever it fails to load Instead of putting a fake `SLocEntry` at `LoadedSLocEntryTable[Index]` when it fails to load in `SourceManager::loadSLocEntry`, allocate a fake one. Unless someone is sniffing the address of the returned `SLocEntry` (doubtful), this won't be a functionality change. Note that `SLocEntryLoaded[Index]` wasn't being set to `true` either before or after this change so no accessor is every going to look at `LoadedSLocEntryTable[Index]`. As a side effect, drop the `mutable` from `LoadedSLocEntryTable`. Differential Revision: https://reviews.llvm.org/D89748 Added: Modified: clang/include/clang/Basic/SourceManager.h clang/lib/Basic/SourceManager.cpp Removed: diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index ec9b2b7d0cfd..765cec465f9d 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -693,7 +693,7 @@ class SourceManager : public RefCountedBase { /// /// Negative FileIDs are indexes into this table. To get from ID to an index, /// use (-ID - 2). - mutable SmallVector LoadedSLocEntryTable; + SmallVector LoadedSLocEntryTable; /// The starting offset of the next local SLocEntry. /// @@ -775,6 +775,8 @@ class SourceManager : public RefCountedBase { mutable std::unique_ptr FakeContentCacheForRecovery; + mutable std::unique_ptr FakeSLocEntryForRecovery; + /// Lazily computed map of macro argument chunks to their expanded /// source location. using MacroArgsMap = std::map; diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 6eae0f06a122..88f95d18ddf1 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -434,9 +434,11 @@ const SrcMgr::SLocEntry &SourceManager::loadSLocEntry(unsigned Index, // If the file of the SLocEntry changed we could still have loaded it. if (!SLocEntryLoaded[Index]) { // Try to recover; create a SLocEntry so the rest of clang can handle it. - LoadedSLocEntryTable[Index] = SLocEntry::get( - 0, FileInfo::get(SourceLocation(), getFakeContentCacheForRecovery(), - SrcMgr::C_User, "")); + if (!FakeSLocEntryForRecovery) +FakeSLocEntryForRecovery = std::make_unique(SLocEntry::get( +0, FileInfo::get(SourceLocation(), getFakeContentCacheForRecovery(), + SrcMgr::C_User, ""))); + return *FakeSLocEntryForRecovery; } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 22e6b18 - SourceManager: Fix an SLocEntry memory regression introduced with FileEntryRef
Author: Duncan P. N. Exon Smith Date: 2020-10-26T15:38:13-04:00 New Revision: 22e6b1863e74136908842d71b4f942313d89b273 URL: https://github.com/llvm/llvm-project/commit/22e6b1863e74136908842d71b4f942313d89b273 DIFF: https://github.com/llvm/llvm-project/commit/22e6b1863e74136908842d71b4f942313d89b273.diff LOG: SourceManager: Fix an SLocEntry memory regression introduced with FileEntryRef 4dc5573acc0d2e7c59d8bac2543eb25cb4b32984 added `FileEntryRef` in order to help enable sharing of a `FileManager` between `CompilerInstance`s. It also added a `StringRef` with the filename on `FileInfo`. This doubled `sizeof(FileInfo)`, bloating `sizeof(SLocEntry)`, of which we have one for each (loaded and unloaded) file and macro expansion. This causes a memory regression in modules builds. Move the filename down into the `ContentCache`, which is a side data structure for `FileInfo` that does not impact `sizeof(SLocEntry)`. Once `FileEntryRef` is used for `ContentCache::OrigEntry` this can go away. Differential Revision: https://reviews.llvm.org/D89580 Radar-Id: rdar://59908826 Added: Modified: clang/include/clang/Basic/SourceManager.h clang/lib/Basic/SourceManager.cpp Removed: diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index 99428e6d7efa..ec9b2b7d0cfd 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -134,6 +134,8 @@ namespace SrcMgr { /// /// It is possible for this to be NULL if the ContentCache encapsulates /// an imaginary text buffer. +/// +/// FIXME: Turn this into a FileEntryRef and remove Filename. const FileEntry *OrigEntry; /// References the file which the contents were actually loaded from. @@ -142,6 +144,11 @@ namespace SrcMgr { /// with the contents of another file. const FileEntry *ContentsEntry; +/// The filename that is used to access OrigEntry. +/// +/// FIXME: Remove this once OrigEntry is a FileEntryRef with a stable name. +StringRef Filename; + /// A bump pointer allocated array of offsets for each source line. /// /// This is lazily computed. The lines are owned by the SourceManager @@ -266,7 +273,11 @@ namespace SrcMgr { /// from. This information encodes the \#include chain that a token was /// expanded from. The main include file has an invalid IncludeLoc. /// - /// FileInfos contain a "ContentCache *", with the contents of the file. + /// FileInfo should not grow larger than ExpansionInfo. Doing so will + /// cause memory to bloat in compilations with many unloaded macro + /// expansions, since the two data structurs are stored in a union in + /// SLocEntry. Extra fields should instead go in "ContentCache *", which + /// stores file contents and other bits on the side. /// class FileInfo { friend class clang::SourceManager; @@ -291,10 +302,6 @@ namespace SrcMgr { llvm::PointerIntPair ContentAndKind; -/// The filename that is used to access the file entry represented by the -/// content cache. -StringRef Filename; - public: /// Return a FileInfo object. static FileInfo get(SourceLocation IL, ContentCache &Con, @@ -305,7 +312,7 @@ namespace SrcMgr { X.HasLineDirectives = false; X.ContentAndKind.setPointer(&Con); X.ContentAndKind.setInt(FileCharacter); - X.Filename = Filename; + Con.Filename = Filename; return X; } @@ -333,7 +340,7 @@ namespace SrcMgr { /// Returns the name of the file that was used when the file was loaded from /// the underlying file system. -StringRef getName() const { return Filename; } +StringRef getName() const { return getContentCache().Filename; } }; /// Each ExpansionInfo encodes the expansion location - where @@ -454,6 +461,13 @@ namespace SrcMgr { } }; + // Assert that the \c FileInfo objects are no bigger than \c ExpansionInfo + // objects. This controls the size of \c SLocEntry, of which we have one for + // each macro expansion. The number of (unloaded) macro expansions can be + // very large. Any other fields needed in FileInfo should go in ContentCache. + static_assert(sizeof(FileInfo) <= sizeof(ExpansionInfo), +"FileInfo must be no larger than ExpansionInfo."); + /// This is a discriminated union of FileInfo and ExpansionInfo. /// /// SourceManager keeps an array of these objects, and they are uniquely diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 2ceb8046098f..6eae0f06a122 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -1734,7 +1734,7 @@ void SourceManager::computeMacroArgsCache(MacroArgsMap &MacroArgsCache, // Predefined header doesn't have a valid include location in main
[clang] 0387015 - SourceManager: Return non-const references in getOrCreateContentCache and related, NFC
Author: Duncan P. N. Exon Smith Date: 2020-10-26T14:07:46-04:00 New Revision: 0387015d7549fc2c0cc8c45d3e78114cc4fd153f URL: https://github.com/llvm/llvm-project/commit/0387015d7549fc2c0cc8c45d3e78114cc4fd153f DIFF: https://github.com/llvm/llvm-project/commit/0387015d7549fc2c0cc8c45d3e78114cc4fd153f.diff LOG: SourceManager: Return non-const references in getOrCreateContentCache and related, NFC Update a few APIs to return non-const references instead of pointers, and remove associated `const_cast`s and non-null assertions. Differential Revision: https://reviews.llvm.org/D90067 Added: Modified: clang/include/clang/Basic/SourceManager.h clang/lib/Basic/SourceManager.cpp clang/lib/Serialization/ASTReader.cpp Removed: diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index a458ef7e72a8..99428e6d7efa 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -297,7 +297,7 @@ namespace SrcMgr { public: /// Return a FileInfo object. -static FileInfo get(SourceLocation IL, const ContentCache &Con, +static FileInfo get(SourceLocation IL, ContentCache &Con, CharacteristicKind FileCharacter, StringRef Filename) { FileInfo X; X.IncludeLoc = IL.getRawEncoding(); @@ -923,7 +923,7 @@ class SourceManager : public RefCountedBase { llvm::MemoryBufferRef getMemoryBufferForFileOrFake(const FileEntry *File) { if (auto B = getMemoryBufferForFileOrNone(File)) return *B; -return getFakeBufferForRecovery()->getMemBufferRef(); +return getFakeBufferForRecovery(); } /// Override the contents of the given source file by providing an @@ -1008,7 +1008,7 @@ class SourceManager : public RefCountedBase { getBufferOrFake(FileID FID, SourceLocation Loc = SourceLocation()) const { if (auto B = getBufferOrNone(FID, Loc)) return *B; -return getFakeBufferForRecovery()->getMemBufferRef(); +return getFakeBufferForRecovery(); } /// Returns the FileEntry record for the provided FileID. @@ -1738,8 +1738,8 @@ class SourceManager : public RefCountedBase { friend class ASTReader; friend class ASTWriter; - llvm::MemoryBuffer *getFakeBufferForRecovery() const; - const SrcMgr::ContentCache *getFakeContentCacheForRecovery() const; + llvm::MemoryBufferRef getFakeBufferForRecovery() const; + SrcMgr::ContentCache &getFakeContentCacheForRecovery() const; const SrcMgr::SLocEntry &loadSLocEntry(unsigned Index, bool *Invalid) const; @@ -1811,17 +1811,16 @@ class SourceManager : public RefCountedBase { /// /// This works regardless of whether the ContentCache corresponds to a /// file or some other input source. - FileID createFileIDImpl(const SrcMgr::ContentCache &File, StringRef Filename, + FileID createFileIDImpl(SrcMgr::ContentCache &File, StringRef Filename, SourceLocation IncludePos, SrcMgr::CharacteristicKind DirCharacter, int LoadedID, unsigned LoadedOffset); - const SrcMgr::ContentCache * -getOrCreateContentCache(const FileEntry *SourceFile, -bool isSystemFile = false); + SrcMgr::ContentCache &getOrCreateContentCache(const FileEntry *SourceFile, +bool isSystemFile = false); /// Create a new ContentCache for the specified memory buffer. - const SrcMgr::ContentCache * + SrcMgr::ContentCache & createMemBufferContentCache(std::unique_ptr Buf); FileID getFileIDSlow(unsigned SLocOffset) const; diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 1feb8c7b66dd..2ceb8046098f 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -380,16 +380,14 @@ void SourceManager::initializeForReplay(const SourceManager &Old) { } } -/// getOrCreateContentCache - Create or return a cached ContentCache for the -/// specified file. -const ContentCache * -SourceManager::getOrCreateContentCache(const FileEntry *FileEnt, - bool isSystemFile) { +ContentCache &SourceManager::getOrCreateContentCache(const FileEntry *FileEnt, + bool isSystemFile) { assert(FileEnt && "Didn't specify a file entry to use?"); // Do we already have information about this file? ContentCache *&Entry = FileInfos[FileEnt]; - if (Entry) return Entry; + if (Entry) +return *Entry; // Nope, create a new Cache entry. Entry = ContentCacheAlloc.Allocate(); @@ -412,19 +410,19 @@ SourceManager::getOrCreateContentCache(const FileEntry *FileEnt, Entry->IsFileVolatile = UserFilesAreVolatile && !isSystemFile; Entry->IsTransient = FilesAreTransient; - return Entry; + return *Entry; }
[clang] 74910cb - HeaderSearch: Simplify use of FileEntryRef in HeaderSearch::LookupFile, NFC
Author: Duncan P. N. Exon Smith Date: 2020-10-23T22:10:50-04:00 New Revision: 74910cbbd8d1df824ab1d5e742c50641d0fee907 URL: https://github.com/llvm/llvm-project/commit/74910cbbd8d1df824ab1d5e742c50641d0fee907 DIFF: https://github.com/llvm/llvm-project/commit/74910cbbd8d1df824ab1d5e742c50641d0fee907.diff LOG: HeaderSearch: Simplify use of FileEntryRef in HeaderSearch::LookupFile, NFC Simplify `HeaderSearch::LookupFile`. Instead of deconstructing a `FileEntryRef` into a name and `FileEntry` and then rebuilding it later, use it as is. This helps to unblock making the constructor of `FileEntryRef` private to `FileManager`. Differential Revision: Added: Modified: clang/lib/Lex/HeaderSearch.cpp Removed: diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 3fd43e0e3aad..50c1fb984206 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -765,8 +765,7 @@ Optional HeaderSearch::LookupFile( // This is the header that MSVC's header search would have found. ModuleMap::KnownHeader MSSuggestedModule; - const FileEntry *MSFE_FE = nullptr; - StringRef MSFE_Name; + Optional MSFE; // Unless disabled, check to see if the file is in the #includer's // directory. This cannot be based on CurDir, because each includer could be @@ -841,8 +840,7 @@ Optional HeaderSearch::LookupFile( if (Diags.isIgnored(diag::ext_pp_include_search_ms, IncludeLoc)) { return FE; } else { - MSFE_FE = &FE->getFileEntry(); - MSFE_Name = FE->getName(); + MSFE = FE; if (SuggestedModule) { MSSuggestedModule = *SuggestedModule; *SuggestedModule = ModuleMap::KnownHeader(); @@ -854,9 +852,6 @@ Optional HeaderSearch::LookupFile( } } - Optional MSFE(MSFE_FE ? FileEntryRef(MSFE_Name, *MSFE_FE) - : Optional()); - CurDir = nullptr; // If this is a system #include, ignore the user #include locs. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 434f377 - clangd: Stop calling FileEntryRef::FileEntryRef
Author: Duncan P. N. Exon Smith Date: 2020-10-23T21:28:09-04:00 New Revision: 434f3774f629f5896614e9efb4eda82d813402ed URL: https://github.com/llvm/llvm-project/commit/434f3774f629f5896614e9efb4eda82d813402ed DIFF: https://github.com/llvm/llvm-project/commit/434f3774f629f5896614e9efb4eda82d813402ed.diff LOG: clangd: Stop calling FileEntryRef::FileEntryRef In `ReplayPreamble::replay`, use `getFileRef` instead of `getFile`, and then use that `FileEntryRef` later to avoid needing `FileEntryRef::FileEntryRef`. The latter is going to become private to `FileManager` in a later commit. Added: Modified: clang-tools-extra/clangd/ParsedAST.cpp Removed: diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp index c8096017b50a..6ca9c4f93d16 100644 --- a/clang-tools-extra/clangd/ParsedAST.cpp +++ b/clang-tools-extra/clangd/ParsedAST.cpp @@ -170,10 +170,9 @@ class ReplayPreamble : private PPCallbacks { void replay() { for (const auto &Inc : Includes) { - const FileEntry *File = nullptr; + llvm::Optional File; if (Inc.Resolved != "") -if (auto FE = SM.getFileManager().getFile(Inc.Resolved)) - File = *FE; +File = expectedToOptional(SM.getFileManager().getFileRef(Inc.Resolved)); // Re-lex the #include directive to find its interesting parts. auto HashLoc = SM.getComposedLoc(SM.getMainFileID(), Inc.HashOffset); @@ -211,17 +210,16 @@ class ReplayPreamble : private PPCallbacks { SynthesizedFilenameTok.setKind(tok::header_name); SynthesizedFilenameTok.setLiteralData(Inc.Written.data()); + const FileEntry *FE = File ? &File->getFileEntry() : nullptr; llvm::StringRef WrittenFilename = llvm::StringRef(Inc.Written).drop_front().drop_back(); Delegate->InclusionDirective(HashTok->location(), SynthesizedIncludeTok, WrittenFilename, Inc.Written.front() == '<', - FileTok->range(SM).toCharRange(SM), File, + FileTok->range(SM).toCharRange(SM), FE, "SearchPath", "RelPath", /*Imported=*/nullptr, Inc.FileKind); if (File) -// FIXME: Use correctly named FileEntryRef. -Delegate->FileSkipped(FileEntryRef(File->getName(), *File), - SynthesizedFilenameTok, Inc.FileKind); +Delegate->FileSkipped(*File, SynthesizedFilenameTok, Inc.FileKind); else { llvm::SmallString<1> UnusedRecovery; Delegate->FileNotFound(WrittenFilename, UnusedRecovery); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits