From 97b5655fa821aba307b6b6027d87d675f221cbc8 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Mon, 12 Dec 2016 07:53:47 +0000 Subject: [PATCH] [Driver] Simplify ToolChain::GetCXXStdlibType (NFC) I made the wrong assumption that execution would continue after an error Diag which led to unneeded complex code. This patch aligns with the better implementation of ToolChain::GetRuntimeLibType. Differential Revision: https://reviews.llvm.org/D25669 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@289422 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChain.cpp | 47 +++++++++++----------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp index 5c6d062583..90eaff12a5 100644 --- a/lib/Driver/ToolChain.cpp +++ b/lib/Driver/ToolChain.cpp @@ -542,7 +542,7 @@ ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType( const Arg* A = Args.getLastArg(options::OPT_rtlib_EQ); StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_RTLIB; - // "platform" is only used in tests to override CLANG_DEFAULT_RTLIB + // Only use "platform" in tests to override CLANG_DEFAULT_RTLIB! if (LibName == "compiler-rt") return ToolChain::RLT_CompilerRT; else if (LibName == "libgcc") @@ -556,43 +556,22 @@ ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType( return GetDefaultRuntimeLibType(); } -static bool ParseCXXStdlibType(const StringRef& Name, - ToolChain::CXXStdlibType& Type) { - if (Name == "libc++") - Type = ToolChain::CST_Libcxx; - else if (Name == "libstdc++") - Type = ToolChain::CST_Libstdcxx; - else - return false; - - return true; -} - ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{ - ToolChain::CXXStdlibType Type; - bool HasValidType = false; - bool ForcePlatformDefault = false; - const Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); - if (A) { - StringRef Value = A->getValue(); - HasValidType = ParseCXXStdlibType(Value, Type); - - // Only use in tests to override CLANG_DEFAULT_CXX_STDLIB! - if (Value == "platform") - ForcePlatformDefault = true; - else if (!HasValidType) - getDriver().Diag(diag::err_drv_invalid_stdlib_name) - << A->getAsString(Args); - } + StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_CXX_STDLIB; - // If no argument was provided or its value was invalid, look for the - // default unless forced or configured to take the platform default. - if (!HasValidType && (ForcePlatformDefault || - !ParseCXXStdlibType(CLANG_DEFAULT_CXX_STDLIB, Type))) - Type = GetDefaultCXXStdlibType(); + // Only use "platform" in tests to override CLANG_DEFAULT_CXX_STDLIB! + if (LibName == "libc++") + return ToolChain::CST_Libcxx; + else if (LibName == "libstdc++") + return ToolChain::CST_Libstdcxx; + else if (LibName == "platform") + return GetDefaultCXXStdlibType(); + + if (A) + getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args); - return Type; + return GetDefaultCXXStdlibType(); } /// \brief Utility function to add a system include directory to CC1 arguments. -- 2.50.1