- Limit the transform to const-ref and non-const value parameters only.
- Do not generate a replacement when the type is already a value.
See CM-139 for the bugs corresponding to this issue.
llvm-svn: 190212
-include/-exclude and friends have been marked as hidden options until this
point. This is no longer necessary. Update the docs to describe their effect.
Differential Revision: http://llvm-reviews.chandlerc.com/D1621
llvm-svn: 190194
clang-modernize can now transform headers properly and the experimental
-headers option is no longer necessary.
Remember, at least -include is necessary for indicating which headers
are allowed to be changed.
Differential Revision: http://llvm-reviews.chandlerc.com/D1610
llvm-svn: 190158
If transformations lead to changes that do not need reformatting, the
current strategy will not write those files. With this patch, we just
update the overall state with the changes due to reformatting, and then
write out everything.
llvm-svn: 190050
There is no reason to expect this tool to be limited to C++11, it seems
very likely to be of on-going interest. It seems likely to be useful for
modernizing even as new libraries come out in TSes and other formats
than a complete standard. Fundamentally, we need something a bit more
general. After some discussion on the list, going with
'clang-modernize'.
I've tried to do a reasonably comprehensive job of fixing up the names,
but I may still have missed some. Feel free to poke me if you spot any
fallout here. Things I've tried reasonably hard to find and fix:
- cpp11-migrate -> clang-modernize
- Migrator -> Modernizer
- Clean up the introductory documentation that was C++11 specific.
I'll also point out that this tool continues to delight me. =] Also,
a huge thanks to those who have so carefully, thoroughly documented the
tool. The docs here are simply phenomenal. Every tool should be this
well documented. I hope I have updated the documentation reasonably
well, but I'm not very good at documentation, so review much
appreciated.
llvm-svn: 189960
The NoProblemsDependencies.modularize test is failing on many buildbots.
I have also reverted the change in 189904 to disable that test for MSVC.
llvm-svn: 189957
Made changes throughout clang-tools-extra for the renaming of
clang-replace to clang-apply-replacements as per feedback from
community.
llvm-svn: 189832
Re-commit of r189691 and r189689 now with a proper autoconf fix.
Massive simplification of how replacements and file overrides are
handled by the migrator:
* Sources and headers are all treated the same.
* All replacements for a given translation unit are stored in the same
TranslationUnitReplacements structure.
* Change tracking is updated only from main file; no need for
propagating "is tracking" flag around.
* Transform base class no longer responsible for applying replacements.
They are simply stored and main() looks after deduplication and
application.
* Renamed -yaml-only to -serialize-replacements. Same restrictions apply:
Can only request one transform. New restriction: formatting cannot also
be turned on since it's basically a transform.
* If -serialize-replacements is requested, changes to files will not be
applied on disk.
* Changed behaviour of function generating names for serialized
replacements: Only the main source file goes into the name of the file
since a file may contain changes for multiple different files.
* Updated HeaderReplacements LIT test for new serialization behaviour.
* Replaced old test that ensures replacements are not serialized if
-serialize-replacements is not provided. New version ensures changes
are made directly to all files in the translation unit.
* Updated unit tests.
* Due to major simplification of structures in FileOverrides.h, the
FileOverridesTest is quite a bit simpler now.
llvm-svn: 189798
Revert "cpp11-migrate: Refactor for driver model of operation"
This reverts commit r189691.
This reverts commit r189689.
This was breaking the phase 1 OS X build for ~2 hours.
https://smooshbase.apple.com/buildbot-internal/builders/phase1%20-%20sanity/builds/9559
I reverted the latter commit since I think the latter depended on the former.
llvm-svn: 189700
Massive simplification of how replacements and file overrides are handled by
the migrator:
* Sources and headers are all treated the same.
* All replacements for a given translation unit are stored in the same
TranslationUnitReplacements structure.
* Change tracking is updated only from main file; no need for
propagating "is tracking" flag around.
* Transform base class no longer responsible for applying replacements.
They are simply stored and main() looks after deduplication and
application.
* Renamed -yaml-only to -serialize-replacements. Same restrictions apply:
Can only request one transform. New restriction: formatting cannot also
be turned on since it's basically a transform.
* If -serialize-replacements is requested, changes to files will not be
applied on disk.
* Changed behaviour of function generating names for serialized
replacements: Only the main source file goes into the name of the file
since a file may contain changes for multiple different files.
* Updated HeaderReplacements LIT test for new serialization behaviour.
* Replaced old test that ensures replacements are not serialized if
-serialize-replacements is not provided. New version ensures changes
are made directly to all files in the translation unit.
* Updated unit tests.
* Due to major simplification of structures in FileOverrides.h, the
FileOverridesTest is quite a bit simpler now.
Differential Revision: http://llvm-reviews.chandlerc.com/D1545
llvm-svn: 189689
clang-replace is likely to move to clang proper one day soon. To facilitate
that move, renaming files and directory structure layout to ease transition for
users of clang-replace and libclangReplace.
For now, functionality still exists in clang::replace namespace. Header guards
and file comments updated.
Differential Revision: http://llvm-reviews.chandlerc.com/D1548
llvm-svn: 189671
Currently only constructor parameters stored in class-local storage are modified
to make use of the pass-by-value idiom but this is a base that can be be further
improved to handle more situations.
This commit is the same as r189363 with additionnal fixes for the build issues.
llvm-svn: 189584
For users of libclangReplace, this patch affords the ability to apply
replacements in memory instead of writing to disk.
Differential Revision: http://llvm-reviews.chandlerc.com/D1519
llvm-svn: 189493
Currently only constructor parameters stored in class-local storage are modified
to make use of the pass-by-value idiom but this is a base that can be be further
improved to handle more situations.
llvm-svn: 189363
The IncludeDirectives class helps with detecting and modifying #include
directives. For now it allows the users to add angled-includes in a source file.
This is a start for this class that will evolve in the future to add more
functionality.
This should fix the reverted commit r189037 (buildbot failures on Windows).
llvm-svn: 189354
Added a command line option "-remove-change-desc-files" that triggers
the deletion of the change description files after merging and applying
regardless of success.
Differential Revision: http://llvm-reviews.chandlerc.com/D1492
llvm-svn: 189268
Test-time dependencies now live within test/clang-replace/Inputs which is more
in line with llvm and clang test suites.
Added 'Inputs' to the lit config's 'exclude' list as with llvm's lit.cfg since
test-time dependencies should not have any lit scripts within.
llvm-svn: 189047
Subdirectories of test/clang-replace contain test-time dependencies and not
more LIT tests. Tell LIT to ignore these directories from the test suite.
llvm-svn: 189019
The IncludeDirectives class helps with detecting and modifying #include
directives. For now it allows the users to add angled-includes in a source file.
This is a start for this class that will evolve in the future to add more
functionality.
This should fix the reverted commit r188791 (buildbot failures on Windows).
llvm-svn: 189017
Functionality for clang-replace completed with the addition of the ability to
write merged replacements to disk.
Test added.
Differential Revision: http://llvm-reviews.chandlerc.com/D1460
llvm-svn: 189014
Introducing new tool 'clang-replace' that finds files containing
serialized Replacements and applies those changes after deduplication
and detecting conflicts.
Currently the tool does not apply changes. It stops just after the
deduplication and conflict report phase. Forthcoming patches will
complete functionality.
Both build systems updated for new tool.
Includes a conflict test case.
clang-replace added to Doxygen build.
Differential Revision: http://llvm-reviews.chandlerc.com/D1424
llvm-svn: 189008
The IncludeDirectives class helps with detecting and modifying #include
directives. For now it allows the users to add angled-includes in a source file.
This is a start for this class that will evolve in the future to add more
functionality.
This should fix the reverted commit r188610 (buildbot failures on Windows).
llvm-svn: 188791
This reverts commit r188610.
Issue with the absolute include paths not found in the unit tests on the Windows
bots. Needs investigation.
llvm-svn: 188611
The IncludeDirectives class helps with detecting and modifying #include
directives. For now it allows the users to add angled-includes in a source file.
This is a start for this class that will evolve in the future to add more
functionality.
llvm-svn: 188610
Allow the migrator to be used without specifing --. If neither -- nor -p is
provided and no compilation database can be detecteded from the first source
file path then -std=c++11 is added as the only compiler argument.
llvm-svn: 188533
For some reason doxygen doesn't seem to like the using namespace
clang::tooling in the source file and complaints about missing class
members.
Also fixed missing parameter documentation for TransformName in
SourceOverrides::applyReplacements().
Differential Revision: http://llvm-reviews.chandlerc.com/D1400
llvm-svn: 188394
For use with -headers, -yaml-only will cause cpp11-migrate to not write header
changes to disk and instead write them as header change description files. This
option facilitiates upcoming functionality to properly support changing headers
as part of migration.
Differential Revision: http://llvm-reviews.chandlerc.com/D1385
llvm-svn: 188371
Reworked how the tests dealt with paths. Instead of removing the full path name,
put a marker in the expected file and replace the marker with the full path
before running diff.
Differential Revision: http://llvm-reviews.chandlerc.com/D1381
llvm-svn: 188299
Another attempt to commit r187204 after windows related problems has
been fixed. Note that changes to this patch reflect the current behavior
of cpp11-migrate.
Header replacements are now written to disk in YAML format for an external tool
to merge. A unique file will be created in the same directory as the header
with all replacements that came from a source file that included the header
file. The YAML file will have:
- Name of the header file
- Name of the source file that included the header file
- Transform ID that generated the replacement
- Offset
- Length
- Replacement text
Any tool reading these replacements should read them using the
HeaderChangeDocument struct.
Differential Revision: http://llvm-reviews.chandlerc.com/D1369
llvm-svn: 188274
This fixes a problem when the path separator in the include/exclude
directory is different (e.g. "\" vs. "/") from the path separator in
the file path we are modifying.
Differential Revision: http://llvm-reviews.chandlerc.com/D1326
llvm-svn: 188094
Committing r187204 with fixes for darwin. Note that one of the lit tests are
disabled on windows due to a bug in writing header replacements to file.
Header replacements are now written to disk in YAML format for an external tool
to merge. A unique file will be created in the same directory as the header
with all replacements that came from a source file that included the header
file. The YAML file will have:
- Name of the file
- Transform ID that generated the replacement
- Offset
- Length
- Replacement text
Any tool reading these replacements should read them using the
TransformDocument struct.
llvm-svn: 187428
This change add a new option command line option -for-compilers that allows the
user to enable multiple transforms automatically.
Another difference is that now all transforms are enabled by default.
llvm-svn: 187360
This is the first version of a possible clang-tidy architecture. The
purpose of clang-tidy is to detect errors in adhering to common coding
patterns, e.g. described in the LLVM Coding Standards.
This is still heavily in flux.
Review: http://llvm-reviews.chandlerc.com/D884
llvm-svn: 187345
Header replacements are now written to disk in YAML format for an external tool
to merge. A unique file will be created in the same directory as the header
with all replacements that came from a source file that included the header
file. The YAML file will have:
- Name of the file
- Transform ID that generated the replacement
- Offset
- Length
- Replacement text
Any tool reading these replacements should read them using the TransformDocument
struct.
Differential Revision: http://llvm-reviews.chandlerc.com/D1142
llvm-svn: 187204
Recent failures on a freebsd buildbot indicated a weakness in the
Reformatting.cpp lit test. Tweaking the test to avoid false negatives and
hopefully make the buildbot happy.
llvm-svn: 187153
Doxygen doesn't recognize <blockquote> html tags. Added support for <blockquote>
and Markdown was introduce with doxygen 1.8.0. This patch replaces blockquote
with \par for compatibility with previous versions.
llvm-svn: 187067
r187041 changed the way the transform are created and the order the transformed
are applied "may" have changed as well (no specific constraints exist on the
order). This produced a test failure on the Windows buildbot.
Now the test use -std=c++11, so 'nullptr' is defined and the test is not anymore
dependent on the order the transforms are applied.
llvm-svn: 187048
With this change each transform now register a factory. The factories are
registered using an llvm::Registry which makes them available globally.
llvm-svn: 187041
It seems that doxygen fails to find overloaded methods when the parameters are
not in sync with the method declaration.
Added the fully-qualifed type to the parameters method definition although it's
not necessary since the using directive is in effect.
llvm-svn: 186948
Adding a feature to optionally reformat code changed by the migrator. Like
LibFormat, can choose between built-in styles (LLVM, Mozilla, Google, Chromium)
or use a YAML-format config file.
Now with no dependency on iostream by the Reformatting.cpp LIT test.
Author: Guillaume Papin <guillaume.papin@epitech.eu>
llvm-svn: 186938
This reverts commit r186866.
This breaks the build and the original author Guillaume Papin
<guillaume.papin@epitech.eu> asked me to revert so he could look at it more with
revane.
llvm-svn: 186873
Adding a feature to optionally reformat code changed by the migrator. Like
LibFormat, can choose between built-in styles (LLVM, Mozilla, Google, Chromium)
or use a YAML-format config file.
Author: Guillaume Papin <guillaume.papin@epitech.eu>
llvm-svn: 186866
using inline namespaces is specified.
UseAuto used to fail to transform iterators when using inline namespaces and
non-fully qualified types, relying on a using directive previously declared.
- This fix uses the already define isFromStdNamespace matcher.
- Fixed tests and added a new test using inline namespaces.
- Added CustomMatchers to reuse common matchers among transforms.
llvm-svn: 186327
This commit include the following changes:
- SourceOverrides is now a class
- it simplifies the usage for the Transform class, since now the
replacements can be applied directly to the file overrides with
SourceOverrides::applyReplacements().
- it contains a method applyRewrites() which was previously named
collectResults() in Transform.cpp. The method has been "optimized"
a bit to re-use the allocated buffer (std::string::clear() is called).
- since the class has some logic it's now unit tested
- Now FileOverrides is a class (not a std::map typedef) and store pointers
to the SourceOverrides. The reason is that the SourceOverrides can't be
copied anymore (which was already something to avoid since it's can be a
quite large object).
Author: Guillaume Papin <guillaume.papin@epitech.eu>
Differential Revision: http://llvm-reviews.chandlerc.com/D1122
llvm-svn: 186161
This patch is in preparation for writing the header replacement to disk.
Added getUniqueHeaderName() that generates a unique header filename in
the same directory as the header file.
Differential Revision: http://llvm-reviews.chandlerc.com/D1104
llvm-svn: 186007
Some changes to r185811 broke certain build configurations. These changes should
fix them.
Author: Guillaume Papin <guillaume.papin@epitech.eu>
llvm-svn: 185814
* Some file headers were missing for files in Core/
* Some headers were included but not necessary
* CMakeLists.txt was linking in LLVMSupport even though CMakeLists in subdirs
were linking it in too.
* StringRefisation of constructors of types in FileOverrides.h
* Other misc cleanups
Author: Guillaume Papin <guillaume.papin@epitech.eu>
llvm-svn: 185811
* all transforms are in the same category
* all transforms' options are in the same category
* display the CommonOptionParser extra-help (which describe in more details the
compilation database stuff)
* add EXAMPLES section
Author: Guillaume Papin <guillaume.papin@epitech.eu>
llvm-svn: 185660
Add a new transform to replace uses of 'std::auto_ptr' by 'std::unique_ptr'.
Copy-ctor and assign-operator are wrapped with a call to 'std::move()'.
Note that until header modification is ready it is not that useful, that's why
it's marked as (EXPERIMENTAL) in the command line description and a "Known
Limitations" section is present in the transform documentation.
Author: Guillaume Papin <guillaume.papin@epitech.eu>
llvm-svn: 185535
sys::fs::make_absolute was turning '.' into '<path>/.' which broke prefix
comparison logic. Stripping these extra chars fixes the problem.
llvm-svn: 184322
Transforms will now make changes to headers if header modifications have been
enabled.
FIXME: Only UseNullptr contains a cursory header modification test. Other
transforms should have them too.
llvm-svn: 184197
To make it possible for replacements made to headers as part of transforming
one translation unit to not be visible to the transform of other translation
units, Transform now handles replacement application as part of its
end-of-source handling. Several things were simplified as a result:
- The duplicated code in every transform for applying replacements is now gone
and replaced with one location in Transform.
- RefactoringTool is no longer used since Transform houses the Replacements
structure.
- RewriterContainer is now a private implementation detail of Transform (also
renamed to RewriterManager since its behaviour is slightly different now with
respect to lifetime of objects).
- There's now no distinction between input and output file state.
Misc notes:
- Interface changes reflected in unit tests.
- Replacements for files other than the main file are assumed to be for headers
and stored as such.
llvm-svn: 184194
To better support per-translation unit replacements, any real work is being
moved out of ActionFactory and into Transform. In this revision, that means
file override application.
For simplification, Transform no longer inherits from SourceFileCallbacks.
TransformTest required updating as a result.
llvm-svn: 184098
This reverts commit r184004.
This test has some dependency on the behavior of the old function on windows. I
added it back to llvm for now.
llvm-svn: 184010
File override structures now contain per-source overrides for headers.
For now, modified headers are written to disk when the Migrator is done.
This is only temporary behaviour since we can expect headers to be
changed by migrating multiple source files. The changes need to be
merged after all migrations are complete.
llvm-svn: 183917
A more flexible container for storing overrides is required for headers. Before
a source goes through the transform pipeline, any headers it references will be
in their original state and unaffected by transforms applied to other sources.
Therefore overrides for headers need to be kept separate for each source file.
This patch doesn't introduce support for storing header overrides yet. It only
replaces the existing structure and makes any necessary changes to support it.
llvm-svn: 183910
Next step toward supporting migrating headers. Instead of using ClangTool's
ability to override all files at once, use a custom FrontendAction and override
only the source (and eventually headers) the action is about to parse.
Use of newFrontendActionFactory() is replaced with a new factory maker provided
by Transform.
llvm-svn: 183855
First step toward supporting header modifications: adding a flag that turns on
such modifications. Eventually header modifications will be on by default but
until all the kinks can be worked out, they must be explicitly enabled.
llvm-svn: 183444
Refactored how global options are passed to Transforms to avoid widespread
changes every time a new global option is added.
Tests updated to reflect new interface.
llvm-svn: 183443
* Documented new command-line options.
* Moved usage to a new page.
* Usage now split into general options and transform-related options.
* Main Migrator page now contains getting started and getting involved
information.
* Also included a JIRA issue collector button for logging bugs.
llvm-svn: 183417
Performance timers captured in each transform for all files they process are now collected and arranged per source file in preparation for writing to disk.
This revision is the last piece of the initial implementation of performance timer capturing.
llvm-svn: 183274
-Added command line option -report-times to enable or disable the output. The
same option can be used to specify the output directory.
-Write timing data to a unique file in disk using json format.
llvm-svn: 183142
Added a new option -override-macros which causes the, the add-override
transform to detect macros that expand to 'override' (like LLVM_OVERRIDE) and
use these macros instead of the override keyword directly.
llvm-svn: 183001
Using updated form of newFrontendActionFactory(), Transforms now automatically
measure, if requested, how long it takes to apply a MatchFinder to a source
file. Other per-transform overhead, e.g. applying replacements, is not
currently measured. This behaviour is disabled for now and soon will be
connected to a new command line arg.
llvm-svn: 182942
UseAuto used to replace declarion lists with new expressons where some
variable were not initialized with new.
This fix checks that every DeclStmt has a VarDecl with an initializer and it
also ensures that all declarations have the same type.
Added tests for multiple declarations and for typedefs.
llvm-svn: 182736
variables.
UseAuto used to match initialized variable declarations independently of
whether they were defined in a declaration list or as a single declaration.
Now it matches declaration statements where every variable declaration is
initialized.
llvm-svn: 182114
The recent improvement to the Use Nullptr Transform for macro arg
expansions wasn't testing that only allowed NULL macros used in macro
args can be transformed. This revision replaces a TODO to that effect.
Fixes PR15955.
llvm-svn: 182014
This commit fixes a "FIXME" in the add-override transform. ' override' was
misplaced when a comment was between the function body and the end of the
'prototype'.
It also remove duplicated check for the main file from the last commit (and
fixes the typo in the comment above).
Author: Guillaume Papin <guillaume.papin@epitech.eu>
llvm-svn: 181806
This patch fixes different issues:
- override is not added in template 'contexts' (this will be further improved
to handle safe situations, a test for this has been written already)
- the main file is now checked before the modifications are applied
- override is not applied now when dealing with pure methods since it was
misplaced (ignoring it isn't the perfect solution but it seems difficult to
find the location just before the pure-specifier)
Fixes PR15827
Author: Guillaume Papin <guillaume.papin@epitech.eu>
llvm-svn: 181596
For loops using pseudo-arrays, classes that can be used like arrays from
the Loop Convert Transform's point of view, should only get transformed
if the pseudo-array class has begin()/end() members for the
range-based for-loop to call.
Free versions of begin()/end() should also be allowed but this is an
enhancement for another revision.
llvm-svn: 181539
If the LoopConvert Transform detects an alias for the loop variable, it
attempts to use that name in the resulting range-based for loop while removing
the original DeclStmt for the variable. That removal produced bad code when the
declaration was in the condition of an if, switch, while, or for stmt. This
revision fixes the problem by simply replacing the declaration with a use of
the alias variable.
llvm-svn: 181242
If a NullTo(Member)Pointer cast results from a macro arg expansion, all uses of
the arg must result in such casts or else the macro arg cannot be replaced with
'nullptr' safely. This revision adds logic and tests to ensure the safety of
replacing macro args in the Use-Nullptr Transform.
Fixes: PR15816
llvm-svn: 181221
It is preferable for a unit test to be responsible for creating its own input
data instead of relying on checked-in data files. Now the IncludeExcludeTest
for cpp11-migrate does this.
- Removed old data files.
- Updated build system and lit files to remove references to old data files.
llvm-svn: 181029
Files containing the list of paths to be included and excluded can now be
specified through -include-from=<filename> and -exclude-from=<filename> command
line options in cpp11-migrate.
Added support for data files for cpp11-migrate unittests. The Cpp11MigrateTests
executable just requires a DATADIR environment variable to be set which
specifies the directory where data files are stored. This is handled
automatically when using LIT.
Author: Jack Yang <jack.yang@intel.com>, Edwin Vane <edwin.vane@intel.com>
llvm-svn: 180939
This commit adds initial support for the -include/-exclude options which are
both currently marked as hidden. This support is the first step toward
supporting transformations in headers included from source files.
Added unittests to test include/exclude support.
Author: Jack Yang <jack.yang@intel.com>
llvm-svn: 179528
This transform adds the override specifier to methods that overrides virtual
methods from a base class that don't already have this specifier.
Author: Philip Dunstan <phil@phildunstan.com>
llvm-svn: 179127
This happens whenever there is a c-style explicit cast to nullptr not
surrounded by parentheses following a return statement.
- Added a white space before nullptr if the character before is alphanumeric
when replacing the null pointer expression.
- Simplified visitor
- Addes tests
llvm-svn: 179103
cast
UseNullptr previously matched the implicit cast to const pointer as well as
the explicit cast within that has an implicit cast to nullptr as a descendant.
-Refactored UseNullptr to avoid special-casing certain kinds of cast sequences
-Added test cases.
llvm-svn: 178907
With cpp11-migrate core functionality moved to a separate library (for enabling
unit tests) this library contained code that referenced symbols that are still
in the main binary. On some platforms, the shared library build broke as a
result. This revision fixes the dependency problem and is safe for the eventual
lib-ification of the transforms as well.
llvm-svn: 178901
With the lib-ification of cpp11-migrate, real unit tests can be written.
Replacing dummy tests with some simple tests for the Transform public
interface.
llvm-svn: 178900
Summary:
Transform.* and Transforms.* moved to form a new library: libmigrateCore.
#includes updated to point to new header locations.
To support autoconf build, Cpp11Migrate.cpp moved to new subdirectory 'tool'
which also contains build files for creating final binary.
CMake and autoconf updated to build the new library and link it with
cpp11-migrate and with cpp11-migrate unit tests.
Dummy unit tests replaced with simple, but real, tests for Transform's public
interface.
TODO: Lib-ifying the transforms to further simplify build of cpp11-migrate.
llvm-svn: 178785
Added support to CMake and autoconf for unit tests in clang-tools-extra. A
dummy test exists for now until more meaningful tests can be written.
llvm-svn: 178661
For variable declarations initialized with new expressions, use 'auto' for the
type specifier.
The 'auto' replacement happens only when the type of the VarDecl exactly
matches the type of the initializer and the VarDecl is *not* CV-qualified. The
only case that is currently handled is if the pointer type of the VarDecl is
itself CV qualified.
Some improvements need to be made to Clang's TypeLoc information in order for
other CV qualifier cases to be successfully handled. See the new test suite
new_cv_failing.cpp for examples of usages that could be handled with such an
improvement.
Function pointers are, for now, not transformed until the identifier info can
be extracted.
Reviewer: klimek
llvm-svn: 178575
Previously UseNullptr matched separately implicit and explicit casts to nullptr,
now it matches casts that either are implict casts to nullptr or have an
implicit cast to nullptr within.
Also fixes PR15572 since the same macro replacement logic is applied to implicit
and explicit casts.
llvm-svn: 178494
Loop convert's variable name aliasing may cause issues if the variable is
declared as a value (copy). The converted loop will declare the variable as a
reference which may inadvertently cause modifications to the container if it
were used and modified as a temporary copy.
This is fixed by preserving the reference or value qualifiers of the aliased
variable. That is, if the variable was declared as a value the loop variable
will also be declared as a value and similarly for references.
Fixes: PR15600
Author: Jack Yang <jack.yang@intel.com>
llvm-svn: 178485
-use-nullptr only replaced macro named NULL and ignored any user defined
macros that behaved like NULL. This patch introduces -user-null-macros
command line option to let users specify their custom NULL like macros.
- Added a -user-null-macros command line option that takes a
comma-separated list of user-defined macros to be replaced when using
the -use-nullptr transform.
- Added documentation.
- Updated testcase to reflect current behavior.
- Whitespace fixes.
Reviewers: revane, klimek, gribozavr
llvm-svn: 178243
cpp11-migrate segfaults when -use-auto tries to resolve initializing
expression resulting in an expression with cleanups.
- Skip expressions with cleanups from the initializer
- Added test case
Fixes PR15550
llvm-svn: 178167
Sam Panzer, author of loop convert, provided a list of limitations of the tool
to be documented. (Thanks Sam!)
The transform's limitations are now documented in the existing user doc.
Included are examples of the cases where the tool may change semantics.
Author: Jack Yang <jack.yang@intel.com>
llvm-svn: 178034
Fix build dependency. Now can say 'make cpp11-migrate' (with cmake anyway) from
a clean build and result will be usable.
Author: Ariel J Bernal <ariel.j.bernal@intel.com>
llvm-svn: 177871
In case of macro body expansion, check to see if the macro is named NULL and
don't replace inside the macro body. This fixes the case when NULL appears
inside the macro body and the transform replaces the usage of the macro with
nullptr. This is an easy fix for the problem for now and we should analyze the
macro body to see if it expands to only NullToPointer in the future for a more
robust solution that takes care of user defined macros that behaves like NULL.
Other changes:
- Moved complex macro tests to macros.cpp
- Added new test cases.
- Added checks to make sure that the macro bodies are not modified by the tool.
Fixes: PR15396
Author: Tareq A Siraj <tareq.a.siraj@intel.com>
llvm-svn: 177422
The outer-most explicit cast is now left alone by the Use-Nullptr transform to
maintain the type of the expression and avoid introducing ambiguities.
Fixes PR15395.
Author: Ariel J Bernal <ariel.j.bernal@intel.com>
llvm-svn: 177179
The Use-Nullptr transform was replacing nullptr_t-typed expressions because in
the AST such expressions have an implicit NullToPointer cast around them. Now
the transform ignores these expressions.
Fixes PR15414.
llvm-svn: 177168
"This documentation" could be construed as the entire c-t-e docs
(despite being under a doxygen heading; people read "locally"
sometimes), which gives a bad impression.
llvm-svn: 176849
There are no python modules in clang-tools-extra so a link to this
auto-generated page, which currently isn't generated anyway, is not necessary.
llvm-svn: 176713
The loop convert tests for conflicting names have been extended to check for
macro names, types, and language keywords including language extensions. Tests
have also been added.
Fixes PR15322
Author: Jack Yang <jack.yang@intel.com>
Reviewer: gribozavr, klimek, revane
llvm-svn: 176690
For iterators where the dereference operator returns by value, LoopConvert
should use 'auto &&' in the range-based for loop expression.
If the dereference operator returns an rvalue reference, this is deemed too
strange and the for loop is not converted.
Moved test case from iterator_failing.cpp to iterator.cpp and added extra
tests.
Fixes PR15437.
Reviewer: gribozavr
llvm-svn: 176631
NOTE: You may need to run 'make clean' or 'ninja -t clean' etc!!! This
is due to really nasty bug/interactions between
CMake/configure/make/Ninja/LIT...
This commit tries to back out the support for generating test cases as
part of the build system due to the issues I brought up in post-commit
review:
1) It adds a *lot* of complexity and fragility to the build system. See
the number of commits required to try to get all the bots happy.
2) It isn't really necessary -- we can already run scripts to generate
things with the RUN lines of a test.
3) It makes the tests somewhat harder to debug as they cross between
more domains.
4) In almost all cases it isn't really needed or it can be done directly
using the preprocessor.
I should have been more proactive reviewing this, and I'm really sorry
about the churn here. =/ To help keep track of what commits are going
where, this backs out most of the non-test-changes from these revisions:
r176397
r176373
r176293
r176184
r175744
r175624
r175545
r175544
There were several trivial or cleanup changes to the lit files or other
files. Some of these looked ok, but I didn't try to tease them apart...
Edwin, if you know what to look for, please carry on with the cleanups
there, and sorry for hosing stuff here but I'm not much of a Python
person, and so I was erring on the side of cautiously backing out the
change.
I've tried to preserve the test changes everywhere I could, but review
is appreciated here in case I missed some.
I then re-wrote the tests to use the preprocessor rather than python to
expand to the various bits of code. The nicest part of this is that now
all the files are just C++ code. They edit and behave like C++ code,
etc. RUN lines with different -D flags are used to run the same test
over multiple different configurations, and includes bracketed in
special defines are used to flesh out a collection of standard interface
stubs to test interactions between pieces. These probably aren't perfect
yet, but I think its an improvement (at least in terms of build system
complexity) and will hopefully be a useful demonstration of the
technique I prefer for these types of tests.
llvm-svn: 176627
The use-null-ptr transform will transform calls to functions that return a
nullptr_t. Even if the function were to only return a null pointer and do
nothing else, this replacement would still be undesired as the behavior and
signature of the function could change in the future.
This adds an XFAILed test case to demonstrate the issue.
Reviewed by: Edwin Vane, Tareq Siraj
llvm-svn: 176553
Before fix, the paren expression was being replaced resulting in returnnullptr.
ParenExpr and implicit casts now ignored so we get return(nullptr) instead.
Added new test cases.
Fixes PR15398
Author: Ariel Bernal <ariel.j.bernal@intel.com>
llvm-svn: 176551
Added a summary option that enables output to stdout counting the number of
changes each transform has accepted, rejected or deferred.
Patch by Ariel Bernal.
llvm-svn: 176465
LoopConvert isn't properly handling iterators whose dereference operator
returns by value. This test case demonstrates the failure.
See PR15437.
llvm-svn: 176437
That is where the documentation gets built to.
I'm pretty much clueless about SVN; I would appreciate if someone more
knowledgeable about SVN made the equivalent change.
llvm-svn: 176417
extra/test/cpp11-migrate/Makefile was using the same tmp file for generating
lit.site.cfg for two different directories. Parallelism caused conflicts so now
using differently named temp files.
llvm-svn: 176379
Previously we would check the syntax of the file before we transform
it, but that's redundant since it'll be checked as part of the
transformation. Remove that check completely.
We also had an unconditional syntax check after transforming. This
is only really useful to debug cpp11-migrate, since users will end
up compiling the transformed source anyways, and the transformations
*should* never introduce a failure. Made this an option, accessible
via "-final-syntax-check".
Resolves PR 15380.
llvm-svn: 176376
Autoconf make (all) now properly recurses from tools/extra/Makefile into
tools/extra/test/Makefile and tools/extra/test/cpp11-migrate/Makefile. The
'all' target is responsible for creating lit config files and autogenerating
tests. Subsequent 'check-all' targets will properly work.
Re-enabling UseAuto/iterator.cpp test.
General clean-up of clang-tools-extra makefiles; removing dead targets and
removing duplicated pieces of llvm/Makefile.rules.
llvm-svn: 176373
This moves the actual replacement code into a separate
function. There is still a bit of code duplication to
go from macros to expansion areas, but that code will
need to be fixed anyways to resolve bugs around macro
replacement.
Reviewed by: Tareq Siraj, Edwin Vane
llvm-svn: 176372
Some buildbots use a shell that doesn't know 'exit'. So instead of using XFAIL
for UseAuto/iterator.cpp (since this problem doesn't exist for cmake) leave the
'grep' command and turn off the others.
llvm-svn: 176295
The way 'make check-all' causes configuration files to be generated results in
the cpp11-migrate/Makefile not being triggered to generated any files. These
files are necessary for UseAuto/iterator.cpp to run. Turning off this test
until the problem is fixed properly.
llvm-svn: 176293
The new Use-Auto transform replaces the type specifier for variable
declarations with the special C++11 'auto' type specifier. For now, the
replacement is done only for variables that are iterators of any of the
std containers and only if the type used is one of those explicitly
allowed by the standard (i.e. not an implementation-specific type).
Reviewers: gribozavr, silvas, klimek
llvm-svn: 176266
To afford hand-written tests access to any auto-generated headers, a
lit.site.cfg is now created for cpp11-migrate's test directory providing a new
config.substition. Tests can refer to %gen_root in the LIT script.
Removed use of --param clang_site_config. Not necessary when running
tests using the build system.
llvm-svn: 176184
Adding an RST document for cpp11-migrate. This user documentation explains
command line options, transformations, risk level and how it applies to
loop convert, and code examples of transformations.
There is a TODO task under "Risk" for "Loop Convert" to find code examples
that produce incorrect transformations that change semantics. The definition
of risk in loop convert and instances where the confidence level is lowered
will need to be looked at more carefully.
Information for all new features (including verbose output, auto transform)
will be added in a later change.
Author: Jack Yang <jack.wang@intel.com>
Reviewer: grigozavr
llvm-svn: 176046
CMake's Ninja generator was not detecting that test/lit.site.cfg.in and
test/subdir/../lit.site.cfg.in were really the same file. Ninja noticed this
and complained as both appeared as targets (for the missing file rule). Now
canonicalizing the path to ensure the paths presented to CMake are identical
and the duplication is now fixed.
llvm-svn: 175744
* Fixed a comment typo
* Changed 'autogen' to 'generated-tests'
* Made the clean target not fail if the 'generated-tests' directory
doesn't already exist.
llvm-svn: 175624
autoconf and CMake flavours both updated to auto-generate files for use
in cpp11-migrate's LIT tests.
Auto-generated files are placed in the build directory under
test/cpp11-migrate/autogen. The directory structure past this point
mirrors the structure in the source directory under test/cpp11-migrate.
A lit.site.cfg is generated in test/cpp11-migrate/autogen to describe
the new test suite. When LIT runs, it runs the standard testsuite and
now also the auto-generated testsuite.
llvm-svn: 175544
If a cast expression (NullToPointer) is detected in a function-like macro
parameter, we should use the spelling location instead of the expansion
location. Using SourceManager::getFileLoc() fixes this problem.
Also added testcases for this bug.
Fixes: PR15279
Author: Tareq A Siraj <tareq.a.siraj@intel.com>
Reviewer: klimek
llvm-svn: 175399
Currently, changes made by previous transforms are not kept if a transform
doesn't make any changes itself to a given file. Now file states are propagated
properly through transforms that don't make changes.
Fixes: PR15281
Author: Jack Yang <jack.yang@intel.com>
Reviewer: klimek
llvm-svn: 175288
Adding a new docs directory, with files auto-generated by sphinx-quickstart,
for user documentation for the various tools in the clang-tools-extra
repository.
Author: Jack Yang <jack.yang@intel.com>
Reviewers: gribozavr, silvas
llvm-svn: 175118
The rewriter was previously reading the content buffer from the file itself.
Since we are now keeping the content in memory and writing to the file only
once, the rewriter's buffer (from the file) was not in sync with the
RefactoringTool's buffer. Adding an overrideFileContents call (similar to how
Clang-format handles for this) will resolve this issue.
Author: Jack Yang <jack.yang@intel.com>
Reviewers: gribozavr, klimek
llvm-svn: 174643
The -invert-pointer-binding option will be superseeded by my next
cfe-commit. Instead of explicitly overwriting this flag, clang-format
can then be configured to auto-detect certain style-options based on the
input file.
llvm-svn: 174503
Apparently the owners of the tools we want to integrate with (eclipse in
this case) don't have JSON parsers.
The output now is:
<replacements>
<replacement offset='2' length='3'> </replacement>
...
</replacements>
Kicking JSON for now - it's easy enough to get back in when we need it.
FIXME: once we find this useful enough, we might want to add it as
free-standing functions to tooling.
llvm-svn: 174497
Using -output-replacements will now output the replacements instead
of the changed code. This allows easier integration with tools that
need full control over what changed.
The format is an array of objects with the members "offset" (number),
"length" (number) and "replacement_text" (string), for example:
[
{
"offset": 42,
"length": 5,
"replacement_text": " "
},
{
"offset": 105,
"length": 4,
"replacement_text": ""
}
]
llvm-svn: 174382
This is backwards compatible with earlier integrations.
Also adds a basic test and a test for the ranges integration.
You can now run:
clang-format -offset=42 -length=15 -offset=150 -length=22
To re-format the ranges (42, +15) and (150, +22).
llvm-svn: 174378
This transform converts the usage of null pointer constants (e.g. NULL, 0,
etc.) in legacy C++ code and converts them to use the new C++11 nullptr
keyword.
- Added use-nullptr transform.
- Added C++11 support to the final syntax check. Used ArgumentAdjuster class to
add -std=c++11 option to the command line options.
- Added tests for use-nullptr transform.
- Added tests that exercises both loop-convert and use-nullptr in the source
file.
TODO: There's a known bug when using both -loop-convert and -use-nullptr at the
same time.
Author: Tareq A Siraj <tareq.a.siraj@intel.com>
Reviewers: klimek, gribozavr
llvm-svn: 173178
Instead of writing the result of each transform to disk for every
transform, write the results to buffers in memory and pass those buffers
to the next transform as input. Only write the buffers to disk if the
final syntax check passes.
Reviewers: klimek
llvm-svn: 172657
RefactoringTool::run() no longer writes changes to disk automatically. Updating users of RefactoringTool to explicitly perform the write.
Reviewers: klimek
llvm-svn: 172218
cpp11-migrate now contains the loop convert transform code and tests.
Cleaning up the old code/tests and updating build system files as
necessary.
Reviewers: klimek
llvm-svn: 172074
- adds '-h' as an alias for '-help'.
- adds an optional <file> argument
- adds an option -i to in-place edit the given file
- adds a help text to explain what the tool does
llvm-svn: 171858
- Turned off -count-only tests as they aren't supported in cpp11-migrate
yet.
- Updated tests to use new binary name and options to access
loop-convert transform.
- Fixed header guards to not use restricted names.
Reviewers: klimek, gribozavr
llvm-svn: 171852
This matches the test change done in clang at r171742. Without this,
clang-format would strip '@' characters and format e.g. '@interface' as
'interface'.
llvm-svn: 171743
RecusiveASTVisitor. With Clang and modern GCCs this was found through
the injected class name of the base class but older GCCs don't properly
implement the injected class name rules.
llvm-svn: 171593
Took existing code from loop-convert tool and made it into a cpp11-migrate
transform. Pattern now set for having transform code in subdirectories. Related
changes:
- Makefile and CMakeLists.txt updated to support source files in
subdirectories.
- At least one transform must be specified. syntax-only tests removed to
reflect this.
- TODO: port over loop-convert tests.
Reviewers: klimek, silvas
llvm-svn: 171481
A segfault used to clear the entire buffer. With this change, a message
to report a bug is displayed instead.
This should solve most cases similar to llvm.org/PR14774.
llvm-svn: 171480
We should also install the clang-format.py script somewhere that makes
since for a Vim integration script. I don't know where that is though,
so just installing the binary for now. This is enough to let me use the
script from a checkout combined with the installed (and thus less likely
to crash or be slow) clang-format binary.
llvm-svn: 171164
- Added directory structures and build system files for the new tool.
- Extremely basic implementation of tool performs only an initial syntax check.
- Basic tests ensure syntax test works as expected.
llvm-svn: 169983
Reads a single source range (offset, length) as well as the style guide
as parameters and then reformats everything it receives from stdin.
llvm-svn: 169364
Seems I had a problem with my version of grep, when run by lit, not supporting
the \s escape. This seems to fix it for me & I'll be getting the buildbots to
run these tests too to keep an eye on them (actually loop-convert tests still
fail when run via a make build, so that'll be addressed in a future commit). I
could use [[:space:]] to generalize over other whitespace but that seemed
unnecessarily verbose when the flexibility wasn't actually required by the
current text of the tests.
Also I just simplified a lot of the loop-convert tests (removing the
unecessary temp file deletion at the start, removing the unnecessary && for
FileCheck, etc).
The remove-cstr-calls/basic.cpp changes were necessitated by an out of tree
lit-like test runner that's a bit less fantastic about escaping. They were
modeled on existing tooling test cases in Clang, with thanks to Manuel Klimek
for the pointers.
llvm-svn: 163009
A new Clang-based tool which converts for loops to use the range-based
syntax new to C++11. Three kinds of loops can be converted:
- Loops over statically allocated arrays
- Loops over containers, using iterators
- Loops over array-like containers, using operator[] and at()
Each transformation is assigned a confidence level by the tool. The
minimum require confidence level to actually apply the transformation
can be specified on the command line, but the default level should be
fine for most code.
Like other tools based on RefactoringTool, it is easiest to use this
tool with a compilation database.
llvm-svn: 162627
Loop Converter Skeleton - array-step-1
Added a check to loop increments - array-step-2b
Added a check on the loop's condition expression - array-step-2c
Finished array matcher - array-step-2
Retrieved matched nodes - array-step-3
Analysis for array loop indices - array-step-4
Added checking for naming and variable scope
Added confidence level and count-only command line args
Added aliased variable elision
Added support for iterator-based loops
Added support for single-iterator loops which call end() repeatedly
Added support for converting array-like containers
llvm-svn: 162610
With this we can build and test the remove-cstr-calls tool which should
serve as a good example of how to add tools and their tests to the
repository.
llvm-svn: 161404