This is an archive of the discontinued LLVM Phabricator instance.

[SyntaxTree] Use PointerUnion instead of inheritance for alternative clauses in NNS
AbandonedPublic

Authored by eduucaldas on Jul 28 2020, 11:38 AM.

Details

Reviewers
gribozavr2
Summary

We also fix a crasch on name specifier.

The generation of syntax tree for name specifiers with longer than 1 character identifier crashed. Root cause is that getLocalSourceRange returns a SourceRange that had its end SourceLocation just before the :: in the nested-name-specifier, but we actually expect SourceLocation to be at the start of tokens.

Diff Detail

Event Timeline

eduucaldas created this revision.Jul 28 2020, 11:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 28 2020, 11:38 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
eduucaldas requested review of this revision.Jul 28 2020, 11:38 AM
eduucaldas updated this revision to Diff 283627.Aug 6 2020, 8:51 AM
  • [SyntaxTree] Fix crash on name specifier.

This diff revision is based on https://reviews.llvm.org/D84348

eduucaldas retitled this revision from Use PointerUnion instead of inheritance for alternative clauses in NNS to [SyntaxTree] Use PointerUnion instead of inheritance for alternative clauses in NNS.Aug 6 2020, 8:54 AM
eduucaldas edited the summary of this revision. (Show Details)
eduucaldas added a reviewer: gribozavr2.
eduucaldas edited the summary of this revision. (Show Details)Aug 6 2020, 9:10 AM
eduucaldas added inline comments.Aug 6 2020, 10:38 AM
clang/lib/Tooling/Syntax/BuildTree.cpp
781

I mark NodeRole as Unknown here, this would need fixing in the future. But should we make roles that mimic the NodeKind of the alternative?

788–789

Newbie mistake causing the crash

clang/unittests/Tooling/Syntax/TreeTest.cpp
997–1002

Here notice the additional level of nesting

eduucaldas updated this revision to Diff 283876.Aug 7 2020, 5:21 AM

Remove Fix crash on name specifier commit from patch

Seeing the API, I like the inheritance-based approach better. It seems more uniform.

clang/lib/Tooling/Syntax/Nodes.cpp
215

getFromOpaqueValue will not select the right alternative in the PointerUnion. You need to do case analysis through if-else-if based on the type of node returned by firstChild.

eduucaldas abandoned this revision.Aug 18 2020, 4:51 AM