mirror of
https://github.com/intel/llvm.git
synced 2026-01-16 05:32:28 +08:00
[clang][HeuristicResolver] Test suite: fail if test code does't compile (#155561)
Fixes https://github.com/llvm/llvm-project/issues/155545
This commit is contained in:
committed by
GitHub
parent
b2a7369631
commit
3219fb0989
@@ -629,6 +629,17 @@ public:
|
||||
return StoredDiagnostics.end();
|
||||
}
|
||||
|
||||
using diags_range = llvm::iterator_range<stored_diag_iterator>;
|
||||
using const_diags_range = llvm::iterator_range<stored_diag_const_iterator>;
|
||||
|
||||
diags_range storedDiagnostics() {
|
||||
return {stored_diag_begin(), stored_diag_end()};
|
||||
}
|
||||
|
||||
const_diags_range storedDiagnostics() const {
|
||||
return {stored_diag_begin(), stored_diag_end()};
|
||||
}
|
||||
|
||||
unsigned stored_diag_size() const { return StoredDiagnostics.size(); }
|
||||
|
||||
stored_diag_iterator stored_diag_afterDriver_begin() {
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "clang/AST/ASTConsumer.h"
|
||||
#include "clang/Basic/FileManager.h"
|
||||
#include "clang/Basic/LLVM.h"
|
||||
#include "clang/Frontend/ASTUnit.h"
|
||||
#include "clang/Frontend/FrontendAction.h"
|
||||
#include "clang/Frontend/PCHContainerOperations.h"
|
||||
#include "clang/Tooling/ArgumentsAdjusters.h"
|
||||
@@ -239,7 +240,8 @@ std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs(
|
||||
const FileContentMappings &VirtualMappedFiles = FileContentMappings(),
|
||||
DiagnosticConsumer *DiagConsumer = nullptr,
|
||||
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS =
|
||||
llvm::vfs::getRealFileSystem());
|
||||
llvm::vfs::getRealFileSystem(),
|
||||
CaptureDiagsKind CaptureKind = CaptureDiagsKind::None);
|
||||
|
||||
/// Utility to run a FrontendAction in a single clang invocation.
|
||||
class ToolInvocation {
|
||||
|
||||
@@ -644,9 +644,13 @@ namespace {
|
||||
|
||||
class ASTBuilderAction : public ToolAction {
|
||||
std::vector<std::unique_ptr<ASTUnit>> &ASTs;
|
||||
CaptureDiagsKind CaptureKind;
|
||||
|
||||
public:
|
||||
ASTBuilderAction(std::vector<std::unique_ptr<ASTUnit>> &ASTs) : ASTs(ASTs) {}
|
||||
ASTBuilderAction(
|
||||
std::vector<std::unique_ptr<ASTUnit>> &ASTs,
|
||||
CaptureDiagsKind CaptureDiagnosticsKind = CaptureDiagsKind::None)
|
||||
: ASTs(ASTs), CaptureKind(CaptureDiagnosticsKind) {}
|
||||
|
||||
bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
|
||||
FileManager *Files,
|
||||
@@ -658,7 +662,7 @@ public:
|
||||
Invocation->getDiagnosticOpts(),
|
||||
DiagConsumer,
|
||||
/*ShouldOwnClient=*/false),
|
||||
Files);
|
||||
Files, false, CaptureKind);
|
||||
if (!AST)
|
||||
return false;
|
||||
|
||||
@@ -693,9 +697,12 @@ std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs(
|
||||
StringRef ToolName, std::shared_ptr<PCHContainerOperations> PCHContainerOps,
|
||||
ArgumentsAdjuster Adjuster, const FileContentMappings &VirtualMappedFiles,
|
||||
DiagnosticConsumer *DiagConsumer,
|
||||
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS) {
|
||||
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
|
||||
CaptureDiagsKind CaptureKind) {
|
||||
std::vector<std::unique_ptr<ASTUnit>> ASTs;
|
||||
ASTBuilderAction Action(ASTs);
|
||||
|
||||
ASTBuilderAction Action(ASTs, CaptureKind);
|
||||
|
||||
auto OverlayFileSystem =
|
||||
llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(
|
||||
std::move(BaseFS));
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "clang/Sema/HeuristicResolver.h"
|
||||
#include "clang/ASTMatchers/ASTMatchFinder.h"
|
||||
#include "clang/ASTMatchers/ASTMatchers.h"
|
||||
#include "clang/Basic/Diagnostic.h"
|
||||
#include "clang/Tooling/Tooling.h"
|
||||
#include "gmock/gmock-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
@@ -41,7 +42,19 @@ template <typename InputNode, typename ParamT, typename InputMatcher,
|
||||
typename... OutputMatchers>
|
||||
void expectResolution(llvm::StringRef Code, ResolveFnT<ParamT> ResolveFn,
|
||||
const InputMatcher &IM, const OutputMatchers &...OMS) {
|
||||
auto TU = tooling::buildASTFromCodeWithArgs(Code, {"-std=c++23"});
|
||||
auto TU = tooling::buildASTFromCodeWithArgs(
|
||||
Code, {"-std=c++23"}, "input.cc", "clang-tool",
|
||||
std::make_shared<PCHContainerOperations>(),
|
||||
tooling::getClangStripDependencyFileAdjuster(),
|
||||
tooling::FileContentMappings(), nullptr, llvm::vfs::getRealFileSystem(),
|
||||
CaptureDiagsKind::All);
|
||||
|
||||
for (const auto &D : TU->storedDiagnostics()) {
|
||||
EXPECT_TRUE(D.getLevel() < DiagnosticsEngine::Error)
|
||||
<< "Unexpected error diagnostic while building AST for test code: "
|
||||
<< D.getMessage();
|
||||
}
|
||||
|
||||
auto &Ctx = TU->getASTContext();
|
||||
auto InputMatches = match(IM, Ctx);
|
||||
ASSERT_EQ(1u, InputMatches.size());
|
||||
|
||||
Reference in New Issue
Block a user