[PATCH] D105495: [clang] Make negative getLocWithOffset widening-safe.
Simon Tatham via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 27 02:50:30 PDT 2021
simon_tatham updated this revision to Diff 361957.
simon_tatham edited the summary of this revision.
simon_tatham added a comment.
In D105495#2882628 <https://reviews.llvm.org/D105495#2882628>, @tmatheson wrote:
> I also think it's the caller's responsibility to make sure what they pass in is correctly signed.
I don't disagree with that in principle, but in a case like this, where the error is extremely easy to make, not warned about at compile time (so you have to exercise the failing code path to spot it), and won't even show up at //runtime// in the default build configuration (even once 64-bit SourceLocations are actually implemented, the current plan is for them to be off by default), I think it's worth at least //trying// to think of ways to help the caller get it right.
Perhaps an alternative API might be to replace `SourceLocation::getLocWithOffset` with an `operator+`, and add an `operator-` to go with it? Then you could write `NewLoc = OldLoc + ThisInteger - ThatInteger` and each integer would be implicitly widened if it was the wrong size.
But in this version of the patch, I haven't done that; I've just reverted the introduction of dyadic `getLocWithOffset` and added cumbersome casts or intermediate variables at the call sites where I'd previously used it.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105495/new/
https://reviews.llvm.org/D105495
Files:
clang/lib/AST/SelectorLocationsKind.cpp
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Lex/Lexer.cpp
clang/lib/Parse/ParseStmtAsm.cpp
clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105495.361957.patch
Type: text/x-patch
Size: 5826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210727/3d392238/attachment-0001.bin>
More information about the cfe-commits
mailing list