diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 95f13cc38453..396b02fc67f3 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -559,6 +559,7 @@ def filelist : Separate<["-"], "filelist">, Flags<[LinkerInput]>; def : Flag<["-"], "findirect-virtual-calls">, Alias; def finline_functions : Flag<["-"], "finline-functions">, Group; def finline : Flag<["-"], "finline">, Group; +def finput_charset_EQ : Joined<["-"], "finput-charset=">, Group; def finstrument_functions : Flag<["-"], "finstrument-functions">, Group, Flags<[CC1Option]>, HelpText<"Generate calls to instrument function entry and exit">; def : Flag<["-"], "fkeep-inline-functions">, Group; diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index c7211686e942..823816791821 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -3911,6 +3911,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, D.Diag(diag::err_drv_clang_unsupported) << Args.getLastArg(options::OPT_fno_for_scope)->getAsString(Args); + // -finput_charset=UTF-8 is default. Reject others + if (Arg *inputCharset = Args.getLastArg( + options::OPT_finput_charset_EQ)) { + StringRef value = inputCharset->getValue(); + if (value != "UTF-8") + D.Diag(diag::err_drv_invalid_value) << inputCharset->getAsString(Args) << value; + } + // -fcaret-diagnostics is default. if (!Args.hasFlag(options::OPT_fcaret_diagnostics, options::OPT_fno_caret_diagnostics, true)) diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c index c88ced05ac35..664ee8a3a4f1 100644 --- a/clang/test/Driver/clang_f_opts.c +++ b/clang/test/Driver/clang_f_opts.c @@ -129,6 +129,9 @@ // RUN: %clang -S -O20 -o /dev/null %s 2>&1 | FileCheck -check-prefix=CHECK-INVALID-O %s // CHECK-INVALID-O: warning: optimization level '-O20' is unsupported; using '-O3' instead +// RUN: %clang -### -S -finput-charset=iso-8859-1 -o /dev/null %s 2>&1 | FileCheck -check-prefix=CHECK-INVALID-CHARSET %s +// CHECK-INVALID-CHARSET: error: invalid value 'iso-8859-1' in '-finput-charset=iso-8859-1' + // Test that we don't error on these. // RUN: %clang -### -S -Werror \ // RUN: -falign-functions -falign-functions=2 -fno-align-functions \ @@ -140,6 +143,7 @@ // RUN: -fgcse -fno-gcse \ // RUN: -fident -fno-ident \ // RUN: -fimplicit-templates -fno-implicit-templates \ +// RUN: -finput-charset=UTF-8 \ // RUN: -fivopts -fno-ivopts \ // RUN: -fnon-call-exceptions -fno-non-call-exceptions \ // RUN: -fpermissive -fno-permissive \