This is an archive of the discontinued LLVM Phabricator instance.

Sema: avoid reuse of Exprs when synthesizing operator=
ClosedPublic

Authored by labath on Aug 16 2013, 9:14 AM.

Details

Summary

Previously, Sema was reusing parts of the AST when synthesizing an assignment
operator, turning it into a AS-dag. This caused problems for the static
analyzer, which assumed an expression appears in the tree only once.

Here I make sure to always create a fresh Expr, when inserting something into
the AST, fixing PR16745 in the process.

Diff Detail

Event Timeline

klimek added inline comments.Aug 27 2013, 1:37 AM
lib/Sema/SemaDeclCXX.cpp
8477

I personally find a class structure easier to understand that goes from public: over protected: to private:, and has methods ordered from most important to know for a user of the class to least important, as that aids the common top-down reading flow.

This file is inconsistent regarding this style question, so I punt to doug for judgement ;)

8489

s/cannot/must not/
Also, I'd probably pull the asserts out of this method. It inserts some duplication, but it also simplifies this class hierarchy.

8498–8502

I think at some point the reduction in duplication gets outweighed by the increase in structural overhead. This might be a different call if not all implementations were here in the .cc file, but in this case I'd just have the Build method on the interface and have an implementation on each class. If you want to pull out common code, I'd put helpers into the base class.

8837–8845

I'd s/Idx/Index/

8841

That cast seems wrong. Please try to reformulate without the cast. Use pointers if necessary.

labath updated this revision to Unknown Object (????).Aug 27 2013, 2:57 AM
  • Minor refactoring to adress Manuel's comments
lib/Sema/SemaDeclCXX.cpp
8477

Ok, I'm leaving the members in the present order for now.

8489

I've put the assertion into a helper method.

8498–8502

I've removed this intermediate class.

8837–8845

Usage of "Index" seems to be more common in this file, replaced.

8841

Reformulated.

Apart from the backwards-layout of classes (which makes it hard to read for me) makes sense. Needs review from Richard or Doug for domain knowledge...

Seems fine to me.

lib/Sema/SemaDeclCXX.cpp
8479

No space between operator and =

labath closed this revision.Aug 30 2013, 1:55 AM

Closed by commit rL189659 (authored by @labath).