 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
61.5% |
32 / 52 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
73.1% |
38 / 52 |
| |
|
Line Coverage: |
66.7% |
32 / 48 |
| |
 |
|
 |
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,
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:
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"
29 : #include <cstring>
30 : #include <utility>
31 : #include <algorithm>
32 : using namespace clang;
33 :
34 : bool clang::ProcessWarningOptions(Diagnostic &Diags,
35 2583: const DiagnosticOptions &Opts) {
36 2583: Diags.setSuppressSystemWarnings(true); // Default to -Wno-system-headers
37 2583: Diags.setIgnoreAllWarnings(Opts.IgnoreWarnings);
38 :
39 : // If -pedantic or -pedantic-errors was specified, then we want to map all
40 : // extension diagnostics onto WARNING or ERROR unless the user has futz'd
41 : // around with them explicitly.
12: branch 0 taken
2571: branch 1 taken
42 2583: if (Opts.PedanticErrors)
43 12: Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Error);
105: branch 0 taken
2466: branch 1 taken
44 2571: else if (Opts.Pedantic)
45 105: Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Warn);
46 : else
47 2466: Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Ignore);
48 :
132: branch 1 taken
2583: branch 2 taken
49 2715: for (unsigned i = 0, e = Opts.Warnings.size(); i != e; ++i) {
50 132: const std::string &Opt = Opts.Warnings[i];
51 132: const char *OptStart = &Opt[0];
52 132: const char *OptEnd = OptStart+Opt.size();
0: branch 0 not taken
132: branch 1 taken
53 132: 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.
57 132: bool isPositive = true;
124: branch 0 taken
8: branch 1 taken
49: branch 3 taken
75: branch 4 taken
58 132: if (OptEnd-OptStart > 3 && memcmp(OptStart, "no-", 3) == 0) {
59 49: isPositive = false;
60 49: OptStart += 3;
61 : }
62 :
63 : // Figure out how this option affects the warning. If -Wfoo, map the
64 : // diagnostic to a warning, if -Wno-foo, map it to ignore.
83: branch 0 taken
49: branch 1 taken
65 132: diag::Mapping Mapping = isPositive ? diag::MAP_WARNING : diag::MAP_IGNORE;
66 :
67 : // -Wsystem-headers is a special case, not driven by the option table. It
68 : // cannot be controlled with -Werror.
0: branch 0 not taken
132: branch 1 taken
0: branch 3 not taken
0: branch 4 not taken
69 132: if (OptEnd-OptStart == 14 && memcmp(OptStart, "system-headers", 14) == 0) {
70 0: Diags.setSuppressSystemWarnings(!isPositive);
71 0: continue;
72 : }
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.
124: branch 0 taken
8: branch 1 taken
28: branch 3 taken
96: branch 4 taken
76 132: if (OptEnd-OptStart >= 5 && memcmp(OptStart, "error", 5) == 0) {
77 28: const char *Specifier = 0;
6: branch 0 taken
22: branch 1 taken
78 28: if (OptEnd-OptStart != 5) { // Specifier must be present.
1: branch 0 taken
5: branch 1 taken
1: branch 2 taken
0: branch 3 not taken
0: branch 4 not taken
6: branch 5 taken
79 6: if ((OptStart[5] != '=' && OptStart[5] != '-') ||
80 : OptEnd-OptStart == 6) {
81 : Diags.Report(diag::warn_unknown_warning_specifier)
82 0: << "-Werror" << ("-W" + Opt);
83 0: continue;
84 : }
85 6: Specifier = OptStart+6;
86 : }
87 :
22: branch 0 taken
6: branch 1 taken
88 28: if (Specifier == 0) {
89 22: Diags.setWarningsAsErrors(isPositive);
90 22: continue;
91 : }
92 :
93 : // -Werror=foo maps foo to Error, -Wno-error=foo maps it to Warning.
5: branch 0 taken
1: branch 1 taken
94 6: Mapping = isPositive ? diag::MAP_ERROR : diag::MAP_WARNING_NO_WERROR;
95 6: OptStart = Specifier;
96 : }
97 :
98 : // -Wfatal-errors is yet another special case.
80: branch 0 taken
30: branch 1 taken
0: branch 3 not taken
80: branch 4 taken
99 110: if (OptEnd-OptStart >= 12 && memcmp(OptStart, "fatal-errors", 12) == 0) {
100 0: const char* Specifier = 0;
0: branch 0 not taken
0: branch 1 not taken
101 0: if (OptEnd-OptStart != 12) {
0: branch 0 not taken
0: branch 1 not taken
0: branch 2 not taken
0: branch 3 not taken
0: branch 4 not taken
0: branch 5 not taken
102 0: if ((OptStart[12] != '=' && OptStart[12] != '-') ||
103 : OptEnd-OptStart == 13) {
104 : Diags.Report(diag::warn_unknown_warning_specifier)
105 0: << "-Wfatal-errors" << ("-W" + Opt);
106 0: continue;
107 : }
108 0: Specifier = OptStart + 13;
109 : }
110 :
0: branch 0 not taken
0: branch 1 not taken
111 0: if (Specifier == 0) {
112 0: Diags.setErrorsAsFatal(isPositive);
113 0: continue;
114 : }
115 :
116 : // -Wfatal-errors=foo maps foo to Fatal, -Wno-fatal-errors=foo
117 : // maps it to Error.
0: branch 0 not taken
0: branch 1 not taken
118 0: Mapping = isPositive ? diag::MAP_FATAL : diag::MAP_ERROR_NO_WFATAL;
119 0: OptStart = Specifier;
120 : }
121 :
0: branch 1 not taken
110: branch 2 taken
122 110: if (Diags.setDiagnosticGroupMapping(OptStart, Mapping))
123 0: Diags.Report(diag::warn_unknown_warning_option) << ("-W" + Opt);
124 : }
125 :
126 2583: return false;
127 : }
Generated: 2010-02-10 01:31 by zcov