Skip to content

Commit 4805901

Browse files
committed
[Driver] Don't pass -fmessage-length=0 to CC1
-fmessage-length=0 is common (unless the environment variable COLUMNS is set and exported. This simplifies a common CC1 command line.
1 parent 855e738 commit 4805901

File tree

13 files changed

+36
-22
lines changed

13 files changed

+36
-22
lines changed

clang/include/clang/Driver/CC1Options.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,6 @@ def fspell_checking_limit : Separate<["-"], "fspell-checking-limit">, MetaVarNam
453453
def fcaret_diagnostics_max_lines :
454454
Separate<["-"], "fcaret-diagnostics-max-lines">, MetaVarName<"<N>">,
455455
HelpText<"Set the maximum number of source lines to show in a caret diagnostic">;
456-
def fmessage_length : Separate<["-"], "fmessage-length">, MetaVarName<"<N>">,
457-
HelpText<"Format message diagnostics so that they fit within N columns or fewer, when possible.">;
458456
def verify_EQ : CommaJoined<["-"], "verify=">,
459457
MetaVarName<"<prefixes>">,
460458
HelpText<"Verify diagnostic output using comment directives that start with"

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,8 @@ def fmacro_backtrace_limit_EQ : Joined<["-"], "fmacro-backtrace-limit=">,
13641364
Group<f_Group>, Flags<[DriverOption, CoreOption]>;
13651365
def fmerge_all_constants : Flag<["-"], "fmerge-all-constants">, Group<f_Group>,
13661366
Flags<[CC1Option, CoreOption]>, HelpText<"Allow merging of constants">;
1367-
def fmessage_length_EQ : Joined<["-"], "fmessage-length=">, Group<f_Group>;
1367+
def fmessage_length_EQ : Joined<["-"], "fmessage-length=">, Group<f_Group>, Flags<[CC1Option]>,
1368+
HelpText<"Format message diagnostics so that they fit within N columns">;
13681369
def fms_extensions : Flag<["-"], "fms-extensions">, Group<f_Group>, Flags<[CC1Option, CoreOption]>,
13691370
HelpText<"Accept some non-standard constructs supported by the Microsoft compiler">;
13701371
def fms_compatibility : Flag<["-"], "fms-compatibility">, Group<f_Group>, Flags<[CC1Option, CoreOption]>,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5130,15 +5130,20 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
51305130
}
51315131

51325132
// Pass -fmessage-length=.
5133-
CmdArgs.push_back("-fmessage-length");
5133+
unsigned MessageLength = 0;
51345134
if (Arg *A = Args.getLastArg(options::OPT_fmessage_length_EQ)) {
5135-
CmdArgs.push_back(A->getValue());
5135+
StringRef V(A->getValue());
5136+
if (V.getAsInteger(0, MessageLength))
5137+
D.Diag(diag::err_drv_invalid_argument_to_option)
5138+
<< V << A->getOption().getName();
51365139
} else {
51375140
// If -fmessage-length=N was not specified, determine whether this is a
51385141
// terminal and, if so, implicitly define -fmessage-length appropriately.
5139-
unsigned N = llvm::sys::Process::StandardErrColumns();
5140-
CmdArgs.push_back(Args.MakeArgString(Twine(N)));
5142+
MessageLength = llvm::sys::Process::StandardErrColumns();
51415143
}
5144+
if (MessageLength != 0)
5145+
CmdArgs.push_back(
5146+
Args.MakeArgString("-fmessage-length=" + Twine(MessageLength)));
51425147

51435148
// -fvisibility= and -fvisibility-ms-compat are of a piece.
51445149
if (const Arg *A = Args.getLastArg(options::OPT_fvisibility_EQ,

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,8 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
16751675
Diags->Report(diag::warn_ignoring_ftabstop_value)
16761676
<< Opts.TabStop << DiagnosticOptions::DefaultTabStop;
16771677
}
1678-
Opts.MessageLength = getLastArgIntValue(Args, OPT_fmessage_length, 0, Diags);
1678+
Opts.MessageLength =
1679+
getLastArgIntValue(Args, OPT_fmessage_length_EQ, 0, Diags);
16791680
addDiagnosticArgs(Args, OPT_W_Group, OPT_W_value_Group, Opts.Warnings);
16801681
addDiagnosticArgs(Args, OPT_R_Group, OPT_R_value_Group, Opts.Remarks);
16811682

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang -### -c %s -fmessage-length=80 2>&1 | FileCheck %s
2+
// CHECK: "-fmessage-length=80"
3+
4+
/// Omit -fmessage-length=0 to simplify common CC1 command lines.
5+
// RUN: %clang -### -c %s -fmessage-length=0 2>&1 | FileCheck --check-prefix=ZERO %s
6+
// ZERO-NOT: "-fmessage-length=0"
7+
8+
// RUN: %clang -### -c %s -fmessage-length=nan 2>&1 | FileCheck --check-prefix=ERR %s
9+
// ERR: error: invalid argument 'nan' to -fmessage-length=

clang/test/Driver/rewrite-legacy-objc.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// TEST0: clang{{.*}}" "-cc1"
44
// TEST0: "-rewrite-objc"
55
// FIXME: CHECK-NOT is broken somehow, it doesn't work here. Check adjacency instead.
6-
// TEST0: "-fmessage-length" "0" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx-fragile" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"
6+
// TEST0: "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx-fragile" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"
77
// TEST0: rewrite-legacy-objc.m"
88
// RUN: %clang -no-canonical-prefixes -target i386-apple-macosx10.9.0 -rewrite-legacy-objc %s -o - -### 2>&1 | \
99
// RUN: FileCheck -check-prefix=TEST1 %s
1010
// RUN: %clang -no-canonical-prefixes -target i386-apple-macosx10.6.0 -rewrite-legacy-objc %s -o - -### 2>&1 | \
1111
// RUN: FileCheck -check-prefix=TEST2 %s
12-
// TEST1: "-fmessage-length" "0" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx-fragile" "-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"
13-
// TEST2: "-fmessage-length" "0" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx-fragile" "-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"
12+
// TEST1: "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx-fragile" "-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"
13+
// TEST2: "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx-fragile" "-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"

clang/test/Driver/rewrite-objc.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
// TEST0: clang{{.*}}" "-cc1"
44
// TEST0: "-rewrite-objc"
55
// FIXME: CHECK-NOT is broken somehow, it doesn't work here. Check adjacency instead.
6-
// TEST0: "-fmessage-length" "0" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"
6+
// TEST0: "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"

clang/test/Frontend/source-col-map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %clang_cc1 -fsyntax-only -fmessage-length 75 -o /dev/null -x c < %s 2>&1 | FileCheck %s -strict-whitespace
1+
// RUN: not %clang_cc1 -fsyntax-only -fmessage-length=75 -o /dev/null -x c < %s 2>&1 | FileCheck %s -strict-whitespace
22
// REQUIRES: utf8-capable-terminal
33

44
// Test case for the text diagnostics source column conversion crash.

clang/test/Misc/diag-line-wrapping.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: not %clang_cc1 -fsyntax-only -fmessage-length 60 %s 2>&1 | FileCheck %s
2-
// RUN: not %clang_cc1 -fsyntax-only -fmessage-length 0 %s 2>&1 | FileCheck %s
1+
// RUN: not %clang_cc1 -fsyntax-only -fmessage-length=60 %s 2>&1 | FileCheck %s
2+
// RUN: not %clang_cc1 -fsyntax-only -fmessage-length=0 %s 2>&1 | FileCheck %s
33

44
struct B { void f(); };
55
struct D1 : B {};

clang/test/Misc/message-length.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: not %clang_cc1 -fmessage-length 72 %s 2>&1 | FileCheck -strict-whitespace %s
2-
// RUN: not %clang_cc1 -fmessage-length 1 %s
3-
// RUN: not %clang_cc1 -fmessage-length 8 %s 2>&1 | FileCheck -check-prefix=CHECK-DOT %s
1+
// RUN: not %clang_cc1 -fmessage-length=72 %s 2>&1 | FileCheck -strict-whitespace %s
2+
// RUN: not %clang_cc1 -fmessage-length=1 %s
3+
// RUN: not %clang_cc1 -fmessage-length=8 %s 2>&1 | FileCheck -check-prefix=CHECK-DOT %s
44
// Hack so we can check things better, force the file name and line.
55
# 1 "FILE" 1
66

0 commit comments

Comments
 (0)