From 2f1e34736e4f14c57d1c1fdcfc8b9e133c4885d9 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Tue, 1 Apr 2014 21:04:24 +0000 Subject: [PATCH] Add a comment about the DIDescriptor class hierarchy. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205358 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/DebugInfo.h | 7 +++++++ lib/IR/DebugInfo.cpp | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/llvm/IR/DebugInfo.h b/include/llvm/IR/DebugInfo.h index 69beaada9c3..bf3ae983817 100644 --- a/include/llvm/IR/DebugInfo.h +++ b/include/llvm/IR/DebugInfo.h @@ -197,6 +197,13 @@ typedef DIRef DIScopeRef; typedef DIRef 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; diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index f9bc63b389e..c9d68afa445 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -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(Val) && !cast(Val)->getString().empty()) || - isa(Val); + (isa(Val) && !cast(Val)->getString().empty()) || + // Not checking for Val->isScope() here, because it would work + // only for lexical scopes and not all subclasses of DIScope. + isa(Val); } /// Check if a field at position Elt of a MDNode can be a ScopeRef. -- 2.11.0