[llvm] r235115 - DebugInfo: Allow DebugLocs to be constructed from const

Duncan P. N. Exon Smith dexonsmith at apple.com
Thu Apr 16 09:56:29 PDT 2015


Author: dexonsmith
Date: Thu Apr 16 11:56:29 2015
New Revision: 235115

URL: http://llvm.org/viewvc/llvm-project?rev=235115&view=rev
Log:
DebugInfo: Allow DebugLocs to be constructed from const

Allow `const`-qualified pointers to be used to construct `DebugLoc`s, as
a convenience.

Modified:
    llvm/trunk/include/llvm/IR/DebugLoc.h
    llvm/trunk/lib/IR/DebugLoc.cpp

Modified: llvm/trunk/include/llvm/IR/DebugLoc.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugLoc.h?rev=235115&r1=235114&r2=235115&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugLoc.h (original)
+++ llvm/trunk/include/llvm/IR/DebugLoc.h Thu Apr 16 11:56:29 2015
@@ -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;

Modified: llvm/trunk/lib/IR/DebugLoc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugLoc.cpp?rev=235115&r1=235114&r2=235115&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugLoc.cpp (original)
+++ llvm/trunk/lib/IR/DebugLoc.cpp Thu Apr 16 11:56:29 2015
@@ -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<MDLocation *>(L)) {}
+DebugLoc::DebugLoc(const MDNode *L) : Loc(const_cast<MDNode *>(L)) {}
 
 MDLocation *DebugLoc::get() const {
   return cast_or_null<MDLocation>(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<MDNode *>(Scope),
+                         const_cast<MDNode *>(InlinedAt));
 }
 
 void DebugLoc::dump() const {





More information about the llvm-commits mailing list