diff options
author | Etienne Bergeron <etienneb@google.com> | 2016-03-22 17:51:27 +0000 |
---|---|---|
committer | Etienne Bergeron <etienneb@google.com> | 2016-03-22 17:51:27 +0000 |
commit | 6feeb6554e271e308238750078b178ff1e83c15c (patch) | |
tree | d3f1fc5217b8937a472e368ada6f3d616afba483 /clang-tools-extra/test/clang-tidy/misc-macro-parentheses-cmdline.cpp | |
parent | 6b535630a1222ff1e535989242dbad8513df2eb2 (diff) | |
download | bcm5719-llvm-6feeb6554e271e308238750078b178ff1e83c15c.tar.gz bcm5719-llvm-6feeb6554e271e308238750078b178ff1e83c15c.zip |
[clang-tidy] Skip reporting of not applicable fixes.
Summary:
Invalid source location are causing clang-tidy to crash when manipulating an invalid file.
Macro definitions on the command line have locations in a virtual buffer and therefore
don't have a corresponding valid FilePath.
A recent patch added path conversion to absolute path. As the FilePath may now be empty,
the result of makeAbsolutePath may incorrectly be the folder WorkingDir. The crash occurs
in getLocation which is not able to find the appropriate FileEntry (null pointer).
```
SmallString<128> FixAbsoluteFilePath = Fix.getFilePath();
Files.makeAbsolutePath(FixAbsoluteFilePath);
FixLoc = getLocation(FixAbsoluteFilePath, Fix.getOffset());
```
With relative path, the code was not crashing because getLocation was skipping empty path.
Example of code:
```
int main() { return X; }
```
With the given command-line:
```
clang-tidy test.cc --checks=misc-macro-* -- -DX=0+0
```
Reviewers: alexfh, aaron.ballman
Subscribers: aaron.ballman, cfe-commits
Differential Revision: http://reviews.llvm.org/D18262
llvm-svn: 264073
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/misc-macro-parentheses-cmdline.cpp')
-rw-r--r-- | clang-tools-extra/test/clang-tidy/misc-macro-parentheses-cmdline.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/misc-macro-parentheses-cmdline.cpp b/clang-tools-extra/test/clang-tidy/misc-macro-parentheses-cmdline.cpp new file mode 100644 index 00000000000..f7e80881070 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/misc-macro-parentheses-cmdline.cpp @@ -0,0 +1,10 @@ +// RUN: %check_clang_tidy %s misc-macro-parentheses %t -- -- -DVAL=0+0 + +// The previous command-line is producing warnings and fixes with the source +// locations from a virtual buffer. VAL is replaced by '0+0'. +// Fixes could not be applied and should not be reported. +int foo() { return VAL; } + +#define V 0+0 +int bar() { return V; } +// CHECK-FIXES: #define V (0+0) |