Skip to content

Commit 28d68fc

Browse files
committed
fix the scope for methods on classes
Signed-off-by: Jade Abraham <[email protected]>
1 parent 1f6a96e commit 28d68fc

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

compiler/llvm/llvmDebug.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static std::pair<llvm::DIType*, int>
178178
removePointersAndQualifiers(llvm::DIType* N, int numLevels = -1) {
179179
auto res = N;
180180
int count = 0;
181-
while (llvm::isa<llvm::DIDerivedType>(res) &&
181+
while (res && llvm::isa<llvm::DIDerivedType>(res) &&
182182
(numLevels < 0 || count < numLevels)) {
183183
auto derived = llvm::cast<llvm::DIDerivedType>(res);
184184
res = derived->getBaseType();
@@ -1276,10 +1276,18 @@ llvm::DISubprogram* DebugData::constructFunction(FnSymbol* function) {
12761276
Symbol* scopeSym = isMethod ?
12771277
methodReceiverType->symbol :
12781278
(Symbol*)modSym;
1279-
llvm::DIScope* diScope =
1280-
isMethod ?
1281-
(llvm::DIScope*)getType(methodReceiverType) :
1282-
(llvm::DIScope*)getModuleScope(modSym);
1279+
llvm::DIScope* diScope = nullptr;
1280+
if (isMethod) {
1281+
auto scopeTy = getType(methodReceiverType);
1282+
diScope = std::get<0>(removePointersAndQualifiers(scopeTy));
1283+
if (scopeTy && !diScope) {
1284+
// couldn't find a base type, this can happen with something like c_ptr(void)
1285+
// for now, just use the ptr type itself
1286+
diScope = scopeTy;
1287+
}
1288+
} else {
1289+
diScope = getModuleScope(modSym);
1290+
}
12831291
DefinitionInfo defInfo(diScope,
12841292
getFile(DIB, function->fname()),
12851293
function->linenum());

0 commit comments

Comments
 (0)