/// @{
/// \brief Get the compilation directory for DW_AT_comp_dir
- /// This can be overridden by clients which want to control the reported
- /// compilation directory and have it be something other than the current
- /// working directory.
- /// Returns an empty string if the current directory cannot be determined.
+ /// The compilation directory should be set with \c setCompilationDir before
+ /// calling this function. If it is unset, an empty string will be returned.
StringRef getCompilationDir() const { return CompilationDir; }
/// \brief Set the compilation directory for DW_AT_comp_dir
- /// Override the default (CWD) compilation directory.
void setCompilationDir(StringRef S) { CompilationDir = S.str(); }
/// \brief Get the main file name for use in error messages and debug
GenDwarfForAssembly(false), GenDwarfFileNumber(0), DwarfVersion(4),
AllowTemporaryLabels(true), DwarfCompileUnitID(0),
AutoReset(DoAutoReset), HadError(false) {
-
- std::error_code EC = llvm::sys::fs::current_path(CompilationDir);
- if (EC)
- CompilationDir.clear();
-
SecureLogFile = getenv("AS_SECURE_LOG_FILE");
SecureLog = nullptr;
SecureLogUsed = false;
Ctx.setDwarfDebugProducer(StringRef(DwarfDebugProducer));
if (!DebugCompilationDir.empty())
Ctx.setCompilationDir(DebugCompilationDir);
+ else {
+ // If no compilation dir is set, try to use the current directory.
+ SmallString<128> CWD;
+ if (!sys::fs::current_path(CWD))
+ Ctx.setCompilationDir(CWD);
+ }
if (!MainFileName.empty())
Ctx.setMainFileName(MainFileName);