@@ -178,7 +178,7 @@ static std::pair<llvm::DIType*, int>
178178removePointersAndQualifiers (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