David Blaikie [Sun, 22 Jan 2012 02:31:55 +0000 (02:31 +0000)]
Fix -Wswitch to warn about out of bounds enum cases even when there's a default
For consistency with GCC & reasonable sanity. The FIXME suggests that the
original author was perhaps using the default check for some other purpose,
not realizing the more obvious limitation/false-negatives it creates, but this
doesn't seem to produce any regressions & fixes the included test.
David Blaikie [Sun, 22 Jan 2012 01:58:03 +0000 (01:58 +0000)]
Move -Wswitch-enum to -Wswitch
This matches GCC's documented (& actual) behavior. What Clang had implemented
as -Wswitch-enum was actually GCC's -Wswitch behavior. -Wswitch is on by
default (part of -Wall) and warns if a switch-over-enum, without a default
case, covers all enum values.
-Wswitch-enum, on the other hand, does not have the default clause and should
fire even in the presence of a default. This warning is off by default.
With this change the -Wswitch-enum flag is off-by-default in Clang but has no
functionality at the moment. I'll add that in a future commit.
Francois Pichet [Sat, 21 Jan 2012 23:26:50 +0000 (23:26 +0000)]
In Microsoft Mode, disable the C++11 strict integral conversion rules for enumerator that were introduced with r148439. Otherwise MSVC headers won't compile in C++ 11 mode.
David Blaikie [Sat, 21 Jan 2012 18:12:07 +0000 (18:12 +0000)]
Add -Wswitch-enum-redundant-default.
This warning acts as the complement to the main -Wswitch-enum warning (which
warns whenever a switch over enum without a default doesn't cover all values of
the enum) & has been an an-doc coding convention in LLVM and Clang in my
experience. The purpose is to ensure there's never a "dead" default in a
switch-over-enum because this would hide future -Wswitch-enum errors.
The name warning has a separate flag name so it can be disabled but it's grouped
under -Wswitch-enum & is on-by-default because of this.
The existing violations of this rule in test cases have had the warning disabled
& I've added a specific test for the new behavior (many negative cases already
exist in the same test file - and none regressed - so I didn't add more).
Reviewed by Ted Kremenek ( http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120116/051690.html )
Anna Zaks [Sat, 21 Jan 2012 05:07:33 +0000 (05:07 +0000)]
[analyzer] Make VLA checker taint aware.
Also, slightly modify the diagnostic message in ArrayBound and DivZero (still use 'taint', which might not mean much to the user, but plan on changing it later).
Eli Friedman [Sat, 21 Jan 2012 04:52:58 +0000 (04:52 +0000)]
Add an assertion that our use-marking actually covers all uses of a variable. The assertion doesn't cover quite as much as it should, but it's a good start, at least.
Richard Trieu [Sat, 21 Jan 2012 02:59:18 +0000 (02:59 +0000)]
Fix code so that a SkipUntil will ignore semicolons when skipping a
function body. This keeps the brace count accurate to prevent
additional errors. Also, moved the caret from the brace to the function
name.
Code:
class F{ int Foo{ return 1; } };
Fixed error:
parameters.cc:1:14: error: function definition does not declare parameters
class F{ int Foo{ return 1; } };
^
1 error generated.
Old errors:
parameters.cc:1:17: error: function definition does not declare parameters
class F{ int Foo{ return 1; } };
^
parameters.cc:1:30: error: expected ';' after class
class F{ int Foo{ return 1; } };
^
;
parameters.cc:1:31: error: expected external declaration
class F{ int Foo{ return 1; } };
^
3 errors generated.
Douglas Gregor [Sat, 21 Jan 2012 00:43:38 +0000 (00:43 +0000)]
Fix the code completion string for variadic macros with more than one
argument, which was broken and very ugly (and even had a test case to
make *sure* it was broken and ugly). Fixes <rdar://problem/10609117>.
Eric Christopher [Fri, 20 Jan 2012 22:10:15 +0000 (22:10 +0000)]
When adding types to the context chain for record types, just emit
a forward declaration unless we already have a type. We can fill it in
later if it's actually used.
Enhance Lexer::makeFileCharRange to check for ranges inside a macro argument
expansion, in which case it returns a file range in the location where the
argument was spelled.
Douglas Gregor [Fri, 20 Jan 2012 16:28:04 +0000 (16:28 +0000)]
Extract the (InputKind, std::string) pair used to describe inputs to
the front end into its own class, FrontendInputFile, to make it easier
to introduce new per-input data. No functionality change.
Ted Kremenek [Fri, 20 Jan 2012 01:44:29 +0000 (01:44 +0000)]
Turn 'SecuritySyntaxChecker' into a "meta" security checker for insecure APIs. Now
multiple checks are exposed as separate checkers, but CheckerManager only creates
one Checker object.
Eli Friedman [Fri, 20 Jan 2012 01:26:23 +0000 (01:26 +0000)]
Remove PotentiallyPotentiallyEvaluated, and replace it with a much simpler and less error-prone way of handling the relevant cases. Towards marking of whether a declaration is used more accurately.
Richard Smith [Wed, 18 Jan 2012 23:55:52 +0000 (23:55 +0000)]
constexpr: converted constant expression handling for enumerator values, case
values and non-type template arguments of integral and enumeration types.
This change causes some legal C++98 code to no longer compile in C++11 mode, by
enforcing the C++11 rule that narrowing integral conversions are not permitted
in the final implicit conversion sequence for the above cases.
Kaelyn Uhrain [Wed, 18 Jan 2012 21:41:41 +0000 (21:41 +0000)]
Convert SemaDecl.cpp to pass callback objects to CorrectTypo.
Includes tests highlighting the cases where accuracy has improved
(there is one call that does no filtering beyond selecting the set
of allowed keywords, and one call that only triggers for ObjC code
for which a test by someone who knows ObjC would be welcome). Also
fixes a small typo in one of the suggestion messages, and drops a
malformed "expected-note" for a suggestion that did not occur even
when the malformed note was committed as r145930.
Douglas Gregor [Wed, 18 Jan 2012 20:56:22 +0000 (20:56 +0000)]
Optimize unqualified/global name lookup in modules by introducing a
generational scheme for identifiers that avoids searching the hash
tables of a given module more than once for a given
identifier. Previously, loading any new module invalidated all of the
previous lookup results for all identifiers, causing us to perform the
lookups repeatedly.
Seth Cantrell [Wed, 18 Jan 2012 12:27:04 +0000 (12:27 +0000)]
Improves support for Unicode in character literals
Updates ProcessUCNExcape() for C++. C++11 allows UCNs in character
and string literals that represent control characters and basic
source characters. Also C++03 allows UCNs that refer to surrogate
codepoints.
UTF-8 sequences in character literals are now handled as single
c-chars.
Added error for multiple characters in Unicode character literals.
Added errors for when a the execution charset encoding of a c-char
cannot be represented as a single code unit in the associated
character type. Note that for the purposes of this error the asso-
ciated character type for a narrow character literal is char, not
int, even though in C narrow character literals have type int.
Kaelyn Uhrain [Wed, 18 Jan 2012 05:58:54 +0000 (05:58 +0000)]
Convert DiagnoseEmptyLookup to use correction callbacks.
No new unit tests yet as there is no behavioral change
(except for slightly more specific filtering in
Sema::ActOnStartOfLambdaDefinition). Tests will be added
as the code paths are traced in greater depth to determine
how to improve the results--there are at least one or two
known bugs that require those improvements. This commit
lays the groundwork for those changes.
Richard Smith [Wed, 18 Jan 2012 05:21:49 +0000 (05:21 +0000)]
Move narrowing conversion detection code from SemaInit to SemaOverload, ready
for it to be used in converted constant expression checking, and fix a couple
of issues:
- Conversion operators implicitly invoked prior to the narrowing conversion
were not being correctly handled when determining whether a constant value
was narrowed.
- For conversions from floating-point to integral types, the diagnostic text
incorrectly always claimed that the source expression was not a constant
expression.
Anna Zaks [Wed, 18 Jan 2012 02:45:11 +0000 (02:45 +0000)]
[analyzer] Taint: warn when tainted data is used to specify a buffer
size (Ex: in malloc, memcpy, strncpy..)
(Maybe some of this could migrate to the CString checker. One issue
with that is that we might want to separate security issues from
regular API misuse.)
Eli Friedman [Wed, 18 Jan 2012 01:05:54 +0000 (01:05 +0000)]
Fix a couple issues where we didn't correctly delay diagnostics in PotentiallyPotentiallyEvaluated contexts. In preparation for making sizeof() PotentiallyPotentiallyEvaluated.
objc-arc: when 'assign' attribute is unspecified,
rely on property's type for its life-time to avoid
bogus warning with -Warc-unsafe-retained-assign.
// rdar://10694932
Sebastian Redl [Tue, 17 Jan 2012 22:49:52 +0000 (22:49 +0000)]
Rename the first of 11 DeduceTemplateArguments overloads.
There are 5 functions of this name in Sema, and 6 more static helpers in
SemaTemplateDeduction.cpp. The Sema functions have jobs like "deduce for
function call", "deduce for taking the address", etc. The static helpers
have jobs like "deduce by comparing two types", "deduce by comparing two
lists of types", "deduce by comparing two template arguments", etc.
The fact that they all are called the same and only differ in two of their
6 or more arguments makes the code using them very hard to read.
Here I rename the one function that concerns me most at the moment, but
as a matter of cleanup, the others will eventually be renamed as well.