diff options
| author | Ilya Biryukov <ibiryukov@google.com> | 2018-12-17 16:37:52 +0000 |
|---|---|---|
| committer | Ilya Biryukov <ibiryukov@google.com> | 2018-12-17 16:37:52 +0000 |
| commit | 1d7ba831ee4321e6a9520b30bbff3a2c3d3d6698 (patch) | |
| tree | 4758f1d9d388ab0391969cb0a304d7b769cb05c1 /clang/unittests/Sema/CodeCompleteTest.cpp | |
| parent | bb3d7e565f9b14559057403e772bc8b26f636534 (diff) | |
| download | bcm5719-llvm-1d7ba831ee4321e6a9520b30bbff3a2c3d3d6698.tar.gz bcm5719-llvm-1d7ba831ee4321e6a9520b30bbff3a2c3d3d6698.zip | |
[CodeComplete] Fix test failure on different host and target configs
This should fix PR40033.
llvm-svn: 349362
Diffstat (limited to 'clang/unittests/Sema/CodeCompleteTest.cpp')
| -rw-r--r-- | clang/unittests/Sema/CodeCompleteTest.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/clang/unittests/Sema/CodeCompleteTest.cpp b/clang/unittests/Sema/CodeCompleteTest.cpp index 294807c56c5..28faa0c1eeb 100644 --- a/clang/unittests/Sema/CodeCompleteTest.cpp +++ b/clang/unittests/Sema/CodeCompleteTest.cpp @@ -31,6 +31,9 @@ const char TestCCName[] = "test.cc"; struct CompletionContext { std::vector<std::string> VisitedNamespaces; std::string PreferredType; + // String representation of std::ptrdiff_t on a given platform. This is a hack + // to properly account for different configurations of clang. + std::string PtrDiffType; }; class VisitedContextFinder : public CodeCompleteConsumer { @@ -47,6 +50,8 @@ public: ResultCtx.VisitedNamespaces = getVisitedNamespace(Context.getVisitedContexts()); ResultCtx.PreferredType = Context.getPreferredType().getAsString(); + ResultCtx.PtrDiffType = + S.getASTContext().getPointerDiffType().getAsString(); } CodeCompletionAllocator &getAllocator() override { @@ -133,11 +138,19 @@ CompletionContext runCodeCompleteOnCode(StringRef AnnotatedCode) { return runCompletion(P.Code, P.Points.front()); } -std::vector<std::string> collectPreferredTypes(StringRef AnnotatedCode) { +std::vector<std::string> +collectPreferredTypes(StringRef AnnotatedCode, + std::string *PtrDiffType = nullptr) { ParsedAnnotations P = parseAnnotations(AnnotatedCode); std::vector<std::string> Types; - for (size_t Point : P.Points) - Types.push_back(runCompletion(P.Code, Point).PreferredType); + for (size_t Point : P.Points) { + auto Results = runCompletion(P.Code, Point); + if (PtrDiffType) { + assert(PtrDiffType->empty() || *PtrDiffType == Results.PtrDiffType); + *PtrDiffType = Results.PtrDiffType; + } + Types.push_back(Results.PreferredType); + } return Types; } @@ -213,9 +226,11 @@ TEST(PreferredTypeTest, BinaryExpr) { ptr += ^10; ptr -= ^10; })cpp"; - // Expect the normalized ptrdiff_t type, which is typically long or long long. - const char *PtrDiff = sizeof(void *) == sizeof(long) ? "long" : "long long"; - EXPECT_THAT(collectPreferredTypes(Code), Each(PtrDiff)); + { + std::string PtrDiff; + auto Types = collectPreferredTypes(Code, &PtrDiff); + EXPECT_THAT(Types, Each(PtrDiff)); + } // Comparison operators. Code = R"cpp( |

