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.)
This commit is contained in:
Matt Pharr
2011-11-30 05:51:53 -08:00
parent 6b9b7437ed
commit c995902796
5 changed files with 12 additions and 3 deletions

View File

@@ -341,6 +341,7 @@ Globals::Globals() {
runCPP = true;
debugPrint = false;
disableWarnings = false;
warningsAsErrors = false;
disableLineWrap = false;
emitPerfWarnings = true;
emitInstrumentation = false;

3
ispc.h
View File

@@ -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;

View File

@@ -104,6 +104,7 @@ static void usage(int ret) {
#endif // !ISPC_IS_WINDOWS
printf(" [--target=<isa>]\t\t\tSelect target ISA. <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(" <file to compile or \"-\" for stdin>\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"))

View File

@@ -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]

View File

@@ -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);
}