[clang] 1647ff6 - [ADT/STLExtras.h] - Add llvm::is_sorted wrapper and update callers.
Author: Georgii Rymar Date: 2020-04-14T14:11:02+03:00 New Revision: 1647ff6e2753026f8a1e21c60d37b83602520b64 URL: https://github.com/llvm/llvm-project/commit/1647ff6e2753026f8a1e21c60d37b83602520b64 DIFF: https://github.com/llvm/llvm-project/commit/1647ff6e2753026f8a1e21c60d37b83602520b64.diff LOG: [ADT/STLExtras.h] - Add llvm::is_sorted wrapper and update callers. It can be used to avoid passing the begin and end of a range. This makes the code shorter and it is consistent with another wrappers we already have. Differential revision: https://reviews.llvm.org/D78016 Added: Modified: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CGObjCMac.cpp clang/lib/Format/Format.cpp clang/lib/Format/SortJavaScriptImports.cpp clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp clang/lib/Tooling/Syntax/Tokens.cpp lld/wasm/InputFiles.cpp llvm/include/llvm/ADT/CoalescingBitVector.h llvm/include/llvm/ADT/STLExtras.h llvm/include/llvm/CodeGen/LiveInterval.h llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp llvm/lib/Analysis/LoopCacheAnalysis.cpp llvm/lib/Analysis/TargetLibraryInfo.cpp llvm/lib/Bitcode/Writer/ValueEnumerator.cpp llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp llvm/lib/Frontend/OpenMP/OMPContext.cpp llvm/lib/IR/AsmWriter.cpp llvm/lib/IR/Attributes.cpp llvm/lib/MC/MCSubtargetInfo.cpp llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp llvm/lib/Target/Mips/MipsCCState.cpp llvm/lib/Target/X86/X86EvexToVex.cpp llvm/lib/Target/X86/X86ISelLowering.cpp llvm/lib/Target/X86/X86InstrFMA3Info.cpp llvm/lib/Target/X86/X86InstrFoldTables.cpp llvm/lib/Target/X86/X86IntrinsicsInfo.h llvm/lib/Transforms/IPO/CalledValuePropagation.cpp llvm/tools/llvm-exegesis/lib/Target.cpp llvm/tools/llvm-objcopy/ELF/Object.cpp llvm/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp llvm/unittests/ADT/SimpleIListTest.cpp llvm/unittests/Support/ParallelTest.cpp Removed: diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h index ce16095e10c0..d2df24a6e21b 100644 --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h @@ -292,9 +292,7 @@ class AnalyzerOptions : public RefCountedBase { }; bool isUnknownAnalyzerConfig(StringRef Name) const { - -assert(std::is_sorted(AnalyzerConfigCmdFlags.begin(), - AnalyzerConfigCmdFlags.end())); +assert(llvm::is_sorted(AnalyzerConfigCmdFlags)); return !std::binary_search(AnalyzerConfigCmdFlags.begin(), AnalyzerConfigCmdFlags.end(), Name); diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index fb0c8b3aeaa3..812fdc61c25a 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -5352,7 +5352,7 @@ findARMVectorIntrinsicInMap(ArrayRef IntrinsicMap, #ifndef NDEBUG if (!MapProvenSorted) { -assert(std::is_sorted(std::begin(IntrinsicMap), std::end(IntrinsicMap))); +assert(llvm::is_sorted(IntrinsicMap)); MapProvenSorted = true; } #endif diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index 31ab7977b7d2..1d0379afb4b5 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -5451,7 +5451,7 @@ llvm::Constant *IvarLayoutBuilder::buildBitmap(CGObjCCommonMac &CGObjC, // This isn't a stable sort, but our algorithm should handle it fine. llvm::array_pod_sort(IvarsInfo.begin(), IvarsInfo.end()); } else { -assert(std::is_sorted(IvarsInfo.begin(), IvarsInfo.end())); +assert(llvm::is_sorted(IvarsInfo)); } assert(IvarsInfo.back().Offset < InstanceEnd); diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 4a5626d42209..9b65c79b3526 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -2049,8 +2049,7 @@ static void sortCppIncludes(const FormatStyle &Style, // enough as additional newlines might be added or removed across #include // blocks. This we handle below by generating the updated #imclude blocks and // comparing it to the original. - if (Indices.size() == Includes.size() && - std::is_sorted(Indices.begin(), Indices.end()) && + if (Indices.size() == Includes.size() && llvm::is_sorted(Indices) && Style.IncludeStyle.IncludeBlocks == tooling::IncludeStyle::IBS_Preserve) return; diff --git a/clang/lib/Format/SortJavaScriptImports.cpp b/clang/lib/Format/SortJavaScriptImports.cpp index 5be243f4c07a..db2b65b08898 100644 --- a/clang/lib/Format/SortJavaScriptImports.cpp +++ b/cl
[clang] 65a2de7 - [FileCheck] - Fix the false positive when -implicit-check-not is used with an unknown -check-prefix.
Author: Georgii Rymar Date: 2020-04-16T15:00:50+03:00 New Revision: 65a2de7e6c986193a630e691686c527b08f292d5 URL: https://github.com/llvm/llvm-project/commit/65a2de7e6c986193a630e691686c527b08f292d5 DIFF: https://github.com/llvm/llvm-project/commit/65a2de7e6c986193a630e691686c527b08f292d5.diff LOG: [FileCheck] - Fix the false positive when -implicit-check-not is used with an unknown -check-prefix. Imagine we have the following invocation: `FileCheck -check-prefix=UNKNOWN-PREFIX -implicit-check-not=something` When the check prefix does not exist it does not fail. This patch fixes the issue. Differential revision: https://reviews.llvm.org/D78024 Added: Modified: clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c llvm/include/llvm/Support/FileCheck.h llvm/lib/Support/FileCheck.cpp llvm/test/FileCheck/implicit-check-not.txt llvm/test/tools/llvm-objcopy/MachO/strip-debug.test Removed: diff --git a/clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c b/clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c index 2e060cfcddef..e8f09975a26e 100644 --- a/clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c +++ b/clang/test/CodeGen/catch-implicit-conversions-basics-negatives.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsanitize=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-recover=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_implicit_conversion" --check-prefixes=CHECK +// RUN: %clang_cc1 -fsanitize=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-recover=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_implicit_conversion" // If we have an enum, it will be promoted to an unsigned integer. // But both types are unsigned, and have same bitwidth. diff --git a/llvm/include/llvm/Support/FileCheck.h b/llvm/include/llvm/Support/FileCheck.h index 429e36cfcbb5..d218ef042257 100644 --- a/llvm/include/llvm/Support/FileCheck.h +++ b/llvm/include/llvm/Support/FileCheck.h @@ -31,6 +31,7 @@ struct FileCheckRequest { bool AllowEmptyInput = false; bool MatchFullLines = false; bool IgnoreCase = false; + bool IsDefaultCheckPrefix = false; bool EnableVarScope = false; bool AllowDeprecatedDagOverlap = false; bool Verbose = false; diff --git a/llvm/lib/Support/FileCheck.cpp b/llvm/lib/Support/FileCheck.cpp index 0913b97fcdd0..71b1e8356137 100644 --- a/llvm/lib/Support/FileCheck.cpp +++ b/llvm/lib/Support/FileCheck.cpp @@ -1305,6 +1305,7 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer, // found. unsigned LineNumber = 1; + bool FoundUsedPrefix = false; while (1) { Check::FileCheckType CheckTy; @@ -1315,6 +1316,8 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer, FindFirstMatchingPrefix(PrefixRE, Buffer, LineNumber, CheckTy); if (UsedPrefix.empty()) break; +FoundUsedPrefix = true; + assert(UsedPrefix.data() == Buffer.data() && "Failed to move Buffer's start forward, or pointed prefix outside " "of the buffer!"); @@ -1398,16 +1401,10 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer, DagNotMatches = ImplicitNegativeChecks; } - // Add an EOF pattern for any trailing --implicit-check-not/CHECK-DAG/-NOTs, - // and use the first prefix as a filler for the error message. - if (!DagNotMatches.empty()) { -CheckStrings->emplace_back( -Pattern(Check::CheckEOF, PatternContext.get(), LineNumber + 1), -*Req.CheckPrefixes.begin(), SMLoc::getFromPointer(Buffer.data())); -std::swap(DagNotMatches, CheckStrings->back().DagNotStrings); - } - - if (CheckStrings->empty()) { + // When there are no used prefixes we report an error except in the case that + // no prefix is specified explicitly but -implicit-check-not is specified. + if (!FoundUsedPrefix && + (ImplicitNegativeChecks.empty() || !Req.IsDefaultCheckPrefix)) { errs() << "error: no check strings found with prefix" << (Req.CheckPrefixes.size() > 1 ? "es " : " "); auto I = Req.CheckPrefixes.begin(); @@ -1423,6 +1420,15 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer, return true; } + // Add an EOF pattern for any trailing --implicit-check-not/CHECK-DAG/-NOTs, + // and use the first prefix as a filler for the error message. + if (!DagNotMatches.empty()) { +CheckStrings->emplace_back( +Pattern(Check::CheckEOF, PatternContext.ge
[clang-tools-extra] 6487ffa - Reland "[yaml2obj][ELF] - Simplify the code that performs sections validation."
Author: Georgii Rymar Date: 2020-10-20T16:25:33+03:00 New Revision: 6487ffafd1dd5ab81c440dde46163218a85d90b5 URL: https://github.com/llvm/llvm-project/commit/6487ffafd1dd5ab81c440dde46163218a85d90b5 DIFF: https://github.com/llvm/llvm-project/commit/6487ffafd1dd5ab81c440dde46163218a85d90b5.diff LOG: Reland "[yaml2obj][ELF] - Simplify the code that performs sections validation." This reverts commit 1b589f4d4db27e3fcd81fdc5abeb9407753ab790 and relands the D89463 with the fix: update `MappingTraits::validate()` in ClangTidyOptions.cpp to match the new signature (change the return type to "std::string" from "StringRef"). Original commit message: This: Changes the return type of MappingTraits>::validate to std::string instead of StringRef. It allows to create more complex error messages. It introduces std::vector> getEntries(): a new virtual method of Section, which is the base class for all sections. It returns names of special section specific keys (e.g. "Entries") and flags that says if them exist in a YAML. The code in validate() uses this list of entries descriptions to generalize validation. This approach was discussed in the D89039 thread. Differential revision: https://reviews.llvm.org/D89463 Added: Modified: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp llvm/include/llvm/ObjectYAML/DWARFYAML.h llvm/include/llvm/ObjectYAML/ELFYAML.h llvm/include/llvm/ObjectYAML/MachOYAML.h llvm/include/llvm/ObjectYAML/MinidumpYAML.h llvm/include/llvm/Support/YAMLTraits.h llvm/lib/ObjectYAML/DWARFYAML.cpp llvm/lib/ObjectYAML/ELFYAML.cpp llvm/lib/ObjectYAML/MachOYAML.cpp llvm/lib/ObjectYAML/MinidumpYAML.cpp llvm/test/tools/yaml2obj/ELF/gnu-hash-section.yaml llvm/unittests/Support/YAMLIOTest.cpp Removed: diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp index 6b28cb2bdd13..8ff22041d725 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp @@ -47,14 +47,14 @@ template <> struct MappingTraits { IO.mapRequired("name", File.Name); IO.mapOptional("lines", File.LineRanges); } - static StringRef validate(IO &io, FileFilter &File) { + static std::string validate(IO &io, FileFilter &File) { if (File.Name.empty()) return "No file name specified"; for (const FileFilter::LineRange &Range : File.LineRanges) { if (Range.first <= 0 || Range.second <= 0) return "Invalid line range"; } -return StringRef(); +return ""; } }; diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp index 7f53faaeaea3..3826e97d62b9 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp @@ -740,9 +740,7 @@ struct MappingTraits { io.mapOptional("exports", file.exportInfo); io.mapOptional("dataInCode", file.dataInCode); } - static StringRef validate(IO &io, NormalizedFile &file) { -return StringRef(); - } + static std::string validate(IO &io, NormalizedFile &file) { return {}; } }; } // namespace llvm diff --git a/llvm/include/llvm/ObjectYAML/DWARFYAML.h b/llvm/include/llvm/ObjectYAML/DWARFYAML.h index edb5f00c5e80..856cea9a1535 100644 --- a/llvm/include/llvm/ObjectYAML/DWARFYAML.h +++ b/llvm/include/llvm/ObjectYAML/DWARFYAML.h @@ -359,8 +359,8 @@ struct MappingTraits> { template struct MappingTraits> { static void mapping(IO &IO, DWARFYAML::ListEntries &ListEntries); - static StringRef validate(IO &IO, -DWARFYAML::ListEntries &ListEntries); + static std::string validate(IO &IO, + DWARFYAML::ListEntries &ListEntries); }; template <> struct MappingTraits { diff --git a/llvm/include/llvm/ObjectYAML/ELFYAML.h b/llvm/include/llvm/ObjectYAML/ELFYAML.h index af6d934d611e..28cbf325ecb6 100644 --- a/llvm/include/llvm/ObjectYAML/ELFYAML.h +++ b/llvm/include/llvm/ObjectYAML/ELFYAML.h @@ -193,6 +193,13 @@ struct Section : public Chunk { static bool classof(const Chunk *S) { return S->Kind != ChunkKind::Fill; } + // Some derived sections might have their own special entries. This method + // returns a vector of pairs. It is used for section + // validation. + virtual std::vector> getEntries() const { +return {}; + }; + // The following members are used to override section fields which is // useful for creating invalid objects. @@ -235,6 +242,10 @@ struct StackSizesSection : Section { StackSizesSection() : Section(ChunkKind::StackSizes) {} + std::vector> getEntries() const override { +return {{"Entries", Entries.hasValue()}}; + }; + static bool classof(const Chunk