From 0f873eb80ad4c4d850ef18a4b591391541fcf97d Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Mon, 3 Dec 2018 17:55:29 +0000 Subject: [PATCH] Update Diagnostic handling for changes in CFE. The clang frontend no longer emits the current working directory for DIFiles containing an absolute path in the filename: and will move the common prefix between current working directory and the file into the directory: component. https://reviews.llvm.org/D55085 llvm-svn: 348155 --- llvm/include/llvm/IR/DiagnosticInfo.h | 17 +++++++--- llvm/lib/IR/DiagnosticInfo.cpp | 38 ++++++++++++++++------- llvm/test/CodeGen/AMDGPU/vi-removed-intrinsics.ll | 2 +- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h index b8fdae2..e98ab29 100644 --- a/llvm/include/llvm/IR/DiagnosticInfo.h +++ b/llvm/include/llvm/IR/DiagnosticInfo.h @@ -340,7 +340,7 @@ private: }; class DiagnosticLocation { - StringRef Filename; + DIFile *File = nullptr; unsigned Line = 0; unsigned Column = 0; @@ -349,8 +349,11 @@ public: DiagnosticLocation(const DebugLoc &DL); DiagnosticLocation(const DISubprogram *SP); - bool isValid() const { return !Filename.empty(); } - StringRef getFilename() const { return Filename; } + bool isValid() const { return File; } + /// Return the full path to the file. + std::string getAbsolutePath() const; + /// Return the file name relative to the compilation directory. + StringRef getRelativePath() const { return File->getFilename(); } unsigned getLine() const { return Line; } unsigned getColumn() const { return Column; } }; @@ -375,9 +378,13 @@ public: const std::string getLocationStr() const; /// Return location information for this diagnostic in three parts: - /// the source file name, line number and column. - void getLocation(StringRef *Filename, unsigned *Line, unsigned *Column) const; + /// the relative source file path, line number and column. + void getLocation(StringRef &RelativePath, unsigned &Line, + unsigned &Column) const; + /// Return the absolute path tot the file. + std::string getAbsolutePath() const; + const Function &getFunction() const { return Fn; } DiagnosticLocation getLocation() const { return Loc; } diff --git a/llvm/lib/IR/DiagnosticInfo.cpp b/llvm/lib/IR/DiagnosticInfo.cpp index 5ddb119..fc6f5f1 100644 --- a/llvm/lib/IR/DiagnosticInfo.cpp +++ b/llvm/lib/IR/DiagnosticInfo.cpp @@ -33,9 +33,10 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/Path.h" #include "llvm/Support/Regex.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/ScopedPrinter.h" +#include "llvm/Support/raw_ostream.h" #include #include #include @@ -106,7 +107,7 @@ void DiagnosticInfoPGOProfile::print(DiagnosticPrinter &DP) const { DiagnosticLocation::DiagnosticLocation(const DebugLoc &DL) { if (!DL) return; - Filename = DL->getFilename(); + File = DL->getFile(); Line = DL->getLine(); Column = DL->getColumn(); } @@ -114,17 +115,32 @@ DiagnosticLocation::DiagnosticLocation(const DebugLoc &DL) { DiagnosticLocation::DiagnosticLocation(const DISubprogram *SP) { if (!SP) return; - Filename = SP->getFilename(); + + File = SP->getFile(); Line = SP->getScopeLine(); Column = 0; } -void DiagnosticInfoWithLocationBase::getLocation(StringRef *Filename, - unsigned *Line, - unsigned *Column) const { - *Filename = Loc.getFilename(); - *Line = Loc.getLine(); - *Column = Loc.getColumn(); +std::string DiagnosticLocation::getAbsolutePath() const { + StringRef Name = File->getFilename(); + if (sys::path::is_absolute(Name)) + return Name; + + SmallString<128> Path; + sys::path::append(Path, File->getDirectory(), Name); + return sys::path::remove_leading_dotslash(Path).str(); +} + +std::string DiagnosticInfoWithLocationBase::getAbsolutePath() const { + return Loc.getAbsolutePath(); +} + +void DiagnosticInfoWithLocationBase::getLocation(StringRef &RelativePath, + unsigned &Line, + unsigned &Column) const { + RelativePath = Loc.getRelativePath(); + Line = Loc.getLine(); + Column = Loc.getColumn(); } const std::string DiagnosticInfoWithLocationBase::getLocationStr() const { @@ -132,7 +148,7 @@ const std::string DiagnosticInfoWithLocationBase::getLocationStr() const { unsigned Line = 0; unsigned Column = 0; if (isLocationAvailable()) - getLocation(&Filename, &Line, &Column); + getLocation(Filename, Line, Column); return (Filename + ":" + Twine(Line) + ":" + Twine(Column)).str(); } @@ -399,7 +415,7 @@ template <> struct MappingTraits { static void mapping(IO &io, DiagnosticLocation &DL) { assert(io.outputting() && "input not yet implemented"); - StringRef File = DL.getFilename(); + StringRef File = DL.getRelativePath(); unsigned Line = DL.getLine(); unsigned Col = DL.getColumn(); diff --git a/llvm/test/CodeGen/AMDGPU/vi-removed-intrinsics.ll b/llvm/test/CodeGen/AMDGPU/vi-removed-intrinsics.ll index 8d66c34..d6b3f03 100644 --- a/llvm/test/CodeGen/AMDGPU/vi-removed-intrinsics.ll +++ b/llvm/test/CodeGen/AMDGPU/vi-removed-intrinsics.ll @@ -17,7 +17,7 @@ attributes #1 = { nounwind } !llvm.module.flags = !{!2, !3} !0 = distinct !DICompileUnit(language: DW_LANG_OpenCL, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug) -!1 = !DIFile(filename: "foo.cl", directory: "/dev/null") +!1 = !DIFile(filename: "foo.cl", directory: ".") !2 = !{i32 2, !"Dwarf Version", i32 4} !3 = !{i32 2, !"Debug Info Version", i32 3} !4 = !DILocation(line: 1, column: 42, scope: !5) -- 2.7.4