diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 1fba91bed04141b03eb5f8c1a71889f964877048..c844452dee36ecb5cad1968b66d559c71c45736d 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -3127,6 +3127,36 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args, IsIndexHeaderMap = false; } +#ifdef BUILD_FOR_OPENEULER + // Add -iprefix/-iwithprefix/-iwithprefixbefore options. + StringRef Prefix = ""; // FIXME: This isn't the correct default prefix. + if (Args.hasFlag(options::OPT_fgcc_compatible, options::OPT_fno_gcc_compatible, false)) { + Prefix = Opts.ResourceDir; // default prefix. + } + for (const auto *A : + Args.filtered(OPT_iprefix, OPT_iwithprefix, OPT_iwithprefixbefore)) { + llvm::SmallString<128> searchPath(Prefix.str()); + if (Args.hasFlag(options::OPT_fgcc_compatible, options::OPT_fno_gcc_compatible, false)) { + llvm::sys::path::append(searchPath, A->getValue()); + } + if (A->getOption().matches(OPT_iprefix)) + Prefix = A->getValue(); + else if (A->getOption().matches(OPT_iwithprefix)) { + if (Args.hasFlag(options::OPT_fgcc_compatible, options::OPT_fno_gcc_compatible, false)) { + Opts.AddPath(searchPath, frontend::After, false, true); + } else { + Opts.AddPath(Prefix.str() + A->getValue(), frontend::After, false, true); + } + } + else { + if (Args.hasFlag(options::OPT_fgcc_compatible, options::OPT_fno_gcc_compatible, false)) { + Opts.AddPath(searchPath, frontend::Angled, false, true); + } else { + Opts.AddPath(Prefix.str() + A->getValue(), frontend::Angled, false, true); + } + } + } +#else // Add -iprefix/-iwithprefix/-iwithprefixbefore options. StringRef Prefix = ""; // FIXME: This isn't the correct default prefix. for (const auto *A : @@ -3138,6 +3168,7 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args, else Opts.AddPath(Prefix.str() + A->getValue(), frontend::Angled, false, true); } +#endif for (const auto *A : Args.filtered(OPT_idirafter)) Opts.AddPath(A->getValue(), frontend::After, false, true); diff --git a/clang/test/Driver/prefix.c b/clang/test/Driver/prefix.c new file mode 100644 index 0000000000000000000000000000000000000000..0590beef26d2f1328daacffc9fdde87ffbfa4abb --- /dev/null +++ b/clang/test/Driver/prefix.c @@ -0,0 +1,10 @@ +// REQUIRES: build_for_openeuler + +// RUN: %clang -v -fgcc-compatible -iwithprefix include %s +// RUN: %clang -v -fgcc-compatible -nostdinc -iwithprefix include %s +// RUN: %clang -v -fgcc-compatible %s + +#include +int main(void) { +return 0; +} diff --git a/debug b/debug new file mode 100644 index 0000000000000000000000000000000000000000..11a6fadbeca8842ff05cabbcab1b82ae0314023e --- /dev/null +++ b/debug @@ -0,0 +1,20 @@ + + // Add -iprefix/-iwithprefix/-iwithprefixbefore options. + StringRef Prefix = ""; // FIXME: This isn't the correct default prefix. + bool iprefixEmpty = true; + for (const auto *A : + Args.filtered(OPT_iprefix, OPT_iwithprefix, OPT_iwithprefixbefore)) { + if (A->getOption().matches(OPT_iprefix)) { + Prefix = A->getValue(); + iprefixEmpty = false; + } else if (A->getOption().matches(OPT_iwithprefix)) { + if (Args.hasFlag(options::OPT_fgcc_compatible, options::OPT_fno_gcc_compatible, false) && iprefixEmpty) { + SmallString<256> path; + llvm::sys::path::append(path, Opts.ResourceDir, A->getValue()); + Opts.AddPath(path, frontend::Angled, false, true); + } else { + Opts.AddPath(Prefix.str() + A->getValue(), frontend::After, false, true); + } + } else + Opts.AddPath(Prefix.str() + A->getValue(), frontend::Angled, false, true); + } \ No newline at end of file