r312917 - [PCH] Allow VFS to be used for tests that generate PCH files
Author: cameron314 Date: Mon Sep 11 08:03:23 2017 New Revision: 312917 URL: http://llvm.org/viewvc/llvm-project?rev=312917&view=rev Log: [PCH] Allow VFS to be used for tests that generate PCH files When using a virtual file-system (VFS) and a preamble file (PCH) is generated, it is generated on-disk in the real file-system instead of in the VFS (which makes sense, since the VFS is read-only). However, when subsequently reading the generated PCH, the frontend passes through the VFS it has been given -- resulting in an error and a failed parse (since the VFS doesn't contain the PCH; the real filesystem does). This patch fixes that by detecting when a VFS is being used for a parse that needs to work with a PCH file, and creating an overlay VFS that includes the PCH file from the real file-system. This allows tests to be written which make use of both PCH files and a VFS. Differential Revision: https://reviews.llvm.org/D37474 Added: cfe/trunk/unittests/Frontend/PCHPreambleTest.cpp (with props) Modified: cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h cfe/trunk/lib/Frontend/ASTUnit.cpp cfe/trunk/unittests/Frontend/CMakeLists.txt Modified: cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h?rev=312917&r1=312916&r2=312917&view=diff == --- cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h (original) +++ cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h Mon Sep 11 08:03:23 2017 @@ -97,9 +97,12 @@ public: PrecompiledPreamble(PrecompiledPreamble &&) = default; PrecompiledPreamble &operator=(PrecompiledPreamble &&) = default; - /// PreambleBounds used to build the preamble + /// PreambleBounds used to build the preamble. PreambleBounds getBounds() const; + /// The temporary file path at which the preamble PCH was placed. + StringRef GetPCHPath() const { return PCHFile.getFilePath(); } + /// Check whether PrecompiledPreamble can be reused for the new contents(\p /// MainFileBuffer) of the main file. bool CanReuse(const CompilerInvocation &Invocation, Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=312917&r1=312916&r2=312917&view=diff == --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original) +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Sep 11 08:03:23 2017 @@ -1009,6 +1009,24 @@ static void checkAndSanitizeDiags(SmallV } } +static IntrusiveRefCntPtr createVFSOverlayForPreamblePCH( +StringRef PCHFilename, +IntrusiveRefCntPtr RealFS, +IntrusiveRefCntPtr VFS) { + // We want only the PCH file from the real filesystem to be available, + // so we create an in-memory VFS with just that and overlay it on top. + auto Buf = RealFS->getBufferForFile(PCHFilename); + if (!Buf) +return VFS; + IntrusiveRefCntPtr + PCHFS(new vfs::InMemoryFileSystem()); + PCHFS->addFile(PCHFilename, 0, std::move(*Buf)); + IntrusiveRefCntPtr + Overlay(new vfs::OverlayFileSystem(VFS)); + Overlay->pushOverlay(PCHFS); + return Overlay; +} + /// Parse the source file into a translation unit using the given compiler /// invocation, replacing the current translation unit. /// @@ -1030,6 +1048,24 @@ bool ASTUnit::Parse(std::shared_ptrsetVirtualFileSystem(VFS); } + // Make sure we can access the PCH file even if we're using a VFS + if (!VFS && FileMgr) +VFS = FileMgr->getVirtualFileSystem(); + IntrusiveRefCntPtr RealFS = vfs::getRealFileSystem(); + if (OverrideMainBuffer && VFS && RealFS && VFS != RealFS && + !VFS->exists(Preamble->GetPCHPath())) { +// We have a slight inconsistency here -- we're using the VFS to +// read files, but the PCH was generated in the real file system. +VFS = createVFSOverlayForPreamblePCH(Preamble->GetPCHPath(), RealFS, VFS); +if (FileMgr) { + FileMgr = new FileManager(FileMgr->getFileSystemOpts(), VFS); + Clang->setFileManager(FileMgr.get()); +} +else { + Clang->setVirtualFileSystem(VFS); +} + } + // Recover resources if we crash before exiting this method. llvm::CrashRecoveryContextCleanupRegistrar CICleanup(Clang.get()); Modified: cfe/trunk/unittests/Frontend/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Frontend/CMakeLists.txt?rev=312917&r1=312916&r2=312917&view=diff == --- cfe/trunk/unittests/Frontend/CMakeLists.txt (original) +++ cfe/trunk/unittests/Frontend/CMakeLists.txt Mon Sep 11 08:03:23 2017 @@ -6,6 +6,7 @@ add_clang_unittest(FrontendTests ASTUnitTest.cpp FrontendActionTest.cpp CodeGenActionTest.cpp + PCHPreambleTest.cpp ) target_link_libraries(FrontendTests clangAST Added: cfe/trunk/unittests/Front
r313796 - [PCH] Fixed preamble breaking with BOM presence (and particularly, fluctuating BOM presence)
Author: cameron314 Date: Wed Sep 20 12:03:37 2017 New Revision: 313796 URL: http://llvm.org/viewvc/llvm-project?rev=313796&view=rev Log: [PCH] Fixed preamble breaking with BOM presence (and particularly, fluctuating BOM presence) This patch fixes broken preamble-skipping when the preamble region includes a byte order mark (BOM). Previously, parsing would fail if preamble PCH generation was enabled and a BOM was present. This also fixes preamble invalidation when a BOM appears or disappears. This may seem to be an obscure edge case, but it happens regularly with IDEs that pass buffer overrides that never (or always) have a BOM, yet the underlying file from the initial parse that generated a PCH might (or might not) have a BOM. I've included a test case for these scenarios. Differential Revision: https://reviews.llvm.org/D37491 Modified: cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h cfe/trunk/include/clang/Lex/Lexer.h cfe/trunk/include/clang/Lex/PreprocessorOptions.h cfe/trunk/lib/Frontend/FrontendActions.cpp cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp cfe/trunk/lib/Lex/Lexer.cpp cfe/trunk/lib/Lex/Preprocessor.cpp cfe/trunk/unittests/Frontend/PCHPreambleTest.cpp Modified: cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h?rev=313796&r1=313795&r2=313796&view=diff == --- cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h (original) +++ cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h Wed Sep 20 12:03:37 2017 @@ -36,21 +36,6 @@ class CompilerInvocation; class DeclGroupRef; class PCHContainerOperations; -/// A size of the preamble and a flag required by -/// PreprocessorOptions::PrecompiledPreambleBytes. -struct PreambleBounds { - PreambleBounds(unsigned Size, bool PreambleEndsAtStartOfLine) - : Size(Size), PreambleEndsAtStartOfLine(PreambleEndsAtStartOfLine) {} - - /// \brief Size of the preamble in bytes. - unsigned Size; - /// \brief Whether the preamble ends at the start of a new line. - /// - /// Used to inform the lexer as to whether it's starting at the beginning of - /// a line after skipping the preamble. - bool PreambleEndsAtStartOfLine; -}; - /// \brief Runs lexer to compute suggested preamble bounds. PreambleBounds ComputePreambleBounds(const LangOptions &LangOpts, llvm::MemoryBuffer *Buffer, Modified: cfe/trunk/include/clang/Lex/Lexer.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=313796&r1=313795&r2=313796&view=diff == --- cfe/trunk/include/clang/Lex/Lexer.h (original) +++ cfe/trunk/include/clang/Lex/Lexer.h Wed Sep 20 12:03:37 2017 @@ -39,6 +39,23 @@ enum ConflictMarkerKind { CMK_Perforce }; +/// Describes the bounds (start, size) of the preamble and a flag required by +/// PreprocessorOptions::PrecompiledPreambleBytes. +/// The preamble includes the BOM, if any. +struct PreambleBounds { + PreambleBounds(unsigned Size, bool PreambleEndsAtStartOfLine) +: Size(Size), + PreambleEndsAtStartOfLine(PreambleEndsAtStartOfLine) {} + + /// \brief Size of the preamble in bytes. + unsigned Size; + /// \brief Whether the preamble ends at the start of a new line. + /// + /// Used to inform the lexer as to whether it's starting at the beginning of + /// a line after skipping the preamble. + bool PreambleEndsAtStartOfLine; +}; + /// Lexer - This provides a simple interface that turns a text buffer into a /// stream of tokens. This provides no support for file reading or buffering, /// or buffering/seeking of tokens, only forward lexing is supported. It relies @@ -443,11 +460,11 @@ public: /// to fewer than this number of lines. /// /// \returns The offset into the file where the preamble ends and the rest - /// of the file begins along with a boolean value indicating whether + /// of the file begins along with a boolean value indicating whether /// the preamble ends at the beginning of a new line. - static std::pair ComputePreamble(StringRef Buffer, - const LangOptions &LangOpts, - unsigned MaxLines = 0); + static PreambleBounds ComputePreamble(StringRef Buffer, +const LangOptions &LangOpts, +unsigned MaxLines = 0); /// \brief Checks that the given token is the first token that occurs after /// the given location (this excludes comments and whitespace). Returns the @@ -618,7 +635,7 @@ private: //======// // Other lexer functions. - void SkipBytes(unsigned Bytes, bool StartOfLine); + void SetByteOf
r313802 - Fixed unused variable warning introduced in r313796 causing build failure
Author: cameron314 Date: Wed Sep 20 12:37:37 2017 New Revision: 313802 URL: http://llvm.org/viewvc/llvm-project?rev=313802&view=rev Log: Fixed unused variable warning introduced in r313796 causing build failure Modified: cfe/trunk/lib/Lex/Lexer.cpp Modified: cfe/trunk/lib/Lex/Lexer.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=313802&r1=313801&r2=313802&view=diff == --- cfe/trunk/lib/Lex/Lexer.cpp (original) +++ cfe/trunk/lib/Lex/Lexer.cpp Wed Sep 20 12:37:37 2017 @@ -564,9 +564,6 @@ PreambleBounds Lexer::ComputePreamble(St Buffer.end()); TheLexer.SetCommentRetentionState(true); - // StartLoc will differ from FileLoc if there is a BOM that was skipped. - SourceLocation StartLoc = TheLexer.getSourceLocation(); - bool InPreprocessorDirective = false; Token TheTok; SourceLocation ActiveCommentLoc; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 358eaa3 - [clang-format] Flexible line endings
Author: Cameron Desrochers Date: 2019-11-15T11:50:22-05:00 New Revision: 358eaa3dcea1dee6350c2cbf80aab3c25db4d4d9 URL: https://github.com/llvm/llvm-project/commit/358eaa3dcea1dee6350c2cbf80aab3c25db4d4d9 DIFF: https://github.com/llvm/llvm-project/commit/358eaa3dcea1dee6350c2cbf80aab3c25db4d4d9.diff LOG: [clang-format] Flexible line endings Line ending detection is now set with the `DeriveLineEnding` option. CRLF can now be used as the default line ending by setting `UseCRLF`. When line ending detection is disabled, all line endings are converted according to the `UseCRLF` option. Differential Revision: https://reviews.llvm.org/D19031 Added: Modified: clang/include/clang/Format/Format.h clang/lib/Format/Format.cpp clang/unittests/Format/FormatTest.cpp Removed: diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 329579bea3d4..f5c356fa2262 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -1217,6 +1217,10 @@ struct FormatStyle { /// \endcode bool Cpp11BracedListStyle; + /// \brief Analyze the formatted file for the most used line ending (``\r\n`` + /// or ``\n``). ``UseCRLF`` is only used as a fallback if none can be derived. + bool DeriveLineEnding; + /// If ``true``, analyze the formatted file for the most common /// alignment of ``&`` and ``*``. /// Pointer and reference alignment styles are going to be updated according @@ -2032,6 +2036,10 @@ struct FormatStyle { UT_Always }; + /// \brief Use ``\r\n`` instead of ``\n`` for line breaks. + /// Also used as fallback if ``DeriveLineEnding`` is true. + bool UseCRLF; + /// The way to use tab characters in the resulting file. UseTabStyle UseTab; @@ -2079,6 +2087,7 @@ struct FormatStyle { R.ConstructorInitializerIndentWidth && ContinuationIndentWidth == R.ContinuationIndentWidth && Cpp11BracedListStyle == R.Cpp11BracedListStyle && + DeriveLineEnding == R.DeriveLineEnding && DerivePointerAlignment == R.DerivePointerAlignment && DisableFormat == R.DisableFormat && ExperimentalAutoDetectBinPacking == @@ -2143,6 +2152,7 @@ struct FormatStyle { SpacesInSquareBrackets == R.SpacesInSquareBrackets && Standard == R.Standard && TabWidth == R.TabWidth && StatementMacros == R.StatementMacros && UseTab == R.UseTab && + UseCRLF == R.UseCRLF && TypenameMacros == R.TypenameMacros; } diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 60958597ad21..083c3a8f02fd 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -467,6 +467,7 @@ template <> struct MappingTraits { Style.ConstructorInitializerIndentWidth); IO.mapOptional("ContinuationIndentWidth", Style.ContinuationIndentWidth); IO.mapOptional("Cpp11BracedListStyle", Style.Cpp11BracedListStyle); +IO.mapOptional("DeriveLineEnding", Style.DeriveLineEnding); IO.mapOptional("DerivePointerAlignment", Style.DerivePointerAlignment); IO.mapOptional("DisableFormat", Style.DisableFormat); IO.mapOptional("ExperimentalAutoDetectBinPacking", @@ -546,6 +547,7 @@ template <> struct MappingTraits { IO.mapOptional("StatementMacros", Style.StatementMacros); IO.mapOptional("TabWidth", Style.TabWidth); IO.mapOptional("TypenameMacros", Style.TypenameMacros); +IO.mapOptional("UseCRLF", Style.UseCRLF); IO.mapOptional("UseTab", Style.UseTab); } }; @@ -762,6 +764,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { LLVMStyle.ConstructorInitializerIndentWidth = 4; LLVMStyle.ContinuationIndentWidth = 4; LLVMStyle.Cpp11BracedListStyle = true; + LLVMStyle.DeriveLineEnding = true; LLVMStyle.DerivePointerAlignment = false; LLVMStyle.ExperimentalAutoDetectBinPacking = false; LLVMStyle.FixNamespaceComments = true; @@ -792,6 +795,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { LLVMStyle.PointerAlignment = FormatStyle::PAS_Right; LLVMStyle.SpacesBeforeTrailingComments = 1; LLVMStyle.Standard = FormatStyle::LS_Latest; + LLVMStyle.UseCRLF = false; LLVMStyle.UseTab = FormatStyle::UT_Never; LLVMStyle.ReflowComments = true; LLVMStyle.SpacesInParentheses = false; @@ -1350,7 +1354,10 @@ class Formatter : public TokenAnalyzer { WhitespaceManager Whitespaces( Env.getSourceManager(), Style, -inputUsesCRLF(Env.getSourceManager().getBufferData(Env.getFileID(; +Style.DeriveLineEnding ? + inputUsesCRLF(Env.getSourceManager().getBufferData(Env.getFileID()), +Style.UseCRLF) : + Style.UseCRLF); ContinuationIndenter Indenter(Style, Tokens.getKeywords(), Env.getSourceManager(), W
r279076 - [libclang] Add clang_getAllSkippedRanges function
Author: cameron314 Date: Thu Aug 18 10:43:55 2016 New Revision: 279076 URL: http://llvm.org/viewvc/llvm-project?rev=279076&view=rev Log: [libclang] Add clang_getAllSkippedRanges function This complements the clang_getSkippedRanges function which returns skipped ranges filtered by a specific file. This function is useful when all the ranges are desired (and a lot more efficient than the equivalent of asking for the ranges file by file, since the implementation of clang_getSkippedRanges iterates over all ranges anyway). Differential Revision: https://reviews.llvm.org/D20132 Modified: cfe/trunk/include/clang-c/Index.h cfe/trunk/tools/libclang/CIndex.cpp cfe/trunk/unittests/libclang/LibclangTest.cpp Modified: cfe/trunk/include/clang-c/Index.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=279076&r1=279075&r2=279076&view=diff == --- cfe/trunk/include/clang-c/Index.h (original) +++ cfe/trunk/include/clang-c/Index.h Thu Aug 18 10:43:55 2016 @@ -627,6 +627,15 @@ CINDEX_LINKAGE CXSourceRangeList *clang_ CXFile file); /** + * \brief Retrieve all ranges from all files that were skipped by the + * preprocessor. + * + * The preprocessor will skip lines when they are surrounded by an + * if/ifdef/ifndef directive whose condition does not evaluate to true. + */ +CINDEX_LINKAGE CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit tu); + +/** * \brief Destroy the given \c CXSourceRangeList. */ CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges); Modified: cfe/trunk/tools/libclang/CIndex.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=279076&r1=279075&r2=279076&view=diff == --- cfe/trunk/tools/libclang/CIndex.cpp (original) +++ cfe/trunk/tools/libclang/CIndex.cpp Thu Aug 18 10:43:55 2016 @@ -7773,6 +7773,33 @@ CXSourceRangeList *clang_getSkippedRange return skipped; } +CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit TU) { + CXSourceRangeList *skipped = new CXSourceRangeList; + skipped->count = 0; + skipped->ranges = nullptr; + + if (isNotUsableTU(TU)) { +LOG_BAD_TU(TU); +return skipped; + } + + ASTUnit *astUnit = cxtu::getASTUnit(TU); + PreprocessingRecord *ppRec = astUnit->getPreprocessor().getPreprocessingRecord(); + if (!ppRec) +return skipped; + + ASTContext &Ctx = astUnit->getASTContext(); + + const std::vector &SkippedRanges = ppRec->getSkippedRanges(); + + skipped->count = SkippedRanges.size(); + skipped->ranges = new CXSourceRange[skipped->count]; + for (unsigned i = 0, ei = skipped->count; i != ei; ++i) +skipped->ranges[i] = cxloc::translateSourceRange(Ctx, SkippedRanges[i]); + + return skipped; +} + void clang_disposeSourceRangeList(CXSourceRangeList *ranges) { if (ranges) { delete[] ranges->ranges; Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=279076&r1=279075&r2=279076&view=diff == --- cfe/trunk/unittests/libclang/LibclangTest.cpp (original) +++ cfe/trunk/unittests/libclang/LibclangTest.cpp Thu Aug 18 10:43:55 2016 @@ -14,6 +14,9 @@ #include "llvm/Support/raw_ostream.h" #include "gtest/gtest.h" #include +#include +#include +#include #include #define DEBUG_TYPE "libclang-test" @@ -349,21 +352,25 @@ TEST(libclang, ModuleMapDescriptor) { clang_ModuleMapDescriptor_dispose(MMD); } -class LibclangReparseTest : public ::testing::Test { +class LibclangParseTest : public ::testing::Test { std::set Files; + typedef std::unique_ptr fixed_addr_string; + std::map UnsavedFileContents; public: std::string TestDir; CXIndex Index; CXTranslationUnit ClangTU; unsigned TUFlags; + std::vector UnsavedFiles; void SetUp() override { llvm::SmallString<256> Dir; ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory("libclang-test", Dir)); TestDir = Dir.str(); TUFlags = CXTranslationUnit_DetailedPreprocessingRecord | - clang_defaultEditingTranslationUnitOptions(); + clang_defaultEditingTranslationUnitOptions(); Index = clang_createIndex(0, 0); +ClangTU = nullptr; } void TearDown() override { clang_disposeTranslationUnit(ClangTU); @@ -384,6 +391,77 @@ public: OS << Contents; assert(OS.good()); } + void MapUnsavedFile(std::string Filename, const std::string &Contents) { +if (!llvm::sys::path::is_absolute(Filename)) { + llvm::SmallString<256> Path(TestDir); + llvm::sys::path::append(Path, Filename); + Filename = Path.str(); +} +auto it = UnsavedFileContents.emplace( +fixed_addr_string(new std::string(Filename)), +
r279085 - [libclang] Fixed signed/unsigned comparison warning introduced in my revision r279076
Author: cameron314 Date: Thu Aug 18 11:25:42 2016 New Revision: 279085 URL: http://llvm.org/viewvc/llvm-project?rev=279085&view=rev Log: [libclang] Fixed signed/unsigned comparison warning introduced in my revision r279076 Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=279085&r1=279084&r2=279085&view=diff == --- cfe/trunk/unittests/libclang/LibclangTest.cpp (original) +++ cfe/trunk/unittests/libclang/LibclangTest.cpp Thu Aug 18 11:25:42 2016 @@ -439,7 +439,7 @@ TEST_F(LibclangParseTest, AllSkippedRang nullptr, 0, TUFlags); CXSourceRangeList *Ranges = clang_getAllSkippedRanges(ClangTU); - EXPECT_EQ(2, Ranges->count); + EXPECT_EQ(2u, Ranges->count); CXSourceLocation cxl; unsigned line; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r279092 - [libclang] Added missing entry for newly introduced 'clang_getAllSkippedRanges' to libclang.exports
Author: cameron314 Date: Thu Aug 18 12:18:03 2016 New Revision: 279092 URL: http://llvm.org/viewvc/llvm-project?rev=279092&view=rev Log: [libclang] Added missing entry for newly introduced 'clang_getAllSkippedRanges' to libclang.exports Modified: cfe/trunk/tools/libclang/libclang.exports Modified: cfe/trunk/tools/libclang/libclang.exports URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=279092&r1=279091&r2=279092&view=diff == --- cfe/trunk/tools/libclang/libclang.exports (original) +++ cfe/trunk/tools/libclang/libclang.exports Thu Aug 18 12:18:03 2016 @@ -142,6 +142,7 @@ clang_findReferencesInFile clang_findReferencesInFileWithBlock clang_formatDiagnostic clang_free +clang_getAllSkippedRanges clang_getArgType clang_getArrayElementType clang_getArraySize ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r279114 - Removed use of 'emplace' on std::map, since not all buildbot slaves support it
Author: cameron314 Date: Thu Aug 18 13:41:41 2016 New Revision: 279114 URL: http://llvm.org/viewvc/llvm-project?rev=279114&view=rev Log: Removed use of 'emplace' on std::map, since not all buildbot slaves support it Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=279114&r1=279113&r2=279114&view=diff == --- cfe/trunk/unittests/libclang/LibclangTest.cpp (original) +++ cfe/trunk/unittests/libclang/LibclangTest.cpp Thu Aug 18 13:41:41 2016 @@ -397,9 +397,9 @@ public: llvm::sys::path::append(Path, Filename); Filename = Path.str(); } -auto it = UnsavedFileContents.emplace( +auto it = UnsavedFileContents.insert(std::make_pair( fixed_addr_string(new std::string(Filename)), -fixed_addr_string(new std::string(Contents))); +fixed_addr_string(new std::string(Contents; UnsavedFiles.push_back({ it.first->first->c_str(), // filename it.first->second->c_str(), // contents ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r279145 - Fixed more signed/unsigned mismatch warnings introduced in my change at r279076
Author: cameron314 Date: Thu Aug 18 15:56:48 2016 New Revision: 279145 URL: http://llvm.org/viewvc/llvm-project?rev=279145&view=rev Log: Fixed more signed/unsigned mismatch warnings introduced in my change at r279076 Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=279145&r1=279144&r2=279145&view=diff == --- cfe/trunk/unittests/libclang/LibclangTest.cpp (original) +++ cfe/trunk/unittests/libclang/LibclangTest.cpp Thu Aug 18 15:56:48 2016 @@ -439,23 +439,23 @@ TEST_F(LibclangParseTest, AllSkippedRang nullptr, 0, TUFlags); CXSourceRangeList *Ranges = clang_getAllSkippedRanges(ClangTU); - EXPECT_EQ(2u, Ranges->count); + EXPECT_EQ(2U, Ranges->count); CXSourceLocation cxl; unsigned line; cxl = clang_getRangeStart(Ranges->ranges[0]); clang_getSpellingLocation(cxl, nullptr, &line, nullptr, nullptr); - EXPECT_EQ(1, line); + EXPECT_EQ(1U, line); cxl = clang_getRangeEnd(Ranges->ranges[0]); clang_getSpellingLocation(cxl, nullptr, &line, nullptr, nullptr); - EXPECT_EQ(3, line); + EXPECT_EQ(3U, line); cxl = clang_getRangeStart(Ranges->ranges[1]); clang_getSpellingLocation(cxl, nullptr, &line, nullptr, nullptr); - EXPECT_EQ(2, line); + EXPECT_EQ(2U, line); cxl = clang_getRangeEnd(Ranges->ranges[1]); clang_getSpellingLocation(cxl, nullptr, &line, nullptr, nullptr); - EXPECT_EQ(4, line); + EXPECT_EQ(4U, line); clang_disposeSourceRangeList(Ranges); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r322503 - [PCH] Serialize skipped preprocessor ranges
Author: cameron314 Date: Mon Jan 15 11:14:16 2018 New Revision: 322503 URL: http://llvm.org/viewvc/llvm-project?rev=322503&view=rev Log: [PCH] Serialize skipped preprocessor ranges The skipped preprocessor ranges are now serialized in the AST PCH file. This fixes, for example, libclang's clang_getSkippedRanges() returning zero ranges after reparsing a translation unit. Differential Revision: https://reviews.llvm.org/D20124 Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h cfe/trunk/include/clang/Serialization/ASTBitCodes.h cfe/trunk/include/clang/Serialization/ASTReader.h cfe/trunk/include/clang/Serialization/Module.h cfe/trunk/lib/Lex/PPDirectives.cpp cfe/trunk/lib/Lex/PreprocessingRecord.cpp cfe/trunk/lib/Serialization/ASTReader.cpp cfe/trunk/lib/Serialization/ASTWriter.cpp cfe/trunk/tools/libclang/CIndex.cpp cfe/trunk/unittests/libclang/LibclangTest.cpp Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=322503&r1=322502&r2=322503&view=diff == --- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original) +++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Mon Jan 15 11:14:16 2018 @@ -297,6 +297,9 @@ class Token; FileID FID) { return None; } + +/// \brief Read a preallocated skipped range from the external source. +virtual SourceRange ReadSkippedRange(unsigned Index) = 0; }; /// \brief A record of the steps taken while preprocessing a source file, @@ -322,6 +325,8 @@ class Token; /// \brief The set of ranges that were skipped by the preprocessor, std::vector SkippedRanges; +bool SkippedRangesAllLoaded = true; + /// \brief Global (loaded or local) ID for a preprocessed entity. /// Negative values are used to indicate preprocessed entities /// loaded from the external source while non-negative values are used to @@ -377,6 +382,16 @@ class Token; /// corresponds to the first newly-allocated entity. unsigned allocateLoadedEntities(unsigned NumEntities); +/// \brief Allocate space for a new set of loaded preprocessed skipped +/// ranges. +/// +/// \returns The index into the set of loaded preprocessed ranges, which +/// corresponds to the first newly-allocated range. +unsigned allocateSkippedRanges(unsigned NumRanges); + +/// \brief Ensures that all external skipped ranges have been loaded. +void ensureSkippedRangesLoaded(); + /// \brief Register a new macro definition. void RegisterMacroDefinition(MacroInfo *Macro, MacroDefinitionRecord *Def); @@ -499,7 +514,8 @@ class Token; MacroDefinitionRecord *findMacroDefinition(const MacroInfo *MI); /// \brief Retrieve all ranges that got skipped while preprocessing. -const std::vector &getSkippedRanges() const { +const std::vector &getSkippedRanges() { + ensureSkippedRangesLoaded(); return SkippedRanges; } Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=322503&r1=322502&r2=322503&view=diff == --- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original) +++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Mon Jan 15 11:14:16 2018 @@ -198,6 +198,25 @@ namespace serialization { } }; +/// \brief Source range of a skipped preprocessor region +struct PPSkippedRange { + /// \brief Raw source location of beginning of range. + unsigned Begin; + /// \brief Raw source location of end of range. + unsigned End; + + PPSkippedRange(SourceRange R) +: Begin(R.getBegin().getRawEncoding()), + End(R.getEnd().getRawEncoding()) { } + + SourceLocation getBegin() const { +return SourceLocation::getFromRawEncoding(Begin); + } + SourceLocation getEnd() const { +return SourceLocation::getFromRawEncoding(End); + } +}; + /// \brief Source range/offset of a preprocessed entity. struct DeclOffset { /// \brief Raw source location. @@ -627,6 +646,9 @@ namespace serialization { /// \brief The stack of open #ifs/#ifdefs recorded in a preamble. PP_CONDITIONAL_STACK = 62, + + /// \brief A table of skipped ranges within the preprocessing record. + PPD_SKIPPED_RANGES = 63 }; /// \brief Record types used within a source manager block. Modified: cfe/trunk/include/clang/Serialization/ASTReader.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=322503&r1=322502&r2=322503&view=diff ==
r322513 - Fixed memory leak in unit test introduced in my previous commit r322503
Author: cameron314 Date: Mon Jan 15 12:37:35 2018 New Revision: 322513 URL: http://llvm.org/viewvc/llvm-project?rev=322513&view=rev Log: Fixed memory leak in unit test introduced in my previous commit r322503 Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=322513&r1=322512&r2=322513&view=diff == --- cfe/trunk/unittests/libclang/LibclangTest.cpp (original) +++ cfe/trunk/unittests/libclang/LibclangTest.cpp Mon Jan 15 12:37:35 2018 @@ -592,6 +592,9 @@ TEST_F(LibclangReparseTest, Preprocessor if (i == 2) flags |= CXTranslationUnit_CreatePreambleOnFirstParse; +if (i != 0) + clang_disposeTranslationUnit(ClangTU); // dispose from previous iter + // parse once ClangTU = clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0, nullptr, 0, flags); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r286973 - [clang-format] Fixed line merging of more than two lines
Author: cameron314 Date: Tue Nov 15 09:07:07 2016 New Revision: 286973 URL: http://llvm.org/viewvc/llvm-project?rev=286973&view=rev Log: [clang-format] Fixed line merging of more than two lines Differential Revision: https://reviews.llvm.org/D19063 Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp?rev=286973&r1=286972&r2=286973&view=diff == --- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp (original) +++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp Tue Nov 15 09:07:07 2016 @@ -151,7 +151,7 @@ public: MergedLines = 0; if (!DryRun) for (unsigned i = 0; i < MergedLines; ++i) -join(*Next[i], *Next[i + 1]); +join(*Next[0], *Next[i + 1]); Next = Next + MergedLines + 1; return Current; } Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=286973&r1=286972&r2=286973&view=diff == --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Nov 15 09:07:07 2016 @@ -276,6 +276,30 @@ TEST_F(FormatTest, RemovesEmptyLines) { "int i;\n" "\n" "} // namespace")); + + FormatStyle Style = getLLVMStyle(); + Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; + Style.MaxEmptyLinesToKeep = 2; + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterClass = true; + Style.BraceWrapping.AfterFunction = true; + Style.KeepEmptyLinesAtTheStartOfBlocks = false; + + EXPECT_EQ("class Foo\n" +"{\n" +" Foo() {}\n" +"\n" +" void funk() {}\n" +"};", +format("class Foo\n" + "{\n" + " Foo()\n" + " {\n" + " }\n" + "\n" + " void funk() {}\n" + "};", + Style)); } TEST_F(FormatTest, RecognizesBinaryOperatorKeywords) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r269769 - [PCH] Fixed bug with preamble invalidation when overridden files change
Author: cameron314 Date: Tue May 17 09:34:53 2016 New Revision: 269769 URL: http://llvm.org/viewvc/llvm-project?rev=269769&view=rev Log: [PCH] Fixed bug with preamble invalidation when overridden files change When remapped files were changed, they would not always cause the preamble's PCH to be invalidated, because the remapped path didn't necessarily match the include path (e.g. slash direction -- this happens a lot on Windows). I fixed this by moving to a llvm::sys::fs::UniqueID-based map instead of comparing paths stringwise. Differential Revision: http://reviews.llvm.org/D20137 Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=269769&r1=269768&r2=269769&view=diff == --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original) +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Tue May 17 09:34:53 2016 @@ -1378,7 +1378,7 @@ ASTUnit::getMainBufferWithPrecompiledPre // First, make a record of those files that have been overridden via // remapping or unsaved_files. - llvm::StringMap OverriddenFiles; + std::map OverriddenFiles; for (const auto &R : PreprocessorOpts.RemappedFiles) { if (AnyFileChanged) break; @@ -1391,24 +1391,38 @@ ASTUnit::getMainBufferWithPrecompiledPre break; } -OverriddenFiles[R.first] = PreambleFileHash::createForFile( +OverriddenFiles[Status.getUniqueID()] = PreambleFileHash::createForFile( Status.getSize(), Status.getLastModificationTime().toEpochTime()); } for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) { if (AnyFileChanged) break; -OverriddenFiles[RB.first] = + +vfs::Status Status; +if (FileMgr->getNoncachedStatValue(RB.first, Status)) { + AnyFileChanged = true; + break; +} + +OverriddenFiles[Status.getUniqueID()] = PreambleFileHash::createForMemoryBuffer(RB.second); } // Check whether anything has changed. - for (llvm::StringMap::iterator + for (llvm::StringMap::iterator F = FilesInPreamble.begin(), FEnd = FilesInPreamble.end(); !AnyFileChanged && F != FEnd; ++F) { -llvm::StringMap::iterator Overridden - = OverriddenFiles.find(F->first()); +vfs::Status Status; +if (FileMgr->getNoncachedStatValue(F->first(), Status)) { + // If we can't stat the file, assume that something horrible happened. + AnyFileChanged = true; + break; +} + +std::map::iterator Overridden + = OverriddenFiles.find(Status.getUniqueID()); if (Overridden != OverriddenFiles.end()) { // This file was remapped; check whether the newly-mapped file // matches up with the previous mapping. @@ -1418,13 +1432,9 @@ ASTUnit::getMainBufferWithPrecompiledPre } // The file was not remapped; check whether it has changed on disk. -vfs::Status Status; -if (FileMgr->getNoncachedStatValue(F->first(), Status)) { - // If we can't stat the file, assume that something horrible happened. - AnyFileChanged = true; -} else if (Status.getSize() != uint64_t(F->second.Size) || - Status.getLastModificationTime().toEpochTime() != - uint64_t(F->second.ModTime)) +if (Status.getSize() != uint64_t(F->second.Size) || +Status.getLastModificationTime().toEpochTime() != +uint64_t(F->second.ModTime)) AnyFileChanged = true; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits