Warnings.cpp (199482) | Warnings.cpp (201361) |
---|---|
1//===--- Warnings.cpp - C-Language Front-end ------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// Command line warning options handler. 11// 12//===----------------------------------------------------------------------===// 13// 14// This file is responsible for handling all warning options. This includes 15// a number of -Wfoo options and their variants, which are driven by TableGen- | 1//===--- Warnings.cpp - C-Language Front-end ------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// Command line warning options handler. 11// 12//===----------------------------------------------------------------------===// 13// 14// This file is responsible for handling all warning options. This includes 15// a number of -Wfoo options and their variants, which are driven by TableGen- |
16// generated data, and the special cases -pedantic, -pedantic-errors, -w and 17// -Werror. | 16// generated data, and the special cases -pedantic, -pedantic-errors, -w, 17// -Werror and -Wfatal-errors. |
18// 19// Each warning option controls any number of actual warnings. 20// Given a warning option 'foo', the following are valid: | 18// 19// Each warning option controls any number of actual warnings. 20// Given a warning option 'foo', the following are valid: |
21// -Wfoo, -Wno-foo, -Werror=foo | 21// -Wfoo, -Wno-foo, -Werror=foo, -Wfatal-errors=foo |
22// 23#include "clang/Frontend/Utils.h" 24#include "clang/Basic/Diagnostic.h" 25#include "clang/Sema/SemaDiagnostic.h" 26#include "clang/Lex/LexDiagnostic.h" 27#include "clang/Frontend/DiagnosticOptions.h" 28#include "clang/Frontend/FrontendDiagnostic.h" | 22// 23#include "clang/Frontend/Utils.h" 24#include "clang/Basic/Diagnostic.h" 25#include "clang/Sema/SemaDiagnostic.h" 26#include "clang/Lex/LexDiagnostic.h" 27#include "clang/Frontend/DiagnosticOptions.h" 28#include "clang/Frontend/FrontendDiagnostic.h" |
29#include <cstdio> | |
30#include <cstring> 31#include <utility> 32#include <algorithm> 33using namespace clang; 34 35bool clang::ProcessWarningOptions(Diagnostic &Diags, 36 const DiagnosticOptions &Opts) { 37 Diags.setSuppressSystemWarnings(true); // Default to -Wno-system-headers --- 4 unchanged lines hidden (view full) --- 42 // around with them explicitly. 43 if (Opts.PedanticErrors) 44 Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Error); 45 else if (Opts.Pedantic) 46 Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Warn); 47 else 48 Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Ignore); 49 | 29#include <cstring> 30#include <utility> 31#include <algorithm> 32using namespace clang; 33 34bool clang::ProcessWarningOptions(Diagnostic &Diags, 35 const DiagnosticOptions &Opts) { 36 Diags.setSuppressSystemWarnings(true); // Default to -Wno-system-headers --- 4 unchanged lines hidden (view full) --- 41 // around with them explicitly. 42 if (Opts.PedanticErrors) 43 Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Error); 44 else if (Opts.Pedantic) 45 Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Warn); 46 else 47 Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Ignore); 48 |
50 // FIXME: -Wfatal-errors / -Wfatal-errors=foo 51 | |
52 for (unsigned i = 0, e = Opts.Warnings.size(); i != e; ++i) { 53 const std::string &Opt = Opts.Warnings[i]; 54 const char *OptStart = &Opt[0]; 55 const char *OptEnd = OptStart+Opt.size(); 56 assert(*OptEnd == 0 && "Expect null termination for lower-bound search"); 57 58 // Check to see if this warning starts with "no-", if so, this is a negative 59 // form of the option. --- 16 unchanged lines hidden (view full) --- 76 77 // -Werror/-Wno-error is a special case, not controlled by the option table. 78 // It also has the "specifier" form of -Werror=foo and -Werror-foo. 79 if (OptEnd-OptStart >= 5 && memcmp(OptStart, "error", 5) == 0) { 80 const char *Specifier = 0; 81 if (OptEnd-OptStart != 5) { // Specifier must be present. 82 if ((OptStart[5] != '=' && OptStart[5] != '-') || 83 OptEnd-OptStart == 6) { | 49 for (unsigned i = 0, e = Opts.Warnings.size(); i != e; ++i) { 50 const std::string &Opt = Opts.Warnings[i]; 51 const char *OptStart = &Opt[0]; 52 const char *OptEnd = OptStart+Opt.size(); 53 assert(*OptEnd == 0 && "Expect null termination for lower-bound search"); 54 55 // Check to see if this warning starts with "no-", if so, this is a negative 56 // form of the option. --- 16 unchanged lines hidden (view full) --- 73 74 // -Werror/-Wno-error is a special case, not controlled by the option table. 75 // It also has the "specifier" form of -Werror=foo and -Werror-foo. 76 if (OptEnd-OptStart >= 5 && memcmp(OptStart, "error", 5) == 0) { 77 const char *Specifier = 0; 78 if (OptEnd-OptStart != 5) { // Specifier must be present. 79 if ((OptStart[5] != '=' && OptStart[5] != '-') || 80 OptEnd-OptStart == 6) { |
84 fprintf(stderr, "warning: unknown -Werror warning specifier: -W%s\n", 85 Opt.c_str()); | 81 Diags.Report(diag::warn_unknown_warning_specifier) 82 << "-Werror" << ("-W" + Opt); |
86 continue; 87 } 88 Specifier = OptStart+6; 89 } 90 91 if (Specifier == 0) { 92 Diags.setWarningsAsErrors(isPositive); 93 continue; 94 } 95 96 // -Werror=foo maps foo to Error, -Wno-error=foo maps it to Warning. 97 Mapping = isPositive ? diag::MAP_ERROR : diag::MAP_WARNING_NO_WERROR; 98 OptStart = Specifier; 99 } 100 | 83 continue; 84 } 85 Specifier = OptStart+6; 86 } 87 88 if (Specifier == 0) { 89 Diags.setWarningsAsErrors(isPositive); 90 continue; 91 } 92 93 // -Werror=foo maps foo to Error, -Wno-error=foo maps it to Warning. 94 Mapping = isPositive ? diag::MAP_ERROR : diag::MAP_WARNING_NO_WERROR; 95 OptStart = Specifier; 96 } 97 |
98 // -Wfatal-errors is yet another special case. 99 if (OptEnd-OptStart >= 12 && memcmp(OptStart, "fatal-errors", 12) == 0) { 100 const char* Specifier = 0; 101 if (OptEnd-OptStart != 12) { 102 if ((OptStart[12] != '=' && OptStart[12] != '-') || 103 OptEnd-OptStart == 13) { 104 Diags.Report(diag::warn_unknown_warning_specifier) 105 << "-Wfatal-errors" << ("-W" + Opt); 106 continue; 107 } 108 Specifier = OptStart + 13; 109 } 110 111 if (Specifier == 0) { 112 Diags.setErrorsAsFatal(isPositive); 113 continue; 114 } 115 116 // -Wfatal-errors=foo maps foo to Fatal, -Wno-fatal-errors=foo 117 // maps it to Error. 118 Mapping = isPositive ? diag::MAP_FATAL : diag::MAP_ERROR_NO_WFATAL; 119 OptStart = Specifier; 120 } 121 |
|
101 if (Diags.setDiagnosticGroupMapping(OptStart, Mapping)) 102 Diags.Report(diag::warn_unknown_warning_option) << ("-W" + Opt); 103 } 104 105 return false; 106} | 122 if (Diags.setDiagnosticGroupMapping(OptStart, Mapping)) 123 Diags.Report(diag::warn_unknown_warning_option) << ("-W" + Opt); 124 } 125 126 return false; 127} |