Commit Graph

1890 Commits

Author SHA1 Message Date
Douglas Gregor 49b4d73451 Type Type::isRealFloatingType() that vectors are not floating-point
types, updating callers of both isFloatingType() and
isRealFloatingType() accordingly. Caught at least one issue where we
allowed one to declare a vector of vectors (!), along with cleaning up
the standard-conversion logic for C++.

llvm-svn: 106595
2010-06-22 23:07:26 +00:00
Tom Care 6e4ea2db7f Printf format strings: Added some more tests and fixed some minor bugs.
- Precision toStrings shouldn't print a dot when they have no value.
- Length of char length modifier is now returned correctly.
- Added several fixit tests.

Note: fixit tests are currently broken due to a bug in HighlightRange. Marking as XFAIL for now.

M    test/Sema/format-strings-fixit.c
M    include/clang/Analysis/Analyses/PrintfFormatString.h
M    lib/Analysis/PrintfFormatString.cpp

llvm-svn: 106275
2010-06-18 03:02:16 +00:00
Tom Care 9eee328dac Bug 7394 - Fixed toString representation of Precisions in format strings.
M    include/clang/Analysis/Analyses/PrintfFormatString.h
M    lib/Analysis/PrintfFormatString.cpp

llvm-svn: 106245
2010-06-17 22:55:40 +00:00
Tom Care b49ec6907b Bug 7377: Fixed several bad printf format string bugs.
- Added warning for undefined behavior when using field specifier
- Added warning for undefined behavior when using length modifier
- Fixed warnings for invalid flags
- Added warning for ignored flags
- Added fixits for the above warnings
- Fixed accuracy of detecting several undefined behavior conditions
- Receive normal warnings in addition to security warnings when using %n
- Fix bug where '+' flag would remain on unsigned conversion suggestions

Summary of changes:
- Added expanded tests
- Added/expanded warnings
- Added position info to OptionalAmounts for fixits
- Extracted optional flags to a wrapper class with position info for fixits
- Added several methods to validate a FormatSpecifier by component, each checking for undefined behavior
- Fixed conversion specifier checking to conform to C99 standard
- Added hooks to detect the invalid states in CheckPrintfHandler::HandleFormatSpecifier

Note: warnings involving the ' ' (space) flag are temporarily disabled until whitespace highlighting no longer triggers assertions. I will make a post about this on cfe-dev shortly.

M    test/Sema/format-strings.c
M    include/clang/Basic/DiagnosticSemaKinds.td
M    include/clang/Analysis/Analyses/PrintfFormatString.h
M    lib/Analysis/PrintfFormatString.cpp
M    lib/Sema/SemaChecking.cpp

llvm-svn: 106233
2010-06-17 19:00:27 +00:00
Alexis Hunt c675ec09f0 Update CMake build for new attribute changes.
llvm-svn: 106188
2010-06-17 00:37:02 +00:00
Ted Kremenek 64c235e4c6 Extend format string type-checking to include '%p'. Fixes remaining cases PR 4468.
llvm-svn: 106151
2010-06-16 21:23:04 +00:00
Tom Care 00554634db Small fixes regarding printf fix suggestions.
- Added some handling of flags that become invalid when changing the conversion specifier.
- Changed fixit behavior to remove unnecessary length modifiers.
- Separated some tests out and added some comments.

modified:
  lib/Analysis/PrintfFormatString.cpp
  test/Sema/format-strings-fixit.c

llvm-svn: 105807
2010-06-11 04:22:02 +00:00
Douglas Gregor b4e3533ce1 Fix a typo that breaks the GCC build. Turns out that Clang isn't
diagnosing this code as an error when it should, so I've filed
http://llvm.org/bugs/show_bug.cgi?id=7325. 

llvm-svn: 105683
2010-06-09 05:25:34 +00:00
Tom Care b704270779 Added FixIt support to printf format string checking.
- Refactored LengthModifier to be a class.
- Added toString methods in all member classes of FormatSpecifier.
- FixIt suggestions keep user specified flags unless incorrect.

Limitations:
- The suggestions are not conversion specifier sensitive. For example, if we have a 'pad with zeroes' flag, and the correction is a string conversion specifier, we do not remove the flag. Clang will warn us on the next compilation.

A    test/Sema/format-strings-fixit.c
M    include/clang/Analysis/Analyses/PrintfFormatString.h
M    lib/Analysis/PrintfFormatString.cpp
M    lib/Sema/SemaChecking.cpp

llvm-svn: 105680
2010-06-09 04:11:11 +00:00
Daniel Dunbar ee6b692551 Makefiles: Set Clang CPP compiler flags in a single location, instead of scattered throughout the project Makefiles.
llvm-svn: 105638
2010-06-08 20:44:43 +00:00
Daniel Dunbar e6c1daa8fd Makefile: Switch Clang Makefiles to always include the top-level Clang Makefile.
- This eliminates most dependencies on how Clang is installed relative to LLVM.

llvm-svn: 105637
2010-06-08 20:34:18 +00:00
Jordy Rose 2e22268904 Assignments to reference variables shouldn't kill the variable.
llvm-svn: 105452
2010-06-04 01:14:56 +00:00
Zhongxing Xu ea9fcffe03 Make addStmt always add stmt. Delegate other cases to Visit() directly.
llvm-svn: 105384
2010-06-03 06:43:23 +00:00
Zhongxing Xu 41cdf585c2 CFG: add all LHS of assingments as lvalue. This improves support for C++ reference. Patch by Jordy.
llvm-svn: 105383
2010-06-03 06:23:18 +00:00
Alexis Hunt ed05325dbe Convert DeclNodes to use TableGen.
The macros required for DeclNodes use have changed to match the use of
StmtNodes. The FooFirst enumerator constants have been named firstFoo
to match usage elsewhere.

llvm-svn: 105165
2010-05-30 07:21:58 +00:00
Ted Kremenek 304a9537e1 Fix crash in CFG construction for 'break' statements appearing in statement expressions
within the increment code of a for loop.

llvm-svn: 104375
2010-05-21 20:30:15 +00:00
Ted Kremenek ecc31c93c2 Don't add a null successor to a CFGBlock when the contents of an @synchronized statement is empty.
Fixes <rdar://problem/7979430>.

llvm-svn: 103717
2010-05-13 16:38:08 +00:00
Douglas Gregor ecc60b99f9 Unbreak CMake build.
llvm-svn: 103077
2010-05-05 05:41:05 +00:00
Ted Kremenek bc1416dcad Add null check in CFGBuilder::VisitStmt() to make CFG construction
more resilient to bad code.

llvm-svn: 102793
2010-04-30 22:25:53 +00:00
Ted Kremenek 989da5eeff Fix CFG crasher involving statement expressions reported in PR 6938.
llvm-svn: 102576
2010-04-29 01:10:26 +00:00
Zhongxing Xu b5e94ac97d Use direct assignment instead of user defined conversion.
llvm-svn: 101236
2010-04-14 05:50:04 +00:00
Zhongxing Xu 7e61217d86 CFGBuilder: always add C++ member call expr as block-level expr.
llvm-svn: 101127
2010-04-13 09:38:01 +00:00
Ted Kremenek 5868ec6e3d Fix CFG bug where bases of member expressions were not always evaluated in a lvalue context. Fixes <rdar://problem/7813989>.
llvm-svn: 100966
2010-04-11 17:02:10 +00:00
Ted Kremenek 66de60376c Fix bug in AddStmtChoice:asLValue() where 'AsLValueNotAlwaysAdd' would not be treated as indicating an lvalue.
llvm-svn: 100965
2010-04-11 17:02:04 +00:00
Ted Kremenek d2ba1f9ff0 Sort visitor methods. No functionality change.
llvm-svn: 100964
2010-04-11 17:01:59 +00:00
Rafael Espindola c50c27cca8 the big refactoring bits of PR3782.
This introduces FunctionType::ExtInfo to hold the calling convention and the
noreturn attribute. The next patch will extend it to include the regparm
attribute and fix the bug.

llvm-svn: 99920
2010-03-30 20:24:48 +00:00
Rafael Espindola 8756268ee5 Be a bit more consistent in using operator->
This patch moves some methods from QualType to Type and changes the users to
use -> instead of .

llvm-svn: 99805
2010-03-29 03:39:46 +00:00
Ted Kremenek 186508c7d6 Fix '+=' accumulation error when parsing numeric amounts in a format string.
llvm-svn: 99479
2010-03-25 03:59:09 +00:00
Ted Kremenek 0b40532b5e Only perform CFG-based warnings on 'static inline' functions that
are called (transitively) by regular functions/blocks within a
translation untion.

llvm-svn: 99233
2010-03-23 00:13:23 +00:00
Jeffrey Yasskin f6442f80cb Allow users to set CPPFLAGS and CXXFLAGS on the make command line.
Tested: make CPPFLAGS=-m64 CXXFLAGS=-m64 -j8 && (cd tools/clang;make test)
llvm-svn: 98399
2010-03-12 22:55:16 +00:00
Ted Kremenek 575398e29b When computing in AnalysisContext the variables referenced
by a block, also look at the contained blocks.

llvm-svn: 98111
2010-03-10 00:18:11 +00:00
Benjamin Kramer a3b13411fa Simplify code a bit and remove unneeded semicolons.
llvm-svn: 97654
2010-03-03 16:28:47 +00:00
Ted Kremenek 0f0883b918 Fix an algorithmic bug in LiveVariables pointed out by Zhongxing.
If an initializer in a DeclStmt references the declared variable, that
extends the liveness of that variable.

llvm-svn: 97624
2010-03-03 01:17:41 +00:00
Ted Kremenek 5d2bb1b9b3 [CFG]
After discussion with Zhongxing, don't force the initializer of DeclStmts to be
block-level expressions.

This led to some interesting fallout:

[UninitializedValues]

Always visit the initializer of DeclStmts (do not assume they are block-level expressions).

[BasicStore]

With initializers of DeclStmts no longer block-level expressions, this causes self-referencing initializers (e.g. 'int x = x') to no longer cause the initialized variable to be live before the DeclStmt.  While this is correct, it caused BasicStore::RemoveDeadBindings() to prune off the values of these variables from the initial store (where they are set to uninitialized).  The fix is to back-port some (and only some) of the lazy-binding logic from RegionStore to
BasicStore.  Now the default values of local variables are determined lazily as opposed
to explicitly initialized.

llvm-svn: 97591
2010-03-02 21:43:54 +00:00
Zhongxing Xu d497e126cb Register all parameters even if they didn't occur in the function body.
We may query their liveness because they are added to store when passing
argument values.

llvm-svn: 97562
2010-03-02 10:08:30 +00:00
Ted Kremenek 80263e5905 Allow a '0' precision in format strings (as the man page says it is okay).
Fixes <rdar://problem/7700339>.

llvm-svn: 97482
2010-03-01 19:22:33 +00:00
Ted Kremenek d166819c26 For printf format string checking, add support for positional format strings.
Along the way, coelesce some of the diagnostics.

llvm-svn: 97297
2010-02-27 01:41:03 +00:00
Ted Kremenek 4a49d9818b For printf format string checking, move the tracking of the data argument index out of
Sema and into analyze_printf::ParseFormatString().  Also use a bitvector to determine
what arguments have been covered (instead of just checking to see if the last argument consumed is the max argument).  This is prep. for support positional arguments (an IEEE extension).

llvm-svn: 97248
2010-02-26 19:18:41 +00:00
Zhongxing Xu a396e617b5 Always add CallExpr as block-level expression. Inline-based interprocedural
analysis needs this.

llvm-svn: 97014
2010-02-24 02:19:28 +00:00
Ted Kremenek 74a4ce7f1e Add support for '%C' and '%S' printf conversion specifiers.
llvm-svn: 97005
2010-02-24 00:05:54 +00:00
Ted Kremenek 552eeaa93e Move the rest of the unreachable code analysis from libSema
to libAnalysis (with only the error reporting in libSema).

llvm-svn: 96893
2010-02-23 05:59:20 +00:00
Ted Kremenek 7296de9ae3 Start moving some of the logic for the unreachable code analysis out of libSema
and into libAnalysis.

llvm-svn: 96872
2010-02-23 02:39:16 +00:00
Daniel Dunbar 260918ce5c Revert "Simplify code: Succ is guaranteed to be not NULL.", which turns out to
not be guaranteed.

llvm-svn: 96782
2010-02-22 05:58:59 +00:00
Zhongxing Xu d39620c451 Simplify code: Succ is guaranteed to be not NULL.
llvm-svn: 96772
2010-02-22 02:59:27 +00:00
Zhongxing Xu 86bab2cddd Add a utility method.
llvm-svn: 96471
2010-02-17 08:45:06 +00:00
Ted Kremenek c8b188d541 Refactor the logic for printf argument type-checking into analyze_printf::ArgTypeResult.
Implement printf argument type checking for '%s'.

Fixes <rdar://problem/3065808>.

llvm-svn: 96310
2010-02-16 01:46:59 +00:00
Ted Kremenek 2a0cd59f8e Convert tabs to spaces.
llvm-svn: 95621
2010-02-09 00:04:09 +00:00
Ted Kremenek 5abd69d946 Teach RegionStore::InvalidateRegions() to also invalidate static variables referenced by blocks.
llvm-svn: 95459
2010-02-06 00:30:00 +00:00
Ted Kremenek 1de1707bfc Move ParseFormatString() and FormatStringHandler back into the analyze_printf namespace.
llvm-svn: 95324
2010-02-04 20:46:58 +00:00
Ted Kremenek 016b605266 Add format string type checking support for 'long double'.
llvm-svn: 95026
2010-02-01 23:23:50 +00:00