Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -781,7 +781,7 @@ Flags<[CC1Option]>, HelpText<"Print option name with mappable diagnostics">; def fdiagnostics_show_note_include_stack : Flag<["-"], "fdiagnostics-show-note-include-stack">, Group, Flags<[CC1Option]>, HelpText<"Display include stacks for diagnostic notes">; -def fdiagnostics_format_EQ : Joined<["-"], "fdiagnostics-format=">, Group; +def fdiagnostics_format_EQ : Joined<["-"], "fdiagnostics-format=">, Group, Flags<[CC1Option, CC1AsOption]>; def fdiagnostics_show_category_EQ : Joined<["-"], "fdiagnostics-show-category=">, Group; def fdiagnostics_show_template_tree : Flag<["-"], "fdiagnostics-show-template-tree">, Group, Flags<[CC1Option]>, @@ -1119,7 +1119,7 @@ def fms_compatibility_version : Joined<["-"], "fms-compatibility-version=">, Group, - Flags<[ CC1Option, CoreOption ]>, + Flags<[ CC1Option, CoreOption, CC1AsOption ]>, HelpText<"Dot-separated value representing the Microsoft compiler " "version number to report in _MSC_VER (0 = don't define it " "(default))">; @@ -1290,7 +1290,7 @@ def fno_rtti : Flag<["-"], "fno-rtti">, Group, Flags<[CC1Option]>, HelpText<"Disable generation of rtti information">; def fno_short_enums : Flag<["-"], "fno-short-enums">, Group; -def fno_show_column : Flag<["-"], "fno-show-column">, Group, Flags<[CC1Option]>, +def fno_show_column : Flag<["-"], "fno-show-column">, Group, Flags<[CC1Option, CC1AsOption]>, HelpText<"Do not include column number on diagnostics">; def fno_show_source_location : Flag<["-"], "fno-show-source-location">, Group, Flags<[CC1Option]>, HelpText<"Do not include source location information with diagnostics">; Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -2077,6 +2077,20 @@ CmdArgs.push_back("-target-feature"); CmdArgs.push_back(MipsTargetFeature); } + + if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) { + CmdArgs.push_back( + Args.MakeArgString(Twine("-fdiagnostics-format=") + A->getValue())); + } + + if (!Args.hasFlag(options::OPT_fshow_column, options::OPT_fno_show_column, + true)) + CmdArgs.push_back("-fno-show-column"); + + VersionTuple MSVT = C.getDefaultToolChain().computeMSVCVersion(&D, Args); + if (!MSVT.empty()) + CmdArgs.push_back( + Args.MakeArgString("-fms-compatibility-version=" + MSVT.getAsString())); } static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, Index: test/Misc/diag-format-asm.s =================================================================== --- test/Misc/diag-format-asm.s +++ test/Misc/diag-format-asm.s @@ -0,0 +1,52 @@ +// RUN: not %clang %s 2>&1 | FileCheck %s -check-prefix=DEFAULT +// RUN: not %clang -fdiagnostics-format=clang %s 2>&1 | FileCheck %s -check-prefix=DEFAULT +// RUN: not %clang -fdiagnostics-format=clang -target x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=DEFAULT +// +// RUN: not %clang -fdiagnostics-format=msvc -fmsc-version=1300 %s 2>&1 | FileCheck %s -check-prefix=MSVC2010 +// RUN: not %clang -fdiagnostics-format=msvc -fms-compatibility-version=13.00 %s 2>&1 | FileCheck %s -check-prefix=MSVC2010 +// RUN: not %clang -fdiagnostics-format=msvc -fmsc-version=1300 -target x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=MSVC2010 +// RUN: not %clang -fdiagnostics-format=msvc -fms-compatibility-version=13.00 -target x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=MSVC2010 +// RUN: not %clang -fdiagnostics-format=msvc -fmsc-version=1300 -target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s -check-prefix=MSVC2010 +// RUN: not %clang -fdiagnostics-format=msvc -fmsc-version=1800 -target x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=MSVC2013 +// RUN: not %clang -fdiagnostics-format=msvc -target x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=MSVC +// RUN: not %clang -fdiagnostics-format=msvc -fmsc-version=1900 -target x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=MSVC2015 +// RUN: not %clang -fdiagnostics-format=msvc -fms-compatibility-version=13.00 -target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s -check-prefix=MSVC2010 +// RUN: not %clang -fdiagnostics-format=msvc -fmsc-version=1800 -target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s -check-prefix=MSVC2013 +// RUN: not %clang -fdiagnostics-format=msvc -target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s -check-prefix=MSVC +// RUN: not %clang -fdiagnostics-format=msvc -fmsc-version=1900 -target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s -check-prefix=MSVC2015 +// +// RUN: not %clang -fdiagnostics-format=vi %s 2>&1 | FileCheck %s -check-prefix=VI +// +// RUN: not %clang -fdiagnostics-format=msvc -fno-show-column -fmsc-version=1900 %s 2>&1 | FileCheck %s -check-prefix=MSVC2015_ORIG +// +// RUN: not %clang -fno-show-column %s 2>&1 | FileCheck %s -check-prefix=NO_COLUMN +// +// RUN: not %clang -Werror -fdiagnostics-format=msvc-fallback -fmsc-version=1300 %s 2>&1 | FileCheck %s -check-prefix=MSVC2010-FALLBACK +// RUN: not %clang -Werror -fdiagnostics-format=msvc-fallback -fms-compatibility-version=13.00 %s 2>&1 | FileCheck %s -check-prefix=MSVC2010-FALLBACK +// RUN: not %clang -Werror -fdiagnostics-format=msvc-fallback -fmsc-version=1800 %s 2>&1 | FileCheck %s -check-prefix=MSVC2013-FALLBACK +// RUN: not %clang -Werror -fdiagnostics-format=msvc-fallback -fmsc-version=1900 %s 2>&1 | FileCheck %s -check-prefix=MSVC2015-FALLBACK + + +// DEFAULT: {{.*}}:48:5: error: invalid instruction mnemonic 'deliberate_error' +// MSVC2010: {{.*}}(48,4) : error: invalid instruction mnemonic 'deliberate_error' +// MSVC2013: {{.*}}(48,5) : error: invalid instruction mnemonic 'deliberate_error' +// MSVC: {{.*}}(48,5){{ ?}}: error: invalid instruction mnemonic 'deliberate_error' +// MSVC2015: {{.*}}(48,5): error: invalid instruction mnemonic 'deliberate_error' +// VI: {{.*}} +48:5: error: invalid instruction mnemonic 'deliberate_error' +// MSVC2015_ORIG: {{.*}}(48): error: invalid instruction mnemonic 'deliberate_error' +// NO_COLUMN: {{.*}}:48: error: invalid instruction mnemonic 'deliberate_error' +// MSVC2010-FALLBACK: {{.*}}(48,4) : error: invalid instruction mnemonic 'deliberate_error' +// MSVC2013-FALLBACK: {{.*}}(48,5) : error: invalid instruction mnemonic 'deliberate_error' +// MSVC2015-FALLBACK: {{.*}}(48,5): error: invalid instruction mnemonic 'deliberate_error' + +//*********** +.section .text +.global TestFunc_ASM +TestFunc_ASM: + nop + nop + deliberate_error + ret +//*********** + + Index: tools/driver/cc1as_main.cpp =================================================================== --- tools/driver/cc1as_main.cpp +++ tools/driver/cc1as_main.cpp @@ -14,6 +14,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticOptions.h" +#include "clang/Basic/VersionTuple.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "clang/Frontend/FrontendDiagnostic.h" @@ -130,8 +131,13 @@ unsigned FatalWarnings : 1; unsigned IncrementalLinkerCompatible : 1; + unsigned ShowColumn : 1; /// The name of the relocation model to use. std::string RelocationModel; + std::string DiagnosticsFormat; + SourceMgr::TextDiagnosticFormat DiagnosticFormat; + unsigned MsvcMajorVersion; + unsigned MsvcMinorVersion; /// @} @@ -150,6 +156,9 @@ FatalWarnings = 0; IncrementalLinkerCompatible = 0; DwarfVersion = 0; + DiagnosticFormat = SourceMgr::TextDiagnosticFormat::Clang; + MsvcMajorVersion = 13; + MsvcMinorVersion = 0; } static bool CreateFromArgs(AssemblerInvocation &Res, @@ -277,6 +286,31 @@ Args.hasArg(OPT_mincremental_linker_compatible); Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym); + if (const Arg *A = Args.getLastArg(OPT_fdiagnostics_format_EQ)) { + Opts.DiagnosticsFormat = A->getValue(); + } else { + Opts.DiagnosticsFormat = "clang"; + } + + Opts.ShowColumn = Args.hasFlag(OPT_fshow_column, OPT_fno_show_column, + /*Default=*/true); + + const Arg *MSCompatibilityVersion = + Args.getLastArg(options::OPT_fms_compatibility_version); + + if (MSCompatibilityVersion) { + VersionTuple MSVT; + if (MSVT.tryParse(MSCompatibilityVersion->getValue())) { + Diags.Report(diag::err_drv_invalid_value) + << MSCompatibilityVersion->getAsString(Args) + << MSCompatibilityVersion->getValue(); + Success = false; + } else { + Opts.MsvcMajorVersion = MSVT.getMajor(); + Opts.MsvcMinorVersion = MSVT.getMinor().getValueOr(0); + } + } + return Success; } @@ -328,6 +362,54 @@ // it later. SrcMgr.setIncludeDirs(Opts.IncludePaths); + if (Opts.DiagnosticsFormat == "vi") { + SrcMgr.DiagnosticFormat = SourceMgr::TextDiagnosticFormat::Vi; + } else if (Opts.DiagnosticsFormat == "msvc" || + Opts.DiagnosticsFormat == "msvc-fallback") { + SrcMgr.DiagnosticFormat = SourceMgr::TextDiagnosticFormat::MSVC; + } else { + SrcMgr.DiagnosticFormat = SourceMgr::TextDiagnosticFormat::Clang; + } + + SrcMgr.ShowColumn = (Opts.ShowColumn) ? true : false; + + switch (Opts.MsvcMajorVersion) { + case 10: + SrcMgr.MsvcVersion = SourceMgr::MSVCVersion::MSVC40; + break; + case 11: + SrcMgr.MsvcVersion = SourceMgr::MSVCVersion::MSVC97; + break; + case 12: + SrcMgr.MsvcVersion = SourceMgr::MSVCVersion::MSVC60; + break; + case 13: + SrcMgr.MsvcVersion = (Opts.MsvcMinorVersion == 0) + ? SourceMgr::MSVCVersion::MSVC2002 + : SourceMgr::MSVCVersion::MSVC2003; + break; + case 14: + SrcMgr.MsvcVersion = SourceMgr::MSVCVersion::MSVC2005; + break; + case 15: + SrcMgr.MsvcVersion = SourceMgr::MSVCVersion::MSVC2008; + break; + case 16: + SrcMgr.MsvcVersion = SourceMgr::MSVCVersion::MSVC2010; + break; + case 17: + SrcMgr.MsvcVersion = SourceMgr::MSVCVersion::MSVC2012; + break; + case 18: + SrcMgr.MsvcVersion = SourceMgr::MSVCVersion::MSVC2013; + break; + case 19: + SrcMgr.MsvcVersion = (Opts.MsvcMinorVersion == 0) + ? SourceMgr::MSVCVersion::MSVC2015 + : SourceMgr::MSVCVersion::MSVC2017; + break; + } + std::unique_ptr MRI(TheTarget->createMCRegInfo(Opts.Triple)); assert(MRI && "Unable to create target register info!");