[cfe-commits] r93288 - in /cfe/trunk: include/clang/Basic/DiagnosticDriverKinds.td include/clang/Frontend/DiagnosticOptions.h lib/Frontend/CompilerInvocation.cpp lib/Frontend/TextDiagnosticPrinter.cpp
Chris Lattner
sabre at nondot.org
Tue Jan 12 19:06:51 PST 2010
Author: lattner
Date: Tue Jan 12 21:06:50 2010
New Revision: 93288
URL: http://llvm.org/viewvc/llvm-project?rev=93288&view=rev
Log:
diagnose invalid values of -ftabstop, patch by Christian Adaker!
Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Frontend/DiagnosticOptions.h
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=93288&r1=93287&r2=93288&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Tue Jan 12 21:06:50 2010
@@ -81,5 +81,7 @@
"the clang compiler does not support '%0'">;
def warn_drv_assuming_mfloat_abi_is : Warning<
"unknown platform, assuming -mfloat-abi=%0">;
+def warn_ignoring_ftabstop_value : Warning<
+ "ignoring invalid -ftabstop value '%0', using default value %1">;
}
Modified: cfe/trunk/include/clang/Frontend/DiagnosticOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/DiagnosticOptions.h?rev=93288&r1=93287&r2=93288&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/DiagnosticOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/DiagnosticOptions.h Tue Jan 12 21:06:50 2010
@@ -37,6 +37,7 @@
/// The distance between tab stops.
unsigned TabStop;
+ enum { DefaultTabStop = 8, MaxTabStop = 100 };
/// Column limit for formatting message diagnostics, or 0 if unused.
unsigned MessageLength;
@@ -52,7 +53,7 @@
public:
DiagnosticOptions() {
IgnoreWarnings = 0;
- TabStop = 8;
+ TabStop = DefaultTabStop;
MessageLength = 0;
NoRewriteMacros = 0;
Pedantic = 0;
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=93288&r1=93287&r2=93288&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Jan 12 21:06:50 2010
@@ -222,7 +222,7 @@
Res.push_back("-verify");
if (Opts.ShowOptionNames)
Res.push_back("-fdiagnostics-show-option");
- if (Opts.TabStop != 8) {
+ if (Opts.TabStop != DiagnosticOptions::DefaultTabStop) {
Res.push_back("-ftabstop");
Res.push_back(llvm::utostr(Opts.TabStop));
}
@@ -808,7 +808,13 @@
Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option);
Opts.ShowSourceRanges = Args.hasArg(OPT_fdiagnostics_print_source_range_info);
Opts.VerifyDiagnostics = Args.hasArg(OPT_verify);
- Opts.TabStop = getLastArgIntValue(Args, OPT_ftabstop, 8, Diags);
+ Opts.TabStop = getLastArgIntValue(Args, OPT_ftabstop,
+ DiagnosticOptions::DefaultTabStop, Diags);
+ if (Opts.TabStop == 0 || Opts.TabStop > DiagnosticOptions::MaxTabStop) {
+ Diags.Report(diag::warn_ignoring_ftabstop_value)
+ << Opts.TabStop << DiagnosticOptions::DefaultTabStop;
+ Opts.TabStop = DiagnosticOptions::DefaultTabStop;
+ }
Opts.MessageLength = getLastArgIntValue(Args, OPT_fmessage_length, 0, Diags);
Opts.DumpBuildInformation = getLastArgValue(Args, OPT_dump_build_information);
Opts.Warnings = getAllArgValues(Args, OPT_W);
Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=93288&r1=93287&r2=93288&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Tue Jan 12 21:06:50 2010
@@ -371,15 +371,17 @@
CaretLine.push_back('^');
// Scan the source line, looking for tabs. If we find any, manually expand
- // them to 8 characters and update the CaretLine to match.
+ // them to spaces and update the CaretLine to match.
for (unsigned i = 0; i != SourceLine.size(); ++i) {
if (SourceLine[i] != '\t') continue;
// Replace this tab with at least one space.
SourceLine[i] = ' ';
- unsigned TabStop = DiagOpts->TabStop > 0 ? DiagOpts->TabStop : 8;
// Compute the number of spaces we need to insert.
+ unsigned TabStop = DiagOpts->TabStop;
+ assert(0 < TabStop && TabStop <= DiagnosticOptions::MaxTabStop &&
+ "Invalid -ftabstop value");
unsigned NumSpaces = ((i+TabStop)/TabStop * TabStop) - (i+1);
assert(NumSpaces < TabStop && "Invalid computation of space amt");
More information about the cfe-commits
mailing list