Commit Graph

2430 Commits

Author SHA1 Message Date
Jordan Rose a7d03840e6 Excise <cctype> from Clang (except clang-tblgen) in favor of CharInfo.h.
Nearly all of these changes are one-to-one replacements; the few that
aren't have to do with custom identifier validation.

llvm-svn: 174768
2013-02-08 22:30:41 +00:00
Ted Kremenek 7d86b9ce1e Add note why we used a switch.
llvm-svn: 174449
2013-02-05 22:03:14 +00:00
Ted Kremenek 8ae67871b4 Change subexpressions to be visited in the CFG from left-to-right.
This is a more natural order of evaluation, and it is very important
for visualization in the static analyzer.  Within Xcode, the arrows
will not jump from right to left, which looks very visually jarring.
It also provides a more natural location for dataflow-based diagnostics.

Along the way, we found a case in the analyzer diagnostics where we
needed to indicate that a variable was "captured" by a block.

-fsyntax-only timings on sqlite3.c show no visible performance change,
although this is just one test case.

Fixes <rdar://problem/13016513>

llvm-svn: 174447
2013-02-05 22:00:19 +00:00
Anna Zaks 064185a8ce [analyzer] add comment
llvm-svn: 174435
2013-02-05 19:52:26 +00:00
NAKAMURA Takumi cc4aaef0f2 clang/Analysis: Fix r174245, a valgrind error in AnalysisDeclContext::getBody(bool &IsAutosynthesized), to initialize IsAutosynthesized explicitly.
llvm-svn: 174303
2013-02-04 05:06:21 +00:00
Anna Zaks 00c69a597c [analyzer] Always inline functions with bodies generated by BodyFarm.
Inlining these functions is essential for correctness. We often have
cases where we do not inline calls. For example, the shallow mode and
when reanalyzing previously inlined ObjC methods as top level.

llvm-svn: 174245
2013-02-02 00:30:04 +00:00
Ted Kremenek 7ba78c679c -Wuninitialized: warn about uninitialized values resulting from ?: that evaluate to lvalues (in C++).
llvm-svn: 172875
2013-01-19 00:25:06 +00:00
DeLesley Hutchins 9fa426a666 Thread-safety analysis: ignore edges from throw expressions in CFG.
llvm-svn: 172858
2013-01-18 22:15:45 +00:00
Jordan Rose 1eb342920b Format strings: don't ever convert %+d to %lu.
Presumably, if the printf format has the sign explicitly requested, the user
wants to treat the data as signed.

This is a fix-up for r172739, and also includes several test changes that
didn't make it into that commit.

llvm-svn: 172762
2013-01-17 22:34:10 +00:00
Jordan Rose aa7a3b3e75 Format strings: correct signedness if already correcting width (%d,%u).
It is valid to do this:
  printf("%u", (int)x);

But if we see this:
  printf("%lu", (int)x);

...our fixit should suggest %d, not %u.

llvm-svn: 172739
2013-01-17 18:47:16 +00:00
Richard Smith 10876ef571 Implement C++11 semantics for [[noreturn]] attribute. This required splitting
it apart from [[gnu::noreturn]] / __attribute__((noreturn)), since their
semantics are not equivalent (for instance, we treat [[gnu::noreturn]] as
affecting the function type, whereas [[noreturn]] does not).

llvm-svn: 172691
2013-01-17 01:30:42 +00:00
Dmitri Gribenko f857950d39 Remove useless 'llvm::' qualifier from names like StringRef and others that are
brought into 'clang' namespace by clang/Basic/LLVM.h

llvm-svn: 172323
2013-01-12 19:30:44 +00:00
Enea Zaffanella 392291f7dc Test commit.
llvm-svn: 172195
2013-01-11 11:37:08 +00:00
Will Dietz df9a2bbcb1 CFG.cpp: Fix wrapping logic when printing block preds/succs.
First check only wrapped with i==8, second wrapped at i==2,8,18,28,...
This fix restores the intended behavior: i==8,18,28,...

Found with -fsanitize=integer.

llvm-svn: 171718
2013-01-07 09:51:17 +00:00
Richard Smith 2bf7fdb723 s/CPlusPlus0x/CPlusPlus11/g
llvm-svn: 171367
2013-01-02 11:42:31 +00:00
Nico Weber a2a0eb940a ArrayRefize a CompoundStmt constructor.
llvm-svn: 171238
2012-12-29 20:03:39 +00:00
Anna Zaks 4127750ed8 [analyzer] Fix typos.
llvm-svn: 170907
2012-12-21 17:27:04 +00:00
Anna Zaks 1ee76c1bae [analyzer] Re-apply r170826 and make the dumping of the GallGraph
deterministic.

Commit message for r170826:

[analyzer] Traverse the Call Graph in topological order.

Modify the call graph by removing the parentless nodes. Instead all
nodes are children of root to ensure they are all reachable. Remove the
tracking of nodes that are "top level" or global. This information is
not used and can be obtained from the Decls stored inside
CallGraphNodes.

Instead of existing ordering hacks, analyze the functions in topological
order over the Call Graph.

Together with the addition of devirtualizable ObjC message sends and
blocks to the call graph, this gives around 6% performance improvement
on several large ObjC benchmarks.

llvm-svn: 170906
2012-12-21 17:27:01 +00:00
Rafael Espindola e7ec558f25 Revert r170826. The output of
./bin/clang -cc1 -internal-isystem /home/espindola/llvm/build/lib/clang/3.3/include/ -analyze -analyzer-checker=debug.DumpCallGraph /home/espindola/llvm/clang/test/Analysis/debug-CallGraph.c -fblocks

changes in each run.

llvm-svn: 170829
2012-12-21 01:30:23 +00:00
Anna Zaks 77ca7f1bbe [analyzer] Traverse the Call Graph in topological order.
Modify the call graph by removing the parentless nodes. Instead all
nodes are children of root to ensure they are all reachable. Remove the
tracking of nodes that are "top level" or global. This information is
not used and can be obtained from the Decls stored inside
CallGraphNodes.

Instead of existing ordering hacks, analyze the functions in topological
order over the Call Graph.

Together with the addition of devirtualizable ObjC message sends and
blocks to the call graph, this gives around 6% performance improvement
on several large ObjC benchmarks.

llvm-svn: 170826
2012-12-21 01:19:22 +00:00
Anna Zaks 5c32dfc5fb [analyzer] Add blocks and ObjC messages to the call graph.
This paves the road for constructing a better function dependency graph.
If we analyze a function before the functions it calls and inlines,
there is more opportunity for optimization.

Note, we add call edges to the called methods that correspond to
function definitions (declarations with bodies).

llvm-svn: 170825
2012-12-21 01:19:15 +00:00
DeLesley Hutchins 0cfa1a5a1d Thread-safety analysis: check member access on guarded non-primitive types.
llvm-svn: 169669
2012-12-08 03:46:30 +00:00
Ted Kremenek 3e871d8cf6 Use the BlockDecl captures list to infer the direct captures for a BlockDataRegion. Fixes <rdar://problem/12415065>.
We still need to do a recursive walk to determine all static/global variables
referenced by a block, which is needed for region invalidation.

llvm-svn: 169481
2012-12-06 07:17:26 +00:00
Jordan Rose 0e5badd93b Format strings: offer a cast to 'unichar' for %C in Objective-C contexts.
For most cases where a conversion specifier doesn't match an argument,
we usually guess that the conversion specifier is wrong. However, if
the argument is an integer type and the specifier is %C, it's likely
the user really did mean to print the integer as a character.

(This is more common than %c because there is no way to specify a unichar
literal -- you have to write an integer literal, such as '0x2603',
and then cast it to unichar.)

This does not change the behavior of %S, since there are fewer cases
where printing a literal Unicode *string* is necessary, but this could
easily be changed in the future.

<rdar://problem/11982013>

llvm-svn: 169400
2012-12-05 18:44:49 +00:00
Jordan Rose 6aaa87e0d2 Format strings: the correct conversion for 'char' is %c, not %d or %hhd.
We tried to account for 'uint8_t' by saying that /typedefs/ of 'char'
should be corrected as %hhd rather than %c, but the condition was wrong.

llvm-svn: 169397
2012-12-05 18:44:37 +00:00
DeLesley Hutchins f489d2b86c Thread-safety analysis: check locks on method calls, operator=, and
copy constructors.

llvm-svn: 169350
2012-12-05 01:20:45 +00:00
DeLesley Hutchins 5df82f2155 Thread Safety Analysis: refactor to make more methods accept const pointers,
adjust checkAccess.  No change in functionality.

llvm-svn: 169348
2012-12-05 00:52:33 +00:00
Chandler Carruth 3a02247dc9 Sort all of Clang's files under 'lib', and fix up the broken headers
uncovered.

This required manually correcting all of the incorrect main-module
headers I could find, and running the new llvm/utils/sort_includes.py
script over the files.

I also manually added quite a few missing headers that were uncovered by
shuffling the order or moving headers up to be main-module-headers.

llvm-svn: 169237
2012-12-04 09:13:33 +00:00
Benjamin Kramer 444a1304ad Include pruning and general cleanup.
llvm-svn: 169095
2012-12-01 17:12:56 +00:00
Benjamin Kramer ea70eb30a0 Pull the Attr iteration parts out of Attr.h, so including DeclBase.h doesn't pull in all the generated Attr code.
Required to pull some functions out of line, but this shouldn't have a perf impact.
No functionality change.

llvm-svn: 169092
2012-12-01 15:09:41 +00:00
Ted Kremenek 778a6ed358 Further reduce "-fsyntax-only -Wuninitialized" time on sqlite3.c by another 2.5% using intelligent pruning of blocks during the final reporting pass.
llvm-svn: 168257
2012-11-17 07:18:30 +00:00
Ted Kremenek 4431a03928 Switch -Wuninitialized to use a reverse-post order traversal as
an initial baseline for enqueued blocks, but use a simple DFS stack
for propagating changes quickly up back edges.

This provides a 3.5% reduction in -fsyntax-only time on sqlite3.c.

llvm-svn: 168241
2012-11-17 02:00:00 +00:00
Ted Kremenek e6ee671e16 Fix bad CFG construction bug when handling C++ 'try' statements.
This code assigned the last created CFGBlock* to the variable 'Block',
which is a scratch variable which is null'ed out after a block is
completed.  By assigning the last created block to 'Block', we start
editing a completed block, inserting CFGStmts that should be in
another block.  This was the case with 'try'.  The test case that
showed this had a while loop inside a 'try', and the logic before
the while loop was being included as part of the "condition block"
for the loop.  This showed up as a bogus dead store, but could
have lots of implications.

Turns out this bug was replicated a few times within CFG.cpp, so
I went and fixed up those as well.

llvm-svn: 167788
2012-11-13 00:12:13 +00:00
Anna Zaks 44dc91b4df [analyzer] add LocationContext::inTopFrame() helper.
llvm-svn: 167351
2012-11-03 02:54:16 +00:00
Ted Kremenek b9f7aa46dd Fix potential null deference in CFG printer.
llvm-svn: 165836
2012-10-12 22:56:31 +00:00
Ted Kremenek 451c4d51ae Remove dead store.
llvm-svn: 165835
2012-10-12 22:56:26 +00:00
Ted Kremenek 6fdefb5495 Conditionally use an integral cast for BodyFarm support for OSAtomicCompareAndSwap if the return type is not a boolean.
llvm-svn: 165774
2012-10-12 00:18:19 +00:00
Ted Kremenek 089ffd0889 Switch over to BodyFarm implementation of OSAtomicCompareAndSwap and
objc_atomicCompareAndSwap.

llvm-svn: 165743
2012-10-11 20:58:18 +00:00
DeLesley Hutchins 1fe885614d Thread-safety analysis: allow attributes on constructors to refer to 'this'.
llvm-svn: 165339
2012-10-05 22:38:19 +00:00
Lang Hames 5de91cc35f Add FP_CONTRACT support for clang.
Clang will now honor the FP_CONTRACT pragma and emit LLVM
fmuladd intrinsics for expressions of the form A * B + C (when they occur in a
single statement).

llvm-svn: 164989
2012-10-02 04:45:10 +00:00
Benjamin Kramer 5721daae02 Avoid malloc thrashing in the uninitialized value analysis.
- The size of the packed vector is often small, save mallocs using SmallBitVector.
- Copying SmallBitVectors is also cheap, remove a level of indirection.

llvm-svn: 164827
2012-09-28 16:44:29 +00:00
Ted Kremenek 3d0ec38cb4 Add clarifying comment.
llvm-svn: 164557
2012-09-24 21:17:14 +00:00
Ted Kremenek e7ad535e66 Experiment in BodyFarm of structuring AST creation calls in a hierarchy,
so that they visually look like an AST dump.

llvm-svn: 164401
2012-09-21 18:33:56 +00:00
Ted Kremenek f465dc1553 Create helper method in BodyFarm for creating simple assignments.
llvm-svn: 164400
2012-09-21 18:33:54 +00:00
Ted Kremenek dff3553e3c Add helper method in BodyFarm to create unary dereferences.
llvm-svn: 164399
2012-09-21 18:33:52 +00:00
Ted Kremenek ca90ea5ed0 Add helper method to BodyFarm for creating lvalue-to-rvalue conversions.
llvm-svn: 164397
2012-09-21 18:13:27 +00:00
Ted Kremenek 69bcb82c59 Add helper method to BodyFarm for creatinging integral casts.
llvm-svn: 164396
2012-09-21 18:13:23 +00:00
DeLesley Hutchins 10958cae09 Thread-safety analysis: better handling of unreachable blocks. Fixes a bug
where a call to function marked 'noreturn' is followed by unreachable
implicit destructor calls.

llvm-svn: 164394
2012-09-21 17:57:00 +00:00
Ted Kremenek 7241813bd7 Use helper method to create DeclRefExprs in BodyFarm, hopefully allevating
them being correctly constructed.

llvm-svn: 164392
2012-09-21 17:54:35 +00:00
Ted Kremenek 2b5c83ca8f Add some structuring comments. No functionality change.
llvm-svn: 164391
2012-09-21 17:54:32 +00:00