代码拉取完成,页面将自动刷新
同步操作将从 openEuler-RISC-V/clang 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
-Wall
and -Werror=format=2
override -Wno
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.33.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。