DbgIntrinsicInst: Downcast to specialized MDNodes in accessors
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sun, 15 Mar 2015 01:23:20 +0000 (01:23 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sun, 15 Mar 2015 01:23:20 +0000 (01:23 +0000)
Change accessors to downcast to `MDLocalVariable` and `MDExpression`,
now that we have -verify checks in place to confirm that it's safe.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232299 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/IntrinsicInst.h
include/llvm/IR/Metadata.h
lib/IR/Verifier.cpp

index 72ab46d8af9abf5ac0cbdd017ee70cb7fcbf7ff8..bf0adc3934776beba3278f604e701d23dbbbbf1d 100644 (file)
@@ -82,8 +82,12 @@ namespace llvm {
   class DbgDeclareInst : public DbgInfoIntrinsic {
   public:
     Value *getAddress() const;
-    MDNode *getVariable() const { return cast<MDNode>(getRawVariable()); }
-    MDNode *getExpression() const { return cast<MDNode>(getRawExpression()); }
+    MDLocalVariable *getVariable() const {
+      return cast<MDLocalVariable>(getRawVariable());
+    }
+    MDExpression *getExpression() const {
+      return cast<MDExpression>(getRawExpression());
+    }
 
     Metadata *getRawVariable() const {
       return cast<MetadataAsValue>(getArgOperand(1))->getMetadata();
@@ -111,8 +115,12 @@ namespace llvm {
       return cast<ConstantInt>(
                           const_cast<Value*>(getArgOperand(1)))->getZExtValue();
     }
-    MDNode *getVariable() const { return cast<MDNode>(getRawVariable()); }
-    MDNode *getExpression() const { return cast<MDNode>(getRawExpression()); }
+    MDLocalVariable *getVariable() const {
+      return cast<MDLocalVariable>(getRawVariable());
+    }
+    MDExpression *getExpression() const {
+      return cast<MDExpression>(getRawExpression());
+    }
 
     Metadata *getRawVariable() const {
       return cast<MetadataAsValue>(getArgOperand(2))->getMetadata();
index c01cc7c92eef0b028b99739b008b65501b9f3d62..6ba0fd4173004670c02a60d3d7ad8729754ecdc8 100644 (file)
@@ -128,6 +128,16 @@ public:
 #define HANDLE_METADATA(CLASS) class CLASS;
 #include "llvm/IR/Metadata.def"
 
+// Provide specializations of isa so that we don't need definitions of
+// subclasses to see if the metadata is a subclass.
+#define HANDLE_METADATA_LEAF(CLASS)                                            \
+  template <> struct isa_impl<CLASS, Metadata> {                               \
+    static inline bool doit(const Metadata &MD) {                              \
+      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
+    }                                                                          \
+  };
+#include "llvm/IR/Metadata.def"
+
 inline raw_ostream &operator<<(raw_ostream &OS, const Metadata &MD) {
   MD.print(OS);
   return OS;
index f0071060276e3d427c36cbcaf28a493fbbe83107..084bfb81a97f2ee0d92b41df646e502e00e2e25d 100644 (file)
@@ -3032,8 +3032,8 @@ void Verifier::visitDbgIntrinsic(StringRef Kind, DbgIntrinsicTy &DII) {
          DII.getRawExpression());
 
   // Don't call visitMDNode(), since that will recurse through operands.
-  visitMDLocalVariable(*cast<MDLocalVariable>(DII.getVariable()));
-  visitMDExpression(*cast<MDExpression>(DII.getExpression()));
+  visitMDLocalVariable(*DII.getVariable());
+  visitMDExpression(*DII.getExpression());
 }
 
 void DebugInfoVerifier::verifyDebugInfo() {