This is an archive of the discontinued LLVM Phabricator instance.

[libTooling] Fix bug in Stencil handling of macro ranges
ClosedPublic

Authored by ymandel on Jan 6 2020, 8:07 AM.

Details

Summary

Currently, an attempt to rewrite source code inside a macro expansion succeeds, but results in empty text, rather than failing with an error. This patch restructures to the code to explicitly validate ranges before attempting to edit them.

Event Timeline

ymandel created this revision.Jan 6 2020, 8:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 6 2020, 8:07 AM

The only functional change that I see in this patch is in clang/lib/Tooling/Transformer/Stencil.cpp. However, I don't understand how that change in the (deprecated) selection() stencil can affect other stencils.

clang/unittests/Tooling/StencilTest.cpp
375

"foo(MACRO);" will fail parsing at the top level, it should be within a function, I think.

ymandel marked 2 inline comments as done.Jan 17 2020, 8:11 AM

The only functional change that I see in this patch is in clang/lib/Tooling/Transformer/Stencil.cpp. However, I don't understand how that change in the (deprecated) selection() stencil can affect other stencils.

Good point. Actually, selection and text are still used internally. See, for example, lines 301-303 in Stencil.cpp. We deprecated their use for clients.

clang/unittests/Tooling/StencilTest.cpp
375

matchStmt *(below) handles wrapping the snippet in a function.

gribozavr2 accepted this revision.Jan 17 2020, 8:17 AM

The only functional change that I see in this patch is in clang/lib/Tooling/Transformer/Stencil.cpp. However, I don't understand how that change in the (deprecated) selection() stencil can affect other stencils.

Good point. Actually, selection and text are still used internally. See, for example, lines 301-303 in Stencil.cpp. We deprecated their use for clients.

Oh, that explains everything.

This revision is now accepted and ready to land.Jan 17 2020, 8:17 AM
ymandel marked an inline comment as done.Jan 17 2020, 8:31 AM

Thanks for the review!

The only functional change that I see in this patch is in clang/lib/Tooling/Transformer/Stencil.cpp. However, I don't understand how that change in the (deprecated) selection() stencil can affect other stencils.

Good point. Actually, selection and text are still used internally. See, for example, lines 301-303 in Stencil.cpp. We deprecated their use for clients.

Oh, that explains everything.

I have to clean up that implementation file...

This revision was automatically updated to reflect the committed changes.