From e2b32738e0873ba3b916ff46841b8c588dea57eb Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 11 Jul 2014 11:43:57 +0000 Subject: [PATCH] GCC compatibility: Create a Group to ignore unsupported optimization. Returns a warning when using an unknown optimization flag. This patch includes -finline-limit as one of those ignored flags. More options will be moved in this group Patch by Arthur Marble in the context of Debian Google Summer of code 2014. Reviewers: rnk, Sylvestre git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212805 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticDriverKinds.td | 2 ++ include/clang/Driver/Options.td | 7 ++++++- lib/Driver/Tools.cpp | 7 +++++++ test/Driver/clang_f_opts.c | 8 ++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index b5a807ecf2..e67c3522b0 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -119,6 +119,8 @@ def err_drv_emit_llvm_link : Error< def err_drv_optimization_remark_pattern : Error< "%0 in '%1'">; +def warn_ignored_gcc_optimization : Warning<"ignoring unsupported optimization flag '%0'">, + InGroup; def warn_O4_is_O3 : Warning<"-O4 is equivalent to -O3">, InGroup; def warn_drv_optimization_value : Warning<"optimization level '%0' is unsupported; using '%1%2' instead">, InGroup; diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 0cb0272860..1142ef2e47 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -91,6 +91,10 @@ def clang_ignored_f_Group : OptionGroup<"">, def clang_ignored_m_Group : OptionGroup<"">, Group; +// Group that ignores all gcc optimizations that won't be implemented +def clang_ignored_gcc_optimization_f_Group : OptionGroup< + "">, Group; + ///////// // Options @@ -1591,7 +1595,8 @@ defm gcse : BooleanFFlag<"gcse">, Group; defm gnu : BooleanFFlag<"gnu">, Group; defm ident : BooleanFFlag<"ident">, Group; defm implicit_templates : BooleanFFlag<"implicit-templates">, Group; -defm inline_limit : BooleanFFlag<"inline-limit">, Group; +def finline_limit_EQ : Joined<["-"], "finline-limit=">, Group; +defm finline_limit : BooleanFFlag<"inline-limit">, Group; defm ivopts : BooleanFFlag<"ivopts">, Group; defm non_call_exceptions : BooleanFFlag<"non-call-exceptions">, Group; defm permissive : BooleanFFlag<"permissive">, Group; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index cac20a1519..3846d471bb 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -3138,6 +3138,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, } } + // Warn about ignored options to clang. + for (arg_iterator it = Args.filtered_begin( + options::OPT_clang_ignored_gcc_optimization_f_Group), + ie = Args.filtered_end(); it != ie; ++it) { + D.Diag(diag::warn_ignored_gcc_optimization) << (*it)->getAsString(Args); + } + // Don't warn about unused -flto. This can happen when we're preprocessing or // precompiling. Args.ClaimAllArgs(options::OPT_flto); diff --git a/test/Driver/clang_f_opts.c b/test/Driver/clang_f_opts.c index c5ebe6cc45..d762faf568 100644 --- a/test/Driver/clang_f_opts.c +++ b/test/Driver/clang_f_opts.c @@ -164,9 +164,17 @@ // RUN: -fno-unsigned-char \ // RUN: -fno-signed-char \ // RUN: -fstrength-reduce -fno-strength-reduce \ +// RUN: -finline-limit=1000 \ +// RUN: -finline-limit \ // RUN: %s 2>&1 | FileCheck --check-prefix=IGNORE %s // IGNORE-NOT: error: unknown argument +// Test that the warning is displayed on these. +// RUN: %clang -### -finline-limit=1000 %s 2>&1 | FileCheck --check-prefix=CHECK-WARNING1 %s +// RUN: %clang -### -finline-limit %s 2>&1 | FileCheck --check-prefix=CHECK-WARNING2 %s +// CHECK-WARNING1: ignoring unsupported optimization flag '-finline-limit=1000 +// CHECK-WARNING2: ignoring unsupported optimization flag '-finline-limit' + // RUN: %clang -### -fshort-wchar -fno-short-wchar %s 2>&1 | FileCheck -check-prefix=CHECK-WCHAR1 %s // RUN: %clang -### -fno-short-wchar -fshort-wchar %s 2>&1 | FileCheck -check-prefix=CHECK-WCHAR2 %s // CHECK-WCHAR1: -fno-short-wchar -- 2.40.0