[llvm-dev] DenseMap/ValueMap: is M[New]=M[Old] valid ?
via llvm-dev
llvm-dev at lists.llvm.org
Fri Sep 27 06:39:11 PDT 2019
> -----Original Message-----
> From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of
> Jeroen Dobbelaere via llvm-dev
> Sent: Friday, September 27, 2019 5:46 AM
> To: Martin Storsjö; David Blaikie
> Cc: llvm-dev at lists.llvm.org
> Subject: Re: [llvm-dev] DenseMap/ValueMap: is M[New]=M[Old] valid ?
>
> > From: Martin Storsjö <martin at martin.st>
> [...]
> > It's not a question about when the operands are evaluated - both do
> > evaluate them in the same order. But evaluating the left and right hand
> > side leaves you with two references. Then to do the assignment, you
> > dereference the right hand side reference and assign it to the
> > dereferenced left hand side reference.
> [...]
> > GlobalMap[a] = GlobalMap[b];
> [...]
>
> Is there a checker in clang that can detect this kind of wrong usage ?
I think I've tripped over this construct twice; once when [a] was always
supposed to be there already (but wasn't because of a bug elsewhere), and
another time when [a] was never supposed to be there already (which has
the obvious fix). I doubt a checker would have enough context to tell
those apart, but maybe it could tell you to add an assertion (that [a] is
already present) or break up the assignment.
--paulr
> If not, how hard would it be to write one ?
>
> Greetings,
>
> Jeroen Dobbelaere
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
More information about the llvm-dev
mailing list