MaskRay created this revision. MaskRay added reviewers: debug-info, aprantl, dblaikie, rjmccall. MaskRay requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
getLineNumber() picks CurLoc if the parameter is invalid. This appears to mainly work around missing SourceLocation information for some ObjC constructs. Drop the special case and add CurLoc fallback in its callers instead. As an example, `ObjCMethodDecl::createImplicitParams` uses `SourceLocation()`. Changing it to a more relevant SourceLocation (e.g. the method's location) will cause updates to a few other Sema/AST tests. This may be worth a further investigation. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D94391 Files: clang/lib/CodeGen/CGDebugInfo.cpp Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -493,11 +493,10 @@ } unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) { - if (Loc.isInvalid() && CurLoc.isInvalid()) + if (Loc.isInvalid()) return 0; SourceManager &SM = CGM.getContext().getSourceManager(); - PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc); - return PLoc.isValid() ? PLoc.getLine() : 0; + return SM.getPresumedLoc(Loc).getLine(); } unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc, bool Force) { @@ -1358,7 +1357,7 @@ // Get the location for the field. llvm::DIFile *file = getOrCreateFile(loc); - unsigned line = getLineNumber(loc); + const unsigned line = getLineNumber(loc.isValid() ? loc : CurLoc); uint64_t SizeInBits = 0; auto Align = AlignInBits; @@ -3336,7 +3335,8 @@ // Get overall information about the record type for the debug info. llvm::DIFile *DefUnit = getOrCreateFile(RD->getLocation()); - unsigned Line = getLineNumber(RD->getLocation()); + const unsigned Line = + getLineNumber(RD->getLocation().isValid() ? RD->getLocation() : CurLoc); StringRef RDName = getClassName(RD); llvm::DIScope *RDContext = getDeclContextDescriptor(RD); @@ -3865,7 +3865,7 @@ llvm::DISubprogram::DISPFlags SPFlagsForDef = SPFlags | llvm::DISubprogram::SPFlagDefinition; - unsigned LineNo = getLineNumber(Loc); + const unsigned LineNo = getLineNumber(Loc.isValid() ? Loc : CurLoc); unsigned ScopeLine = getLineNumber(ScopeLoc); llvm::DISubroutineType *DIFnType = getOrCreateFunctionType(D, FnType, Unit); llvm::DISubprogram *Decl = nullptr; @@ -4368,7 +4368,8 @@ Ty = CreateSelfType(VD->getType(), Ty); // Get location information. - unsigned Line = getLineNumber(VD->getLocation()); + const unsigned Line = + getLineNumber(VD->getLocation().isValid() ? VD->getLocation() : CurLoc); unsigned Column = getColumnNumber(VD->getLocation()); const llvm::DataLayout &target = CGM.getDataLayout(); @@ -4828,6 +4829,8 @@ if (!NSDecl->isAnonymousNamespace() || CGM.getCodeGenOpts().DebugExplicitImport) { auto Loc = UD.getLocation(); + if (!Loc.isValid()) + Loc = CurLoc; DBuilder.createImportedModule( getCurrentContextDescriptor(cast<Decl>(UD.getDeclContext())), getOrCreateNamespace(NSDecl), getOrCreateFile(Loc), getLineNumber(Loc));
Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -493,11 +493,10 @@ } unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) { - if (Loc.isInvalid() && CurLoc.isInvalid()) + if (Loc.isInvalid()) return 0; SourceManager &SM = CGM.getContext().getSourceManager(); - PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc); - return PLoc.isValid() ? PLoc.getLine() : 0; + return SM.getPresumedLoc(Loc).getLine(); } unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc, bool Force) { @@ -1358,7 +1357,7 @@ // Get the location for the field. llvm::DIFile *file = getOrCreateFile(loc); - unsigned line = getLineNumber(loc); + const unsigned line = getLineNumber(loc.isValid() ? loc : CurLoc); uint64_t SizeInBits = 0; auto Align = AlignInBits; @@ -3336,7 +3335,8 @@ // Get overall information about the record type for the debug info. llvm::DIFile *DefUnit = getOrCreateFile(RD->getLocation()); - unsigned Line = getLineNumber(RD->getLocation()); + const unsigned Line = + getLineNumber(RD->getLocation().isValid() ? RD->getLocation() : CurLoc); StringRef RDName = getClassName(RD); llvm::DIScope *RDContext = getDeclContextDescriptor(RD); @@ -3865,7 +3865,7 @@ llvm::DISubprogram::DISPFlags SPFlagsForDef = SPFlags | llvm::DISubprogram::SPFlagDefinition; - unsigned LineNo = getLineNumber(Loc); + const unsigned LineNo = getLineNumber(Loc.isValid() ? Loc : CurLoc); unsigned ScopeLine = getLineNumber(ScopeLoc); llvm::DISubroutineType *DIFnType = getOrCreateFunctionType(D, FnType, Unit); llvm::DISubprogram *Decl = nullptr; @@ -4368,7 +4368,8 @@ Ty = CreateSelfType(VD->getType(), Ty); // Get location information. - unsigned Line = getLineNumber(VD->getLocation()); + const unsigned Line = + getLineNumber(VD->getLocation().isValid() ? VD->getLocation() : CurLoc); unsigned Column = getColumnNumber(VD->getLocation()); const llvm::DataLayout &target = CGM.getDataLayout(); @@ -4828,6 +4829,8 @@ if (!NSDecl->isAnonymousNamespace() || CGM.getCodeGenOpts().DebugExplicitImport) { auto Loc = UD.getLocation(); + if (!Loc.isValid()) + Loc = CurLoc; DBuilder.createImportedModule( getCurrentContextDescriptor(cast<Decl>(UD.getDeclContext())), getOrCreateNamespace(NSDecl), getOrCreateFile(Loc), getLineNumber(Loc));
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits