Handling of option -Wall and -Werror=format=2 override -Wno
Signed-off-by: xiajingze <xiajingze1@huawei.com>
This commit is contained in:
parent
ad573df38e
commit
b66116b404
225
0023-Handling-of-option-Wall-and-Werror-format-2-override.patch
Normal file
225
0023-Handling-of-option-Wall-and-Werror-format-2-override.patch
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
From 001e7941bc936847b07da2fdb4b19a8adcba7718 Mon Sep 17 00:00:00 2001
|
||||||
|
From: liyunfei <liyunfei33@huawei.com>
|
||||||
|
Date: Fri, 19 Jul 2024 10:44:49 +0800
|
||||||
|
Subject: [PATCH 1/2] Complete -fgcc-compatible option scope
|
||||||
|
|
||||||
|
Complete -fgcc-compatible option scope to Langopts and Diagopts
|
||||||
|
|
||||||
|
(cherry picked from commit 8881224782ade2afaab4860f3462e44b7d5c2601)
|
||||||
|
Signed-off-by: wangqiang <wangqiang1@kylinos.cn>
|
||||||
|
---
|
||||||
|
clang/include/clang/Basic/DiagnosticOptions.def | 4 ++++
|
||||||
|
clang/include/clang/Basic/LangOptions.def | 4 ++++
|
||||||
|
clang/include/clang/Driver/Options.td | 6 ++++--
|
||||||
|
clang/lib/Driver/ToolChains/Clang.cpp | 2 ++
|
||||||
|
clang/lib/Frontend/CompilerInvocation.cpp | 15 +++++++++++++--
|
||||||
|
5 files changed, 27 insertions(+), 4 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/clang/include/clang/Basic/DiagnosticOptions.def b/clang/include/clang/Basic/DiagnosticOptions.def
|
||||||
|
index 6d0c1b14acc1..5253e951d403 100644
|
||||||
|
--- a/clang/include/clang/Basic/DiagnosticOptions.def
|
||||||
|
+++ b/clang/include/clang/Basic/DiagnosticOptions.def
|
||||||
|
@@ -99,6 +99,10 @@ VALUE_DIAGOPT(MessageLength, 32, 0)
|
||||||
|
|
||||||
|
DIAGOPT(ShowSafeBufferUsageSuggestions, 1, 0)
|
||||||
|
|
||||||
|
+#ifdef BUILD_FOR_OPENEULER
|
||||||
|
+DIAGOPT(GccCompatible, 1, 0) /// -fgcc-compatible
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
#undef DIAGOPT
|
||||||
|
#undef ENUM_DIAGOPT
|
||||||
|
#undef VALUE_DIAGOPT
|
||||||
|
diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def
|
||||||
|
index f7ec0406f33e..eb62a4951c65 100644
|
||||||
|
--- a/clang/include/clang/Basic/LangOptions.def
|
||||||
|
+++ b/clang/include/clang/Basic/LangOptions.def
|
||||||
|
@@ -468,6 +468,10 @@ LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process statements"
|
||||||
|
|
||||||
|
BENIGN_LANGOPT(CheckNew, 1, 0, "Do not assume C++ operator new may not return NULL")
|
||||||
|
|
||||||
|
+#ifdef BUILD_FOR_OPENEULER
|
||||||
|
+LANGOPT(GccCompatible, 1, 0, "Enable gcc compatibility for openEuler.")
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
#undef LANGOPT
|
||||||
|
#undef COMPATIBLE_LANGOPT
|
||||||
|
#undef BENIGN_LANGOPT
|
||||||
|
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
|
||||||
|
index 71d6ed66ab96..344c8bd49da7 100644
|
||||||
|
--- a/clang/include/clang/Driver/Options.td
|
||||||
|
+++ b/clang/include/clang/Driver/Options.td
|
||||||
|
@@ -1810,9 +1810,11 @@ def fautotune_rank : Flag<["-"], "fautotune-rank">, Group<f_Group>,
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BUILD_FOR_OPENEULER
|
||||||
|
-def fgcc_compatible : Flag<["-"], "fgcc-compatible">, Group<f_Group>,
|
||||||
|
+def fgcc_compatible : Flag<["-"], "fgcc-compatible">,
|
||||||
|
+ Flags<[CC1Option]>,
|
||||||
|
+ MarshallingInfoFlag<DiagnosticOpts<"GccCompatible">>,
|
||||||
|
HelpText<"Enable gcc compatibility for openEuler.">;
|
||||||
|
-def fno_gcc_compatible : Flag<["-"], "fno-gcc-compatible">, Group<f_Group>;
|
||||||
|
+def fno_gcc_compatible : Flag<["-"], "fno-gcc-compatible">, Flags<[CC1Option]>;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Begin sanitizer flags. These should all be core options exposed in all driver
|
||||||
|
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
|
||||||
|
index c49cb43ff19c..fac4f03d6193 100644
|
||||||
|
--- a/clang/lib/Driver/ToolChains/Clang.cpp
|
||||||
|
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
|
||||||
|
@@ -4725,6 +4725,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
|
CmdArgs.push_back("-Wno-error=varargs");
|
||||||
|
CmdArgs.push_back("-Wno-error=unused-value");
|
||||||
|
CmdArgs.push_back("-Wno-error=format-nonliteral");
|
||||||
|
+
|
||||||
|
+ CmdArgs.push_back("-fgcc-compatible");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
|
||||||
|
index 1fba91bed041..d7b609ef276c 100644
|
||||||
|
--- a/clang/lib/Frontend/CompilerInvocation.cpp
|
||||||
|
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
|
||||||
|
@@ -818,8 +818,9 @@ static void addDiagnosticArgs(ArgList &Args, OptSpecifier Group,
|
||||||
|
std::vector<std::string> &Diagnostics) {
|
||||||
|
for (auto *A : Args.filtered(Group)) {
|
||||||
|
if (A->getOption().getKind() == Option::FlagClass) {
|
||||||
|
- // The argument is a pure flag (such as OPT_Wall or OPT_Wdeprecated). Add
|
||||||
|
- // its name (minus the "W" or "R" at the beginning) to the diagnostics.
|
||||||
|
+ // The argument is a pure flag (such as OPT_Wall or
|
||||||
|
+ // OPT_Wdeprecated). Add its name (minus the "W" or "R" at the
|
||||||
|
+ // beginning) to the diagnostics.
|
||||||
|
Diagnostics.push_back(
|
||||||
|
std::string(A->getOption().getName().drop_front(1)));
|
||||||
|
} else if (A->getOption().matches(GroupWithValue)) {
|
||||||
|
@@ -829,6 +830,7 @@ static void addDiagnosticArgs(ArgList &Args, OptSpecifier Group,
|
||||||
|
std::string(A->getOption().getName().drop_front(1).rtrim("=-")));
|
||||||
|
} else {
|
||||||
|
// Otherwise, add its value (for OPT_W_Joined and similar).
|
||||||
|
+
|
||||||
|
Diagnostics.push_back(A->getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -3522,6 +3524,11 @@ void CompilerInvocation::GenerateLangArgs(const LangOptions &Opts,
|
||||||
|
|
||||||
|
if (!Opts.RandstructSeed.empty())
|
||||||
|
GenerateArg(Args, OPT_frandomize_layout_seed_EQ, Opts.RandstructSeed, SA);
|
||||||
|
+
|
||||||
|
+#ifdef BUILD_FOR_OPENEULER
|
||||||
|
+ if (Opts.GccCompatible)
|
||||||
|
+ GenerateArg(Args, OPT_fgcc_compatible, SA);
|
||||||
|
+#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||||
|
@@ -4073,6 +4080,10 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||||
|
Diags.Report(diag::err_drv_hlsl_unsupported_target) << T.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
+#ifdef BUILD_FOR_OPENEULER
|
||||||
|
+ Opts.GccCompatible = Args.hasArg(options::OPT_fgcc_compatible);
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
return Diags.getNumErrors() == NumErrorsBefore;
|
||||||
|
}
|
||||||
|
|
||||||
|
--
|
||||||
|
2.43.0
|
||||||
|
|
||||||
|
|
||||||
|
From c6f76aa5cdb02c376df17aafadf2dd7cf41fe5b1 Mon Sep 17 00:00:00 2001
|
||||||
|
From: wangqiang <wangqiang1@kylinos.cn>
|
||||||
|
Date: Fri, 19 Jul 2024 11:01:22 +0800
|
||||||
|
Subject: [PATCH 2/2] Handling of option `-Wall` and `-Werror=format=2`
|
||||||
|
override `-Wno`
|
||||||
|
|
||||||
|
Fix nfs-utils build issue
|
||||||
|
|
||||||
|
Signed-off-by: wangqiang <wangqiang1@kylinos.cn>
|
||||||
|
---
|
||||||
|
clang/lib/Frontend/CompilerInvocation.cpp | 32 ++++++++++++++++++++++-
|
||||||
|
clang/test/Driver/test-warnning.c | 15 +++++++++++
|
||||||
|
2 files changed, 46 insertions(+), 1 deletion(-)
|
||||||
|
create mode 100644 clang/test/Driver/test-warnning.c
|
||||||
|
|
||||||
|
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
|
||||||
|
index d7b609ef276c..cbb122cc6eeb 100644
|
||||||
|
--- a/clang/lib/Frontend/CompilerInvocation.cpp
|
||||||
|
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
|
||||||
|
@@ -817,10 +817,40 @@ static void addDiagnosticArgs(ArgList &Args, OptSpecifier Group,
|
||||||
|
OptSpecifier GroupWithValue,
|
||||||
|
std::vector<std::string> &Diagnostics) {
|
||||||
|
for (auto *A : Args.filtered(Group)) {
|
||||||
|
+#ifdef BUILD_FOR_OPENEULER
|
||||||
|
+ bool GccCompatible = Args.hasFlag(options::OPT_fgcc_compatible,
|
||||||
|
+ options::OPT_fno_gcc_compatible, false);
|
||||||
|
if (A->getOption().getKind() == Option::FlagClass) {
|
||||||
|
// The argument is a pure flag (such as OPT_Wall or
|
||||||
|
// OPT_Wdeprecated). Add its name (minus the "W" or "R" at the
|
||||||
|
// beginning) to the diagnostics.
|
||||||
|
+ if (A->getOption().getName() == "Wall" && GccCompatible) {
|
||||||
|
+ // Avoid -Wall and -Werror=format=2 override -Wno-xxx
|
||||||
|
+ Diagnostics.insert(
|
||||||
|
+ Diagnostics.begin(),
|
||||||
|
+ std::string(A->getOption().getName().drop_front(1)));
|
||||||
|
+ } else {
|
||||||
|
+ Diagnostics.push_back(
|
||||||
|
+ std::string(A->getOption().getName().drop_front(1)));
|
||||||
|
+ }
|
||||||
|
+ } else if (A->getOption().matches(GroupWithValue)) {
|
||||||
|
+ // This is -Wfoo= or -Rfoo=, where foo is the name of the diagnostic
|
||||||
|
+ // group. Add only the group name to the diagnostics.
|
||||||
|
+ Diagnostics.push_back(std::string(
|
||||||
|
+ A->getOption().getName().drop_front(1).rtrim("=-")));
|
||||||
|
+ } else {
|
||||||
|
+ // Otherwise, add its value (for OPT_W_Joined and similar).
|
||||||
|
+ if (std::string(A->getValue()) == "error=format=2" && GccCompatible) {
|
||||||
|
+ // Avoid -Werror=format=2 override -Wno-xxx
|
||||||
|
+ Diagnostics.insert(Diagnostics.begin(), A->getValue());
|
||||||
|
+ } else {
|
||||||
|
+ Diagnostics.push_back(A->getValue());
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+#else
|
||||||
|
+ if (A->getOption().getKind() == Option::FlagClass) {
|
||||||
|
+ // The argument is a pure flag (such as OPT_Wall or OPT_Wdeprecated). Add
|
||||||
|
+ // its name (minus the "W" or "R" at the beginning) to the diagnostics.
|
||||||
|
Diagnostics.push_back(
|
||||||
|
std::string(A->getOption().getName().drop_front(1)));
|
||||||
|
} else if (A->getOption().matches(GroupWithValue)) {
|
||||||
|
@@ -830,9 +860,9 @@ static void addDiagnosticArgs(ArgList &Args, OptSpecifier Group,
|
||||||
|
std::string(A->getOption().getName().drop_front(1).rtrim("=-")));
|
||||||
|
} else {
|
||||||
|
// Otherwise, add its value (for OPT_W_Joined and similar).
|
||||||
|
-
|
||||||
|
Diagnostics.push_back(A->getValue());
|
||||||
|
}
|
||||||
|
+#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
diff --git a/clang/test/Driver/test-warnning.c b/clang/test/Driver/test-warnning.c
|
||||||
|
new file mode 100644
|
||||||
|
index 000000000000..641f9e3512d5
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/clang/test/Driver/test-warnning.c
|
||||||
|
@@ -0,0 +1,15 @@
|
||||||
|
+// REQUIRES: build_for_openeuler
|
||||||
|
+
|
||||||
|
+// RUN: %clang -v -fgcc-compatible -Wno-format-security -Werror=format=2 -Wall %s
|
||||||
|
+// RUN: %clang -v -Wall %s 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s
|
||||||
|
+// CHECK-ERROR: warning: format string is not a string literal (potentially insecure)
|
||||||
|
+// RUN: %clang -v -Wno-format-security -Werror=format=2 -Wall %s 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s
|
||||||
|
+// CHECK-ERROR: error: format string is not a string literal (potentially insecure)
|
||||||
|
+
|
||||||
|
+#include <stdio.h>
|
||||||
|
+
|
||||||
|
+int main() {
|
||||||
|
+ char *str = "llvm-project";
|
||||||
|
+ printf(str);
|
||||||
|
+ return 0;
|
||||||
|
+}
|
||||||
|
\ No newline at end of file
|
||||||
|
--
|
||||||
|
2.43.0
|
||||||
|
|
||||||
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
Name: %{pkg_name}
|
Name: %{pkg_name}
|
||||||
Version: %{clang_version}
|
Version: %{clang_version}
|
||||||
Release: 26
|
Release: 27
|
||||||
Summary: A C language family front-end for LLVM
|
Summary: A C language family front-end for LLVM
|
||||||
|
|
||||||
License: NCSA
|
License: NCSA
|
||||||
@ -74,6 +74,7 @@ Patch19: 0019-AArch64-Support-HiSilicon-s-HIP09-Processor.patch
|
|||||||
Patch20: 0020-Backport-LoongArch-fix-and-add-some-new-support.patch
|
Patch20: 0020-Backport-LoongArch-fix-and-add-some-new-support.patch
|
||||||
Patch21: 0021-AArch64-Delete-hip09-macro.patch
|
Patch21: 0021-AArch64-Delete-hip09-macro.patch
|
||||||
Patch22: 0022-Driver-Pass-z-arg-and-Wl-z-arg-option-to-the-linker.patch
|
Patch22: 0022-Driver-Pass-z-arg-and-Wl-z-arg-option-to-the-linker.patch
|
||||||
|
Patch23: 0023-Handling-of-option-Wall-and-Werror-format-2-override.patch
|
||||||
|
|
||||||
# Patches for clang-tools-extra
|
# Patches for clang-tools-extra
|
||||||
# See https://reviews.llvm.org/D120301
|
# See https://reviews.llvm.org/D120301
|
||||||
@ -418,6 +419,9 @@ LD_LIBRARY_PATH=%{buildroot}/%{install_libdir} %{__ninja} check-all -C ./_build
|
|||||||
%{install_bindir}/git-clang-format
|
%{install_bindir}/git-clang-format
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Tue Nov 19 2024 wangqiang <wangqiang1@kylinos.cn> - 17.0.6-27
|
||||||
|
- Handling of option `-Wall` and `-Werror=format=2` override `-Wno`
|
||||||
|
|
||||||
* Tue Nov 19 2024 xiajingze <xiajingze1@huawei.com> - 17.0.6-26
|
* Tue Nov 19 2024 xiajingze <xiajingze1@huawei.com> - 17.0.6-26
|
||||||
- [Driver] Pass -z<arg> and -Wl,-z <arg> option to the linker
|
- [Driver] Pass -z<arg> and -Wl,-z <arg> option to the linker
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user