diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -220,7 +220,11 @@ SystemConfigDir = CLANG_CONFIG_FILE_SYSTEM_DIR; #endif #if defined(CLANG_CONFIG_FILE_USER_DIR) - UserConfigDir = CLANG_CONFIG_FILE_USER_DIR; + { + SmallString<128> P; + llvm::sys::fs::expand_tilde(CLANG_CONFIG_FILE_USER_DIR, P); + UserConfigDir = static_cast(P); + } #endif // Compute the path to the resource directory. @@ -1008,8 +1012,8 @@ } if (CLOptions->hasArg(options::OPT_config_user_dir_EQ)) { SmallString<128> CfgDir; - CfgDir.append( - CLOptions->getLastArgValue(options::OPT_config_user_dir_EQ)); + llvm::sys::fs::expand_tilde( + CLOptions->getLastArgValue(options::OPT_config_user_dir_EQ), CfgDir); if (CfgDir.empty() || getVFS().makeAbsolute(CfgDir)) UserConfigDir.clear(); else diff --git a/clang/test/Driver/config-file3.c b/clang/test/Driver/config-file3.c --- a/clang/test/Driver/config-file3.c +++ b/clang/test/Driver/config-file3.c @@ -221,3 +221,8 @@ // // RUN: rm %t/testdmode/clang-g++.cfg // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix NO-CONFIG + +//--- Tilde expansion in user configuration file directory +// +// RUN: HOME=%S/Inputs/config %clang --config-user-dir=~ -v 2>&1 | FileCheck %s -check-prefix CHECK-TILDE +// CHECK-TILDE: User configuration file directory: {{.*}}/Inputs/config