From c9959027967aee4720c79f17522b74a32664a644 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Wed, 30 Nov 2011 05:51:53 -0800 Subject: [PATCH] Add --werror flag to treat warnings as errors. The specific need for it was so that tests in tests_errors can test to see if a desired diagnostic warning is issued (like ptrcast-lose-info does.) --- ispc.cpp | 1 + ispc.h | 3 +++ main.cpp | 3 +++ run_tests.py | 4 ++-- util.cpp | 4 +++- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ispc.cpp b/ispc.cpp index 188b753e..c8bdb6b3 100644 --- a/ispc.cpp +++ b/ispc.cpp @@ -341,6 +341,7 @@ Globals::Globals() { runCPP = true; debugPrint = false; disableWarnings = false; + warningsAsErrors = false; disableLineWrap = false; emitPerfWarnings = true; emitInstrumentation = false; diff --git a/ispc.h b/ispc.h index e564ed6a..ed8a8b22 100644 --- a/ispc.h +++ b/ispc.h @@ -348,6 +348,9 @@ struct Globals { /** Indicates whether all warning messages should be surpressed. */ bool disableWarnings; + /** Indicates whether warnings should be issued as errors. */ + bool warningsAsErrors; + /** Indicates whether line wrapping of error messages to the terminal width should be disabled. */ bool disableLineWrap; diff --git a/main.cpp b/main.cpp index 40ee8550..e40a42ee 100644 --- a/main.cpp +++ b/main.cpp @@ -104,6 +104,7 @@ static void usage(int ret) { #endif // !ISPC_IS_WINDOWS printf(" [--target=]\t\t\tSelect target ISA. ={%s}\n", Target::SupportedTargetISAs()); printf(" [--version]\t\t\t\tPrint ispc version\n"); + printf(" [--werror]\t\t\tTreat warnings as errors\n"); printf(" [--woff]\t\t\t\tDisable warnings\n"); printf(" [--wno-perf]\t\t\tDon't issue warnings related to performance-related issues\n"); printf(" \n"); @@ -283,6 +284,8 @@ int main(int Argc, char *Argv[]) { g->disableWarnings = true; g->emitPerfWarnings = false; } + else if (!strcmp(argv[i], "--werror")) + g->warningsAsErrors = true; else if (!strcmp(argv[i], "--nowrap")) g->disableLineWrap = true; else if (!strcmp(argv[i], "--wno-perf") || !strcmp(argv[i], "-wno-perf")) diff --git a/run_tests.py b/run_tests.py index 058b10b8..a487a9de 100755 --- a/run_tests.py +++ b/run_tests.py @@ -107,8 +107,8 @@ def run_tasks_from_queue(queue): # is this a test to make sure an error is issued? want_error = (filename.find("tests_errors") != -1) if want_error == True: - ispc_cmd = "ispc --nowrap %s --arch=%s --target=%s" % \ - ( filename, options.arch, options.target) + ispc_cmd = "ispc --werror --nowrap %s --arch=%s --target=%s" % \ + (filename, options.arch, options.target) sp = subprocess.Popen(shlex.split(ispc_cmd), stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output = sp.communicate()[1] diff --git a/util.cpp b/util.cpp index 78e94020..ba1b8906 100644 --- a/util.cpp +++ b/util.cpp @@ -291,7 +291,9 @@ Warning(SourcePos p, const char *fmt, ...) { va_list args; va_start(args, fmt); - lPrint("Warning", p, fmt, args); + lPrint(g->warningsAsErrors ? "Error" : "Warning", p, fmt, args); + if (g->warningsAsErrors) + ++m->errorCount; va_end(args); }