Add a comment about the DIDescriptor class hierarchy.
authorAdrian Prantl <aprantl@apple.com>
Tue, 1 Apr 2014 21:04:24 +0000 (21:04 +0000)
committerAdrian Prantl <aprantl@apple.com>
Tue, 1 Apr 2014 21:04:24 +0000 (21:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205358 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/DebugInfo.h
lib/IR/DebugInfo.cpp

index 69beaada9c31e69a449dbf746a518eac80713747..bf3ae983817c92302609d30165c0df1bcf726590 100644 (file)
@@ -197,6 +197,13 @@ typedef DIRef<DIScope> DIScopeRef;
 typedef DIRef<DIType> DITypeRef;
 
 /// DIScope - A base class for various scopes.
+///
+/// Although, implementation-wise, DIScope is the parent class of most
+/// other DIxxx classes, including DIType and its descendants, most of
+/// DIScope’s descendants are not a substitutable subtype of
+/// DIScope. The DIDescriptor::isScope() method only is true for
+/// DIScopes that are scopes in the strict lexical scope sense
+/// (DICompileUnit, DISubprogram, etc.), but not for, e.g., a DIType.
 class DIScope : public DIDescriptor {
 protected:
   friend class DIDescriptor;
index f9bc63b389e2b0074ba6364ace757fd91945c0aa..c9d68afa445f2c7cd9c03706b802112e25d43127 100644 (file)
@@ -429,8 +429,10 @@ static bool fieldIsTypeRef(const MDNode *DbgNode, unsigned Elt) {
 /// Check if a value can be a ScopeRef.
 static bool isScopeRef(const Value *Val) {
   return !Val ||
-         (isa<MDString>(Val) && !cast<MDString>(Val)->getString().empty()) ||
-         isa<MDNode>(Val);
+    (isa<MDString>(Val) && !cast<MDString>(Val)->getString().empty()) ||
+    // Not checking for Val->isScope() here, because it would work
+    // only for lexical scopes and not all subclasses of DIScope.
+    isa<MDNode>(Val);
 }
 
 /// Check if a field at position Elt of a MDNode can be a ScopeRef.