Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear diagnostics between processing of source files #357

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/libdredd/src/new_mutate_frontend_action_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <string>

#include "clang/AST/ASTConsumer.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/FrontendOptions.h"
Expand All @@ -45,15 +46,23 @@ class MutateFrontendAction : public clang::ASTFrontendAction {
llvm::StringRef file) override;

bool BeginInvocation(clang::CompilerInstance& compiler_instance) override {
(void)compiler_instance; // Unused.
// Clear any diagnostics generated when operating on previous source files.
compiler_instance.getDiagnostics().getClient()->clear();

// Sanity check to confirm that there is a current input file.
const bool input_exists = !getCurrentInput().isEmpty();
(void)input_exists; // Keep release-mode compilers happy.
assert(input_exists && "No current file.");

// Check whether this file has already been processed.
if (processed_files_->contains(getCurrentFile().str())) {
llvm::errs() << "Warning: already processed " << getCurrentFile()
<< "; skipping repeat occurrence.\n";
return false;
}

// Record that this file has been processed so that duplicate processing
// will be detected in the future.
processed_files_->insert(getCurrentFile().str());
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions test/bespoke/one_bad_file_one_good_file/bad.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void foo() error {

}
3 changes: 3 additions & 0 deletions test/bespoke/one_bad_file_one_good_file/good.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void bar() {

}
23 changes: 23 additions & 0 deletions test/bespoke/one_bad_file_one_good_file/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os
import re
import shutil
import subprocess
import sys
from pathlib import Path

DREDD_REPO_ROOT = os.environ['DREDD_REPO_ROOT']
DREDD_INSTALLED_EXECUTABLE = Path(DREDD_REPO_ROOT, 'third_party', 'clang+llvm', 'bin', 'dredd')


def main():
# Run Dredd
cmd = [DREDD_INSTALLED_EXECUTABLE, 'bad.c', 'good.c', '--']
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
assert result.returncode != 0
error_output = result.stderr.decode('utf-8')
pattern = r"Error while processing .*good\.c"
assert re.search(pattern, error_output) is None


if __name__ == '__main__':
sys.exit(main())