Commit Graph

72 Commits

Author SHA1 Message Date
Ariel J. Bernal 1d66e366e9 Fix UseAuto replacing declaration lists with new expressions
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
2013-05-27 14:30:23 +00:00
Ariel J. Bernal eba5189f9a Fix UseAuto replacing variable declaration lists containing non-initialized
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
2013-05-17 15:30:17 +00:00
Edwin Vane 799ad8e212 cpp11-migrate: Check for valid NULL macros from macro arg expansions
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
2013-05-16 14:55:05 +00:00
Edwin Vane ba6a0960ea cpp11-migrate: Add override specifier before comments on inline methods
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
2013-05-14 17:34:12 +00:00
Edwin Vane b8c3875618 cpp11-migrate: Fix crash in AddOverride due to template instantiations
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
2013-05-10 14:04:58 +00:00
Edwin Vane b40bf83eab Transform for loops over pseudo-arrays only if begin/end members exist
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
2013-05-09 20:03:52 +00:00
Ariel J. Bernal 3429028a81 Use 'auto const&' for iterators whose deref operator return a const var
This patch fixes PR15601.
- Added check for whether the loop variable and the initializer have the same
type.
- Added tests.

llvm-svn: 181528
2013-05-09 17:46:20 +00:00
Edwin Vane fa58b26a50 Stop LoopConvert removing DeclStmts from selection/iteration condition clauses
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
2013-05-06 20:01:43 +00:00
Edwin Vane 10414112d1 Added comprehensive macro arg usage logic to Use-Nullptr Transform
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
2013-05-06 17:27:02 +00:00
Edwin Vane c049c92933 Add support to read include/exclude paths from file
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
2013-05-02 19:02:02 +00:00
Edwin Vane 8ef7fa1e07 Adding the AddOverride transform for cpp11-migrate
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
2013-04-09 20:49:49 +00:00
Ariel J. Bernal 464957e2d6 Fix UseNullptr fails to replace c-style explicit cast in a return statement
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
2013-04-09 16:54:56 +00:00
Ariel J. Bernal 005daf1bc6 Fix UseNullptr fails to replace explict casts surrounded by another implicit
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
2013-04-05 20:32:36 +00:00
Edwin Vane c0b7be60f8 Unit test support for Clang extra tools
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
2013-04-03 15:11:08 +00:00
Edwin Vane eeed39a583 Use 'auto' with 'new' expressions
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
2013-04-02 20:43:57 +00:00
Ariel J. Bernal f78debd7d2 Refactor Usenullptr matcher to avoid duplication
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
2013-04-01 20:09:29 +00:00
Edwin Vane 61af48ce4e Improve loop convert's variable aliasing
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
2013-04-01 18:15:06 +00:00
Tareq A. Siraj c2aa348dd0 Allow users to specify NULL like macros to be replaced
-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
2013-03-28 16:06:59 +00:00
John Thompson 4e4d9b3abf modularize - revised to group duplicate symbols together in the error output.
llvm-svn: 178207
2013-03-28 01:20:19 +00:00
Ariel J. Bernal 3f08aae84f cpp11-migrate segfaults transforming map<string,int>::iterator
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
2013-03-27 18:49:31 +00:00
John Thompson 81450dfff9 Revised per review comments to rename test files and rearrange input files.
llvm-svn: 178047
2013-03-26 18:17:28 +00:00
John Thompson 333ec6ceb7 Added simple regression test for modularize.
llvm-svn: 177960
2013-03-26 01:18:28 +00:00
Edwin Vane a9bf2fd9d1 Adding a failing test case for cpp11-migrate's Loop Convert Transform
Related to PR15589.

llvm-svn: 177891
2013-03-25 19:24:24 +00:00
Daniel Jasper 83c10c9d38 Remove clang-format tests from tools/extra.
These will be re-added to clang/test.

llvm-svn: 177852
2013-03-25 09:14:14 +00:00
Edwin Vane c383960be9 Don't replace macro usage if macro body has NULL
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
2013-03-19 18:47:03 +00:00
Edwin Vane 2032fb973b Don't include outer-most explicit cast in nullptr replacement
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
2013-03-15 20:18:08 +00:00
Edwin Vane 52c326ec78 Prevent nullptr_t-typed exprs from being replaced
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
2013-03-15 18:10:07 +00:00
Edwin Vane c016c0da12 Turned no_xform into a pass from expected failure.
Since no_xform is not a bug to be fixed, made the test pass using the 'not'
utility and removed XFAIL.

llvm-svn: 176709
2013-03-08 18:39:07 +00:00
Edwin Vane 3606f5508b Extend loop variable naming checks
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
2013-03-08 14:15:18 +00:00
Edwin Vane 4f05d7143f Have LoopConvert use 'auto &&' where necessary
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
2013-03-07 16:22:05 +00:00
Chandler Carruth 074a3568fc Switch from autogenerating tests to using the preprocessor.
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
2013-03-07 10:09:47 +00:00
Stefanus Du Toit 49fe6388b6 Test case for PR-15414 - nullptr_t functions
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
2013-03-06 15:32:20 +00:00
Edwin Vane 105963d17c Fixed Use-Nullptr when replacing return(0)
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
2013-03-06 14:51:34 +00:00
Edwin Vane 529e3c7c57 Adding failing LoopConvert testcase
LoopConvert isn't properly handling iterators whose dereference operator
returns by value. This test case demonstrates the failure.

See PR15437.

llvm-svn: 176437
2013-03-04 16:56:04 +00:00
Edwin Vane 2f43085b46 Properly identify 'this' as range-based for container
The Loop-Convert transform was mistransforming loops using 'this' implicitly.
Fixed and added tests.

Fixes PR15411.

llvm-svn: 176436
2013-03-04 16:35:04 +00:00
Benjamin Kramer 65d2d14f32 Make gen_my_std.h.py compatible with python 2.5 too.
llvm-svn: 176409
2013-03-02 15:52:55 +00:00
Benjamin Kramer 336ec56081 Make the UseAuto test case generator compatible with python 2.5.
llvm-svn: 176406
2013-03-02 09:24:42 +00:00
Edwin Vane a98217a2b6 Avoid parallelism problems generating lit.site.cfgs
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
2013-03-01 21:21:37 +00:00
Edwin Vane b1bb4c2dbb Fix recursive make in clang-tools-extra
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
2013-03-01 19:50:52 +00:00
Edwin Vane 4b80752550 Don't use 'exit' in lit script
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
2013-02-28 20:11:25 +00:00
Edwin Vane ca5a85fad4 Turning off UseAuto/iterator.cpp test until recursive make issue fixed
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
2013-02-28 19:55:53 +00:00
Edwin Vane 266b625ca9 Introducing Use-Auto transform for cpp11-migrate
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
2013-02-28 16:29:24 +00:00
Edwin Vane 24b4bb06ed Custom lit.site.cfg configuration for cpp11-migrate
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
2013-02-27 13:09:24 +00:00
Edwin Vane 12db04f820 Fixing a "multiple rules generate X" warning from ninja
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
2013-02-21 15:12:01 +00:00
Edwin Vane ea8b062a56 Tweaks and fixes to cpp11-migrate generated tests
* 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
2013-02-20 14:35:53 +00:00
Edwin Vane 963a7b411e Adding files left out of commit r175544.
llvm-svn: 175545
2013-02-19 19:14:45 +00:00
Edwin Vane 8b526f22c6 Add support for auto-generating LIT tests by the build
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
2013-02-19 19:08:10 +00:00
Edwin Vane 4ad00b46fb Fix -use-nullptr problems with assert()
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
2013-02-17 16:45:54 +00:00
Manuel Klimek f92b666da9 Adapt test to new clang-format behavior.
llvm-svn: 174738
2013-02-08 20:04:33 +00:00
Edwin Vane 37fea69391 Fix for combined loop and nullptr convert tests
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
2013-02-07 18:49:23 +00:00