From d6629b3db8a731259c8f6de12c6df79bf079d2a4 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Thu, 16 Apr 2015 16:56:29 +0000 Subject: [PATCH] DebugInfo: Allow DebugLocs to be constructed from const Allow `const`-qualified pointers to be used to construct `DebugLoc`s, as a convenience. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235115 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/DebugLoc.h | 8 ++++---- lib/IR/DebugLoc.cpp | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/llvm/IR/DebugLoc.h b/include/llvm/IR/DebugLoc.h index 365860fd877..f88a7b156b2 100644 --- a/include/llvm/IR/DebugLoc.h +++ b/include/llvm/IR/DebugLoc.h @@ -48,7 +48,7 @@ namespace llvm { } /// \brief Construct from an \a MDLocation. - DebugLoc(MDLocation *L); + DebugLoc(const MDLocation *L); /// \brief Construct from an \a MDNode. /// @@ -56,7 +56,7 @@ namespace llvm { /// accessors will crash. However, construction from other nodes is /// supported in order to handle forward references when reading textual /// IR. - explicit DebugLoc(MDNode *N); + explicit DebugLoc(const MDNode *N); /// \brief Get the underlying \a MDLocation. /// @@ -87,8 +87,8 @@ namespace llvm { /// If \c !Scope, returns a default-constructed \a DebugLoc. /// /// FIXME: Remove this. Users should use MDLocation::get(). - static DebugLoc get(unsigned Line, unsigned Col, MDNode *Scope, - MDNode *InlinedAt = nullptr); + static DebugLoc get(unsigned Line, unsigned Col, const MDNode *Scope, + const MDNode *InlinedAt = nullptr); unsigned getLine() const; unsigned getCol() const; diff --git a/lib/IR/DebugLoc.cpp b/lib/IR/DebugLoc.cpp index d9229483d05..4cf7e9e34e1 100644 --- a/lib/IR/DebugLoc.cpp +++ b/lib/IR/DebugLoc.cpp @@ -16,8 +16,8 @@ using namespace llvm; //===----------------------------------------------------------------------===// // DebugLoc Implementation //===----------------------------------------------------------------------===// -DebugLoc::DebugLoc(MDLocation *L) : Loc(L) {} -DebugLoc::DebugLoc(MDNode *L) : Loc(L) {} +DebugLoc::DebugLoc(const MDLocation *L) : Loc(const_cast(L)) {} +DebugLoc::DebugLoc(const MDNode *L) : Loc(const_cast(L)) {} MDLocation *DebugLoc::get() const { return cast_or_null(Loc.get()); @@ -56,13 +56,15 @@ DebugLoc DebugLoc::getFnDebugLoc() const { return DebugLoc(); } -DebugLoc DebugLoc::get(unsigned Line, unsigned Col, - MDNode *Scope, MDNode *InlinedAt) { +DebugLoc DebugLoc::get(unsigned Line, unsigned Col, const MDNode *Scope, + const MDNode *InlinedAt) { // If no scope is available, this is an unknown location. if (!Scope) return DebugLoc(); - return MDLocation::get(Scope->getContext(), Line, Col, Scope, InlinedAt); + return MDLocation::get(Scope->getContext(), Line, Col, + const_cast(Scope), + const_cast(InlinedAt)); } void DebugLoc::dump() const {