[llvm] [TableGen] Rework error reporting for duplicate Feature/Processor. (PR #102257)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 7 11:00:34 PDT 2024
jurahul wrote:
> > Could you use line number as the tie breaker in the sort?
>
> I did look into whether I can order them by `SMLoc` but did not find a way. Let me take a closer look.
It seems this works:
```
auto GetSourceLocation = [](const Record *Rec) {
const SMLoc Loc = Rec->getLoc()[0];
const MemoryBuffer *MB =
SrcMgr.getMemoryBuffer(SrcMgr.FindBufferContainingLoc(Loc));
StringRef BufferID = MB->getBufferIdentifier();
auto LineAndCol = SrcMgr.getLineAndColumn(Loc);
return std::tuple(BufferID, LineAndCol.first, LineAndCol.second);
};
// Order First/Second by their lexical order if possible. Note that if they
// are from different files, they will be ordered by file names.
if (GetSourceLocation(First) > GetSourceLocation(Second))
std::swap(First, Second);
```
right before printing the error message. It's still not foolproof since it uses filename as the first key, so if fileA included fileB, I am assuming it will think fileA is the earlier def and one in fileB is second, so I am still keeping the message position ambiguous. The !/$ for getting this fully correct is not there. I'll update the PR soon.
https://github.com/llvm/llvm-project/pull/102257
More information about the llvm-commits
mailing list