From 60c9ad34be6e88bb4d8cc252f32ef45a9290ee08 Mon Sep 17 00:00:00 2001 From: s30032676 Date: Wed, 6 Nov 2024 10:50:37 +0800 Subject: [PATCH] [libcbs2c] bugfix for add default include path for bsc_include2c When compiling a c file, the default include path of bsc_inlude2c didn`t work. So this commit fixs this bug, by add a new function named "AddClangBSC2cSystemIncludeArgs". This function mainly adds the path of bsc_include2c to system include, so that users don`t have to include files in bsc_include2c manually. And this commit also add some new logic to call this function. --- clang/include/clang/Driver/ToolChain.h | 4 ++++ clang/lib/Driver/ToolChain.cpp | 5 +++++ clang/lib/Driver/ToolChains/Clang.cpp | 5 +++++ clang/lib/Driver/ToolChains/Linux.cpp | 11 ++++++++--- clang/lib/Driver/ToolChains/Linux.h | 4 ++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 3ec8c682cc88..978c83d3806a 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -625,6 +625,10 @@ public: AddClangBSCSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const; #endif + + virtual void + AddClangBSC2cSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const; /// Add options that need to be passed to cc1 for this target. virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index b9761bf19990..a831dd9ffdcb 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -808,6 +808,11 @@ void ToolChain::AddClangBSCSystemIncludeArgs(const ArgList &DriverArgs, } #endif +void ToolChain::AddClangBSC2cSystemIncludeArgs(const ArgList &DriverArgs, + ArgStringList &CC1Args) const { + // Each toolchain should provide the appropriate include flags. +} + void ToolChain::addClangTargetOptions( const ArgList &DriverArgs, ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const {} diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 7e8700e1399b..c9ad2912b0dc 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1486,6 +1486,11 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, } #endif + forAllAssociatedToolChains(C, JA, getToolChain(), + [&Args, &CmdArgs](const ToolChain &TC) { + TC.AddClangBSC2cSystemIncludeArgs(Args, CmdArgs); + }); + // Add system include arguments for all targets but IAMCU. if (!IsIAMCU) forAllAssociatedToolChains(C, JA, getToolChain(), diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index 45c94c2da8ee..773ae3724f21 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -571,14 +571,19 @@ void Linux::AddClangBSCSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { const Driver &D = getDriver(); SmallString<128> ResourceDirBSCInclude(D.ResourceDir); - SmallString<128> ResourceDirBSCInclude2c(D.ResourceDir); llvm::sys::path::append(ResourceDirBSCInclude, "include/bsc_include"); - llvm::sys::path::append(ResourceDirBSCInclude2c, "include/bsc_include/bsc_include2c"); addSystemInclude(DriverArgs, CC1Args, ResourceDirBSCInclude); - addSystemInclude(DriverArgs, CC1Args, ResourceDirBSCInclude2c); } #endif +void Linux::AddClangBSC2cSystemIncludeArgs(const ArgList &DriverArgs, + ArgStringList &CC1Args) const { + const Driver &D = getDriver(); + SmallString<128> ResourceDirBSCInclude2c(D.ResourceDir); + llvm::sys::path::append(ResourceDirBSCInclude2c, "include/bsc_include/bsc_include2c"); + addSystemInclude(DriverArgs, CC1Args, ResourceDirBSCInclude2c); +} + void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { const Driver &D = getDriver(); diff --git a/clang/lib/Driver/ToolChains/Linux.h b/clang/lib/Driver/ToolChains/Linux.h index cac32ce94690..9ed60520b807 100644 --- a/clang/lib/Driver/ToolChains/Linux.h +++ b/clang/lib/Driver/ToolChains/Linux.h @@ -37,6 +37,10 @@ public: llvm::opt::ArgStringList &CC1Args) const override; #endif + void + AddClangBSC2cSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; + void addLibStdCxxIncludePaths( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; -- Gitee