From ae28a7e53505859d5335e931e1ebb16f93cc87ca Mon Sep 17 00:00:00 2001 From: luofeng14 Date: Mon, 20 Jan 2025 22:21:34 +0800 Subject: [PATCH] [Clang] Set default prefix for search path when prefix is empty --- clang/lib/Driver/ToolChains/Clang.cpp | 6 ++++++ clang/test/Driver/prefix.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 clang/test/Driver/prefix.c diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 4e5f689498d6..7e78e4d8d351 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4689,6 +4689,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, #ifdef BUILD_FOR_OPENEULER if (Args.hasFlag(options::OPT_fgcc_compatible, options::OPT_fno_gcc_compatible, false)) { + if (Args.hasArg(options::OPT_nostdinc) && !Args.hasArg(options::OPT_iprefix)) { + SmallString<128> P(D.ResourceDir); + P += llvm::sys::path::get_separator(); + CmdArgs.insert(CmdArgs.begin() + 1, "-iprefix"); + CmdArgs.insert(CmdArgs.begin() + 2, Args.MakeArgString(P)); + } // compatibility relevent warnings CmdArgs.push_back("-Wno-error=unknown-warning-option"); CmdArgs.push_back("-Wno-error=ignored-attributes"); diff --git a/clang/test/Driver/prefix.c b/clang/test/Driver/prefix.c new file mode 100644 index 000000000000..7f1cb4672c39 --- /dev/null +++ b/clang/test/Driver/prefix.c @@ -0,0 +1,14 @@ +// REQUIRES: build_for_openeuler + +// RUN: %clang %s +// RUN: %clang -iprefix $(dirname `which clang`)/../lib/clang/*/ -iwithprefix include %s +// RUN: %clang -iwithprefix include %s +// RUN: %clang -nostdinc -iwithprefix include %s -fgcc-compatible +// RUN: %clang -nostdinc -iprefix $(dirname `which clang`)/../lib/clang/*/ -iwithprefix include %s -fgcc-compatible +// RUN: not %clang -nostdinc -iwithprefix include %s +// RUN: not %clang -nostdinc -iprefix "" -iwithprefix include %s + +#include +int main(void) { +return 0; +} -- Gitee