From 7a7ffdcdef1fdd2f8807fecfb5ce3c438d942b23 Mon Sep 17 00:00:00 2001 From: eastb233 Date: Mon, 15 Dec 2025 10:15:13 +0800 Subject: [PATCH] [NFC] Remove BUILD_FOR_OPENEULER macro for gcc compatible features --- clang/CMakeLists.txt | 2 +- .../include/clang/Basic/DiagnosticOptions.def | 2 -- clang/include/clang/Basic/LangOptions.def | 4 +-- clang/include/clang/Driver/Options.td | 9 ------- clang/lib/Driver/Driver.cpp | 6 ----- clang/lib/Driver/ToolChains/Clang.cpp | 14 ++++------- clang/lib/Frontend/CompilerInvocation.cpp | 25 ++----------------- .../test-generate-missing-build-notes.cpp | 9 +++---- clang/test/Driver/test-warnning.c | 8 +++--- clang/test/Driver/z-args.c | 1 - 10 files changed, 16 insertions(+), 64 deletions(-) diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt index 84d2e7fa10b2..29500285c859 100644 --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -355,7 +355,7 @@ if (LLVM_COMPILER_IS_GCC_COMPATIBLE) endif () endif () -option(BUILD_FOR_OPENEULER "Add gcc compatible options for openEuler toolchain" OFF) +option(BUILD_FOR_OPENEULER "Build support for openeuler" OFF) if (BUILD_FOR_OPENEULER) add_definitions( -DBUILD_FOR_OPENEULER ) endif() diff --git a/clang/include/clang/Basic/DiagnosticOptions.def b/clang/include/clang/Basic/DiagnosticOptions.def index 5253e951d403..6a322688cc68 100644 --- a/clang/include/clang/Basic/DiagnosticOptions.def +++ b/clang/include/clang/Basic/DiagnosticOptions.def @@ -99,9 +99,7 @@ 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 diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 1b7cb80a91a9..94d1ac90ee9e 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -525,9 +525,7 @@ BENIGN_LANGOPT(CheckConstexprFunctionBodies, 1, 1, LANGOPT(BoundsSafety, 1, 0, "Bounds safety extension for C") -#ifdef BUILD_FOR_OPENEULER -LANGOPT(GccCompatible, 1, 0, "Enable gcc compatibility for openEuler.") -#endif +LANGOPT(GccCompatible, 1, 0, "Enable gcc compatible compilation") #undef LANGOPT #undef COMPATIBLE_LANGOPT diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index df86644e4a7c..526c3bddfe86 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1043,13 +1043,8 @@ def Xopenmp_target : Separate<["-"], "Xopenmp-target">, Group def Xopenmp_target_EQ : JoinedAndSeparate<["-"], "Xopenmp-target=">, Group, HelpText<"Pass to the target offloading toolchain identified by .">, MetaVarName<" ">; -#ifdef BUILD_FOR_OPENEULER def z : JoinedOrSeparate<["-"], "z">, Flags<[LinkerInput]>, HelpText<"Pass -z or -z to the linker">, MetaVarName<"">, -#else -def z : Separate<["-"], "z">, Flags<[LinkerInput]>, - HelpText<"Pass -z to the linker">, MetaVarName<"">, -#endif Group; def offload_link : Flag<["--"], "offload-link">, Group, HelpText<"Use the new offloading linker to perform the link job.">; @@ -2329,7 +2324,6 @@ def fmemory_profile_use_EQ : Joined<["-"], "fmemory-profile-use=">, HelpText<"Use memory profile for profile-guided memory optimization">, MarshallingInfoString>; -#ifdef BUILD_FOR_OPENEULER def fgcc_compatible : Flag<["-"], "fgcc-compatible">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, MarshallingInfoFlag>, @@ -2340,7 +2334,6 @@ def fGNU_compatibility : Flag<["-"], "fGNU-compatibility">, HelpText<"Alias for -fgcc_compatible">; def fno_gcc_compatible : Flag<["-"], "fno-gcc-compatible">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>; -#endif // Begin sanitizer flags. These should all be core options exposed in all driver // modes. @@ -6484,13 +6477,11 @@ def falign_jumps_EQ : Joined<["-"], "falign-jumps=">, Group, Group; defm peephole2 : BooleanFFlag<"peephole2">, Group; defm aggressive_loop_optiomizations : BooleanFFlag<"aggressive-loop-optiomizations">, Group; def flto_partition_EQ : Joined<["-"], "flto-partition=">, Group; -#endif defm check_new : BoolOption<"f", "check-new", LangOpts<"CheckNew">, DefaultFalse, diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 7ce7bb733acb..fd4b5301c34e 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1531,13 +1531,11 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { // Populate the tool chains for the offloading devices, if any. CreateOffloadingDeviceToolChains(*C, Inputs); -#ifdef BUILD_FOR_OPENEULER if(C->getArgs().hasFlag(options::OPT_fgcc_compatible, options::OPT_fno_gcc_compatible, false)) { getDiags().setDiagnosticGroupWarningAsError("unused-command-line-argument", 0); getDiags().setDiagnosticGroupWarningAsError("ignored-optimization-argument", 0); } -#endif // Construct the list of abstract actions to perform for this compilation. On // MachO targets this uses the driver-driver and universal actions. @@ -2551,7 +2549,6 @@ void Driver::BuildUniversalActions(Compilation &C, const ToolChain &TC, } } -#ifdef BUILD_FOR_OPENEULER llvm::DenseSet ZArgsList{ "defs", "muldefs", "execstack", "noexecstack", "globalaudit", "combreloc", "nocombreloc", "global", "initfirst", "interpose", "lazy", "loadfltr", @@ -2559,7 +2556,6 @@ llvm::DenseSet ZArgsList{ "origin", "relro", "norelro", "separate-code", "noseparate-code", "common", "nocommon", "text", "notext", "textoff" }; -#endif bool Driver::DiagnoseInputExistence(const DerivedArgList &Args, StringRef Value, types::ID Ty, bool TypoCorrect) const { @@ -2632,13 +2628,11 @@ bool Driver::DiagnoseInputExistence(const DerivedArgList &Args, StringRef Value, if (IsCLMode() && Ty == types::TY_Object && !Value.starts_with("/")) return true; -#ifdef BUILD_FOR_OPENEULER if (ZArgsList.find(Value) != ZArgsList.end() || Value.starts_with("common-page-size=") || Value.starts_with("max-page-size=") || Value.starts_with("stack-size=")) return true; -#endif Diag(clang::diag::err_drv_no_such_file) << Value; return false; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index c572b74324ef..647982832617 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2773,12 +2773,10 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, CmdArgs.push_back(Value.data()); } else if (Value == "--version") { D.PrintVersion(C, llvm::outs()); - #ifdef BUILD_FOR_OPENEULER } else if (Value.starts_with("--generate-missing-build-notes=") && - Args.hasFlag(options::OPT_fgcc_compatible, - options::OPT_fno_gcc_compatible, false)) { - // Do nothing. - #endif + Args.hasFlag(options::OPT_fgcc_compatible, + options::OPT_fno_gcc_compatible, false)) { + // Do nothing. } else { D.Diag(diag::err_drv_unsupported_option_argument) << A->getSpelling() << Value; @@ -4998,7 +4996,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-triple"); CmdArgs.push_back(Args.MakeArgString(TripleStr)); -#ifdef BUILD_FOR_OPENEULER if (Args.hasFlag(options::OPT_fgcc_compatible, options::OPT_fno_gcc_compatible, false)) { // compatibility relevent warnings @@ -5019,7 +5016,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-Wno-error=return-type-c-linkage"); // By default, clang reports errors, but gcc reports warnings. // when -Werror is passed don't add -Wno-error=*. - if(!D.getDiags().getWarningsAsErrors()) { + if (!D.getDiags().getWarningsAsErrors()) { CmdArgs.push_back("-Wno-error=implicit-function-declaration"); CmdArgs.push_back("-Wno-error=incompatible-function-pointer-types"); CmdArgs.push_back("-Wno-error=register"); @@ -5029,7 +5026,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-Wno-error=return-type"); CmdArgs.push_back("-Wno-error=reserved-user-defined-literal"); } - //other warnings + // Other warnings CmdArgs.push_back("-Wno-error=cast-align"); CmdArgs.push_back("-Wno-error=enum-conversion"); CmdArgs.push_back("-Wno-error=switch"); @@ -5040,7 +5037,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-fgcc-compatible"); } -#endif if (const Arg *MJ = Args.getLastArg(options::OPT_MJ)) { DumpCompilationDatabase(C, MJ->getValue(), TripleStr, Output, Input, Args); diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 72e18071ed7f..f0dafb0eff3d 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -938,9 +938,8 @@ static void addDiagnosticArgs(ArgList &Args, OptSpecifier Group, OptSpecifier GroupWithValue, std::vector &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); + 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 @@ -968,22 +967,6 @@ static void addDiagnosticArgs(ArgList &Args, OptSpecifier Group, 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)) { - // 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). - Diagnostics.push_back(A->getValue()); - } -#endif } } @@ -3962,10 +3945,8 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts, if (!Opts.RandstructSeed.empty()) GenerateArg(Consumer, OPT_frandomize_layout_seed_EQ, Opts.RandstructSeed); -#ifdef BUILD_FOR_OPENEULER if (Opts.GccCompatible) GenerateArg(Consumer, OPT_fgcc_compatible); -#endif } bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, @@ -4595,9 +4576,7 @@ 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; } diff --git a/clang/test/Driver/test-generate-missing-build-notes.cpp b/clang/test/Driver/test-generate-missing-build-notes.cpp index efd5251e6a1c..4a9aef08a36d 100644 --- a/clang/test/Driver/test-generate-missing-build-notes.cpp +++ b/clang/test/Driver/test-generate-missing-build-notes.cpp @@ -1,11 +1,10 @@ -// REQUIRES: build_for_openeuler // RUN: %clang -### -fgcc-compatible -Wa,--generate-missing-build-notes=yes %s 2>&1 | FileCheck -check-prefix=CHECK-NO-ERROR %s // RUN: %clang -### -fgcc-compatible -Wa,--generate-missing-build-notes=no %s 2>&1 | FileCheck -check-prefix=CHECK-NO-ERROR %s // CHECK-NO-ERROR-NOT: --generate-missing-build-notes= -// RUN: %clang -### -Wa,--generate-missing-build-notes=yes %s 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s -// RUN: %clang -### -Wa,--generate-missing-build-notes=no %s 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s -// RUN: %clang -### -fno-gcc-compatible -Wa,--generate-missing-build-notes=yes %s 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s -// RUN: %clang -### -fno-gcc-compatible -Wa,--generate-missing-build-notes=no %s 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s +// RUN: not %clang -### -Wa,--generate-missing-build-notes=yes %s 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s +// RUN: not %clang -### -Wa,--generate-missing-build-notes=no %s 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s +// RUN: not %clang -### -fno-gcc-compatible -Wa,--generate-missing-build-notes=yes %s 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s +// RUN: not %clang -### -fno-gcc-compatible -Wa,--generate-missing-build-notes=no %s 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s // CHECK-ERROR: error: unsupported argument '--generate-missing-build-notes= int main() { diff --git a/clang/test/Driver/test-warnning.c b/clang/test/Driver/test-warnning.c index 641f9e3512d5..5837b1636c5e 100644 --- a/clang/test/Driver/test-warnning.c +++ b/clang/test/Driver/test-warnning.c @@ -1,9 +1,7 @@ -// 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 +// RUN: %clang -v -Wall %s 2>&1 | FileCheck -check-prefix=CHECK-WARNING %s +// CHECK-WARNING: warning: format string is not a string literal (potentially insecure) +// RUN: not %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 diff --git a/clang/test/Driver/z-args.c b/clang/test/Driver/z-args.c index 83bb2b570e69..c91f26d9f2e8 100644 --- a/clang/test/Driver/z-args.c +++ b/clang/test/Driver/z-args.c @@ -1,4 +1,3 @@ -// REQUIRES: build_for_openeuler // RUN: %clang -### -znow 2>&1 | FileCheck -check-prefix=CHECK-LINKER %s // CHECK-LINKER: "-z" "now" -- Gitee