Commit Graph

31847 Commits

Author SHA1 Message Date
Chandler Carruth 29027b9352 Fix this test which had encoded the typo fixed in r137814.
llvm-svn: 137821
2011-08-17 08:56:14 +00:00
Chandler Carruth e89ca5f7d2 Don't suggest assignment in implausible situation. We still warn, as the
code is very likely to be buggy, but its going to require more
significant changes on the part of the user to correct it in this case.

llvm-svn: 137820
2011-08-17 08:38:11 +00:00
Chandler Carruth ae51ecc57b Introduce a new warning, -Wtop-level-comparison. This warning is
a complement to the warnings we provide in condition expressions. Much
like we warn on conditions such as:

  int x, y;
  ...
  if (x = y) ... // Almost always a typo of '=='

This warning applies the complementary logic to "top-level" statements,
or statements whose value is not consumed or used in some way:

  int x, y;
  ...
  x == y; // Almost always a type for '='

We also mirror the '!=' vs. '|=' logic.

The warning is designed to fire even for overloaded operators for two reasons:

1) Especially in the presence of widespread templates that assume
   operator== and operator!= perform the expected comparison operations,
   it seems unreasonable to suppress warnings on the offchance that
   a user has written a class that abuses these operators, embedding
   side-effects or other magic within them.
2) There is a trivial source modification to silence the warning for
   truly exceptional cases:

     (void)(x == y); // No warning

A (greatly reduced) form of this warning has already caught a number of
bugs in our codebase, so there is precedent for it actually firing. That
said, its currently off by default, but enabled under -Wall.

There are several fixmes left here that I'm working on in follow-up
patches, including de-duplicating warnings from -Wunused, sharing code
with -Wunused's implementation (and creating a nice place to hook
diagnostics on "top-level" statements), and handling cases where a proxy
object with a bool conversion is returned, hiding the operation in the
cleanup AST nodes.

Suggestions for any of this code more than welcome. Also, I'd really
love suggestions for better naming than "top-level".

llvm-svn: 137819
2011-08-17 08:38:04 +00:00
Jordy Rose c1470290c3 Hook up -W[no-]analyzer-incompatible-plugin to new warning, and unbreak buildbot.
llvm-svn: 137816
2011-08-17 06:25:12 +00:00
Jordy Rose 9c09ce48b4 Fix typo.
llvm-svn: 137814
2011-08-17 05:00:56 +00:00
Jordy Rose 075d73bcce [analyzer] Add a warning for an incompatible plugin version.
llvm-svn: 137813
2011-08-17 04:56:03 +00:00
Benjamin Kramer 8b3929d956 Silence compiler warnings by casting object pointers to function pointers via intptr_t.
This is ugly but ISO C++ doesn't allow direct casts.

llvm-svn: 137812
2011-08-17 04:22:25 +00:00
Jordy Rose ae55cf2f90 Don't use BuiltinBug in analyzer plugin example.
llvm-svn: 137811
2011-08-17 03:23:51 +00:00
Jordy Rose 9db0719242 [analyzer] Add some documentation for the new analyzer plugin infrastructure.
llvm-svn: 137805
2011-08-17 02:15:41 +00:00
NAKAMURA Takumi 203f87ccb1 [MSVC] Fix a warning C4334 "'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)".
llvm-svn: 137803
2011-08-17 01:46:16 +00:00
Jordy Rose 93b86e494d [analyzer] Add basic support for pluggable checkers.
llvm-svn: 137802
2011-08-17 01:30:59 +00:00
Francois Pichet 09af8c36d1 Add serialization support for ClassScopeFunctionSpecializationDecl.
llvm-svn: 137799
2011-08-17 01:06:54 +00:00
Argyrios Kyrtzidis f872dc4c3b [python] Add support for CXType to python bindings.
Patch by Anders Waldenborg!

llvm-svn: 137797
2011-08-17 00:43:03 +00:00
Argyrios Kyrtzidis 6f5bd2f630 [libclang] Make clang_getCursor able to handle locations that point inside macro arguments.
e.g. for:

\define INVOKE(METHOD, CLASS) [CLASS METHOD]

void test2() {
  INVOKE(meth, MyClass);
}

Pointing at 'meth' will give a CXCursor_ObjCMessageExpr and pointing at 'MyClass'
will give a CXCursor_ObjCClassRef.

llvm-svn: 137796
2011-08-17 00:31:25 +00:00
Argyrios Kyrtzidis 161868db4c Make Lexer::GetBeginningOfToken able to handle macro arg expansion locations.
llvm-svn: 137795
2011-08-17 00:31:23 +00:00
Argyrios Kyrtzidis 92a47bd997 Introduce SourceManager::getMacroArgExpandedLocation function.
If we pass it a source location that points inside a function macro argument,
the returned location will be the macro location in which the argument was expanded.
If a macro argument is used multiple times, the expanded location will
be at the first expansion of the argument.
 e.g.
   MY_MACRO(foo);
             ^
Passing a file location pointing at 'foo', will yield a macro location
where 'foo' was expanded into.

Make SourceManager::getLocation call getMacroArgExpandedLocation as well.

llvm-svn: 137794
2011-08-17 00:31:20 +00:00
Argyrios Kyrtzidis ac199bffab Make SourceManager::isBeforeInTranslationUnit handle macro locations correctly.
llvm-svn: 137793
2011-08-17 00:31:18 +00:00
Argyrios Kyrtzidis a1d943a121 [PCH] When writing out ExpansionInfo, make sure we don't lose track if it's a macro arg expansion or not.
llvm-svn: 137792
2011-08-17 00:31:14 +00:00
Chandler Carruth f87d6c00e7 Switch this code to use the more idiomatic 'dyn_cast' pattern.
llvm-svn: 137780
2011-08-16 22:30:10 +00:00
Eric Christopher 43b1188a71 Migrate test from llvm/test/FrontendC++.
llvm-svn: 137773
2011-08-16 21:41:54 +00:00
Eric Christopher ed78181605 Migrate from llvm/test/FrontendC++ and FileCheckize.
llvm-svn: 137772
2011-08-16 21:41:52 +00:00
Eric Christopher 77214ad172 Migrate from llvm/test/FrontendC++.
llvm-svn: 137771
2011-08-16 21:41:50 +00:00
Eric Christopher 38a7c55cae Migrate test from llvm/test/FrontendC++ and FileCheckize.
llvm-svn: 137770
2011-08-16 21:41:48 +00:00
Eric Christopher 88fa0f0eb7 Migrate test from llvm/test/FrontendC++.
llvm-svn: 137769
2011-08-16 21:41:46 +00:00
Eric Christopher 3f98c99b07 Migrate from llvm/test/FrontendC++.
llvm-svn: 137768
2011-08-16 21:41:44 +00:00
Eric Christopher 82da54d872 Migrate from llvm/test/FrontendC++.
llvm-svn: 137767
2011-08-16 21:41:41 +00:00
Eric Christopher 2e4877fcb2 Migrate test from llvm/test/FrontendC++.
llvm-svn: 137766
2011-08-16 21:41:40 +00:00
Eric Christopher f1b912b88e Migrate from llvm/test/FrontendC++.
llvm-svn: 137765
2011-08-16 21:41:38 +00:00
Eric Christopher 74733d2e12 Migrate varargs.cpp from llvm/test/FrontendC++.
llvm-svn: 137764
2011-08-16 21:41:35 +00:00
Eric Christopher 9eeae42a6e Migrate weak-external.cpp from llvm/test/FrontendC++.
llvm-svn: 137763
2011-08-16 21:41:33 +00:00
Eric Christopher 148bdfa58a Migrate x86-64-abi-sret-vs-2word-struct-param.cpp from
llvm/test/FrontendC++ and FileCheckize.

llvm-svn: 137762
2011-08-16 21:41:31 +00:00
Eric Christopher 8a24ed567c Migrate thunk-linkonce-odr.cpp from llvm/test/FrontendC++.
llvm-svn: 137761
2011-08-16 21:41:26 +00:00
Ted Kremenek e1962328f5 [analyzer] teach ExprEngine about loads from static C++ class fields. Fixes <rdar://problem/9948787>.
llvm-svn: 137760
2011-08-16 21:37:52 +00:00
Jordy Rose 59cce71af6 [analyzer] Overhaul of checker registration in preparation for basic plugin support. Removes support for checker groups (we can add them back in later if we decide they are still useful), and -analyzer-checker-help output is a little worse for the time being (no packages).
llvm-svn: 137758
2011-08-16 21:24:21 +00:00
Devang Patel 0e3a9f645b Robustify test, there is no need to check metadata number which can change.
llvm-svn: 137752
2011-08-16 21:01:06 +00:00
Devang Patel ffa30ab216 Finalize debug info after all deferred globals are emitted.
llvm-svn: 137750
2011-08-16 20:58:22 +00:00
Anna Zaks a06421a02c MacOSKeychainAPIChecker: Turn it on by default.
llvm-svn: 137740
2011-08-16 20:02:05 +00:00
Jim Grosbach acb07b599c Update createMCAsmParser() to match r137735.
llvm-svn: 137736
2011-08-16 18:33:55 +00:00
Anna Zaks 01ae1e1197 MacOSKeychainAPIChecker: Do not report double allocation if first allocation returned an error.
llvm-svn: 137720
2011-08-16 16:30:24 +00:00
Ted Kremenek 31fdb61618 [analyzer] Enhance ConditionVisitor to handle arbitrary ValueDecls in binary expressions, and also handle inverting the order of comparison when the named decl appears on the RHS.
llvm-svn: 137714
2011-08-16 10:57:37 +00:00
NAKAMURA Takumi f665ce60c2 CMake: "clang-test" may not depend on check.deps.
...I believe it would not break anything...

FIXME: "check-all" may not be generated w/o LLVM_INCLUDE_TESTS.
llvm-svn: 137709
2011-08-16 03:45:31 +00:00
Ted Kremenek 01401a54f8 [analyzer] fix operation inversion calculation in ConditionVisitor.
llvm-svn: 137708
2011-08-16 03:44:38 +00:00
Ted Kremenek 667417ef9c [analyzer] Enhance ConditionVisitor to understand eagerly evaluated (simple) binary conditions, and teach it to only focus on constraint changes.
llvm-svn: 137705
2011-08-16 01:53:41 +00:00
Ted Kremenek b1bf2680f5 [analyzer] add ExprEngine::getEagerlyAssumedTags() to allow externally querying of "eagerly assumed" expressions.
llvm-svn: 137704
2011-08-16 01:53:39 +00:00
Ted Kremenek 9815709cd2 [analyzer] Remove PostStmtCustom ProgramPoint. It can be represented using tagged PostStmts.
llvm-svn: 137697
2011-08-16 00:49:19 +00:00
Argyrios Kyrtzidis e593e7fe6f Fix tests for non-darwin hosts.
llvm-svn: 137688
2011-08-15 23:43:33 +00:00
Eric Christopher d4737be322 Move test from llvm/test/FrontendCXX and update.
llvm-svn: 137682
2011-08-15 23:24:31 +00:00
Anna Zaks 5443a6497b MacOSKeychainAPIChecker: The security API/memory leak checker should always generate regular nodes instead of sink nodes.
llvm-svn: 137681
2011-08-15 23:23:15 +00:00
Ted Kremenek 32b9e234fe Add ProgramState.cpp.
llvm-svn: 137677
2011-08-15 23:05:22 +00:00
Ted Kremenek cb8473643b Add missing header files.
llvm-svn: 137676
2011-08-15 23:03:51 +00:00