Commit Graph

28770 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis b2cf708395 [analyzer] Migrate OSAtomicChecker to CheckerV2.
llvm-svn: 126610
2011-02-28 01:27:02 +00:00
Argyrios Kyrtzidis 0a9ce3ec8f [analyzer] Migrate ArrayBoundCheckerV2 to CheckerV2.
Turns -analyzer-check-buffer-overflows into -analyzer-checker=core.experimental.Overflow

llvm-svn: 126609
2011-02-28 01:26:57 +00:00
Argyrios Kyrtzidis 560bbb1241 [analyzer] Turn -analyzer-stats into -analyzer-checker=debug.Stats
llvm-svn: 126608
2011-02-28 01:26:50 +00:00
Argyrios Kyrtzidis 21c9423ef4 [analyzer] Remove '-analyzer-experimental-checks' flag.
llvm-svn: 126607
2011-02-28 01:26:43 +00:00
Argyrios Kyrtzidis 183f0fb4cf [analyzer] Migrate MallocChecker to CheckerV2.
llvm-svn: 126606
2011-02-28 01:26:35 +00:00
Argyrios Kyrtzidis 4e23dbd0fd [analyzer] Have CheckerManager::registerChecker return a pointer to the checker object and
only allow a checker to be registered once.

llvm-svn: 126605
2011-02-28 01:26:28 +00:00
Chris Lattner dc2cc67e57 remove a bogus assertion, add a comment.
llvm-svn: 126603
2011-02-28 01:06:02 +00:00
Chris Lattner 0709542628 make switch condition constant folding much more aggressive, handling
compound statements and break statements.  This implements enough to 
handle PR9322 and rdar://6970405.

llvm-svn: 126602
2011-02-28 01:02:29 +00:00
Anders Carlsson 246ff3f19f Factor code out into a helper function, shouldUseExceptionTablesForObjCExceptions.
llvm-svn: 126601
2011-02-28 00:44:51 +00:00
Chris Lattner 30db828ce7 fix my containsBreak predicate.
llvm-svn: 126600
2011-02-28 00:42:31 +00:00
Anders Carlsson 6774b1f1c1 Add -fcxx-exceptions to all tests that use C++ exceptions.
llvm-svn: 126599
2011-02-28 00:40:07 +00:00
Anders Carlsson 6dc07d4e56 Get rid of the areExceptionsEnabled() getter from LangOptions.
llvm-svn: 126598
2011-02-28 00:33:03 +00:00
Chris Lattner 0725a8b653 First tiny step to implementing PR9322: build infrastructure for only emitting the
live case of a switch statement when switching on a constant.  This is terribly
limited, but enough to handle the trivial example included.  Before we would 
emit:

define void @test1(i32 %i) nounwind {
entry:
  %i.addr = alloca i32, align 4
  store i32 %i, i32* %i.addr, align 4
  switch i32 1, label %sw.epilog [
    i32 1, label %sw.bb
  ]

sw.bb:                                            ; preds = %entry
  %tmp = load i32* %i.addr, align 4
  %inc = add nsw i32 %tmp, 1
  store i32 %inc, i32* %i.addr, align 4
  br label %sw.epilog

sw.epilog:                                        ; preds = %sw.bb, %entry
  switch i32 0, label %sw.epilog3 [
    i32 1, label %sw.bb1
  ]

sw.bb1:                                           ; preds = %sw.epilog
  %tmp2 = load i32* %i.addr, align 4
  %add = add nsw i32 %tmp2, 2
  store i32 %add, i32* %i.addr, align 4
  br label %sw.epilog3

sw.epilog3:                                       ; preds = %sw.bb1, %sw.epilog
  ret void
}

now we emit:

define void @test1(i32 %i) nounwind {
entry:
  %i.addr = alloca i32, align 4
  store i32 %i, i32* %i.addr, align 4
  %tmp = load i32* %i.addr, align 4
  %inc = add nsw i32 %tmp, 1
  store i32 %inc, i32* %i.addr, align 4
  ret void
}

This improves -O0 compile time (less IR to generate and shove through the code 
generator) and the clever linux kernel people found a way to fail to build if we 
don't do this optimization.  This step isn't enough to handle the kernel case
though.

llvm-svn: 126597
2011-02-28 00:22:07 +00:00
Chris Lattner 29911cc2f5 Add some helper methods that will be used in my next patch.
llvm-svn: 126596
2011-02-28 00:18:40 +00:00
Chris Lattner 80d51eb03a tidy up
llvm-svn: 126595
2011-02-28 00:18:06 +00:00
Chris Lattner 589b989713 add a const version of this accessor.
llvm-svn: 126594
2011-02-28 00:17:41 +00:00
Douglas Gregor 6e068014f0 When we encounter a dependent template name within a
nested-name-specifier, e.g., 

  T::template apply<U>::

represent the dependent template name specialization as a
DependentTemplateSpecializationType, rather than a
TemplateSpecializationType with a dependent TemplateName.

llvm-svn: 126593
2011-02-28 00:04:36 +00:00
Chris Lattner 41c6ab538a Change the interface to ConstantFoldsToSimpleInteger to not encode
a bool + success into one tri-state integer, simplifying things.

llvm-svn: 126592
2011-02-27 23:02:32 +00:00
Douglas Gregor b09518c551 Eliminate a silly little Parse/Sema dance when parsing typename
specifiers such as

  typename T::template apply<U>

Previously, we would turn T::template apply<U> into a
TemplateSpecializationType. Then, we'd reprocess that
TemplateSpecializationType and turn it into either a
TemplateSpecializationType wrapped in an ElaboratedType (when we could
resolve "apply" to a template declaration) or a
DependentTemplateSpecializationType. We now produce the same ASTs but
without generating the intermediate TemplateSpecializationType.

The end goal here is to avoid generating TemplateSpecializationTypes
with dependent template-names, ever. We're not there yet.

llvm-svn: 126589
2011-02-27 22:46:49 +00:00
Benjamin Kramer 6e152156d5 Fix an obvious typo.
GCC -Waddress warns about this but clang doesn't (PR9043).

llvm-svn: 126577
2011-02-27 18:07:41 +00:00
Oscar Fuentes 6401523405 CMake: updated list of installable header files. PR9321.
llvm-svn: 126572
2011-02-27 13:33:31 +00:00
Frits van Bommel ba6ce03e46 Fix this test case for CMake builds after r126502, which sneakily changed the actual executable name to clang-<version>.
llvm-svn: 126560
2011-02-27 01:17:12 +00:00
Daniel Dunbar 160fc36896 cc1: Fix stats printing by default when using -mllvm -stats.
llvm-svn: 126559
2011-02-26 23:17:25 +00:00
Alexis Hunt c5575cced8 Implement delegating constructors partially.
This successfully performs constructor lookup and verifies that a
delegating initializer is the only initializer present.

This does not perform loop detection in the initialization, but it also
doesn't codegen delegating constructors at all, so this won't cause
runtime infinite loops yet.

llvm-svn: 126552
2011-02-26 19:13:13 +00:00
John McCall c57994467b Don't assume that whoever is asking for a message send is going
to give us a non-null return slot.

llvm-svn: 126544
2011-02-26 09:48:59 +00:00
John McCall 71309be80a Zero-initialize the struct-return slot of an Objective-C message
send before making the call.  Fixes rdar://problem/7854674

llvm-svn: 126543
2011-02-26 09:12:15 +00:00
John McCall 8a3c55567e A much-delayed response to Ken Dyck's review: make this somewhat more
char-width agnostic.

llvm-svn: 126542
2011-02-26 08:41:59 +00:00
John McCall 4b13633082 Don't crash during constant-evaluation of 1/(1/0). PR9262.
llvm-svn: 126541
2011-02-26 08:27:17 +00:00
John McCall 53fcbd2718 Pretty up the emission of field l-values and use volatile and TBAA when
loading references as part of that.  Use 'char' TBAA when accessing
(immediate!) fields of a may_alias struct;  fixes PR9307.

llvm-svn: 126540
2011-02-26 08:07:02 +00:00
John McCall bebede4d33 Provide a bit saying that a builtin undergoes custom type-checking, then
don't let calls to such functions go down the normal type-checking path.
Test this out with __builtin_classify_type and __builtin_constant_p.

llvm-svn: 126539
2011-02-26 05:39:39 +00:00
Fariborz Jahanian 8f4903397d Fix objc rewriting bug casting to qualified objective-c pointetr.
// rdar://9056351

llvm-svn: 126536
2011-02-26 01:31:36 +00:00
Fariborz Jahanian f2890fc93f Fix a rewriter bug involving call to property's
block. // rdar://9055596

llvm-svn: 126535
2011-02-26 00:33:41 +00:00
Matt Beaumont-Gay 531c079de8 ASTStmtReader is already a friend of DependentScopeDeclRefExpr, and GCC
doesn't like re-friending.

llvm-svn: 126524
2011-02-25 22:36:42 +00:00
Ted Kremenek e925322f41 Update test cases.
llvm-svn: 126523
2011-02-25 22:19:14 +00:00
Ted Kremenek 5eb4b60734 Tidy up help text in Checkers.td, and rename StackAddrLeakChecker to StackAddrEscapeChecker.
llvm-svn: 126522
2011-02-25 22:00:43 +00:00
Ted Kremenek 27fdf0feda Enhance scan-build to print out available analyses using new checker registration model.
This isn't totally complete.  Right now scan-build uses some heuristics to determine
which checkers are enabled by default, but it cannot always tell which checkers
are not enabled.

llvm-svn: 126521
2011-02-25 22:00:40 +00:00
Daniel Dunbar 5480578d83 Driver: Attmpt to fix some possibly UB that MSVC doesn't care for.
llvm-svn: 126513
2011-02-25 21:20:15 +00:00
Fariborz Jahanian e6b127d7da Sprinkle optional text of the "unavailable' attribute
where ever such attribute causes an error diagnostic.

llvm-svn: 126509
2011-02-25 20:51:14 +00:00
Douglas Gregor 3a43fd645d Push nested-name-specifier source location information into
DependentScopeDeclRefExpr. Plus, give NestedNameSpecifierLoc == and !=
operators, since we're going to need 'em elsewhere.

llvm-svn: 126508
2011-02-25 20:49:16 +00:00
Chandler Carruth 20d0fee3f4 Clean up some gross code in the printer here. No more string stream
silliness, and actually use the existing facilities of raw_ostream to do
escaping.

This will also hopefully fix an assert when building with signed char
(MSVC I think).

llvm-svn: 126505
2011-02-25 20:09:13 +00:00
Chandler Carruth 301416380e Remove the FIXME I introduced last night, and pull the logic for
marking selected overloads into the callers. This allows a few callers
to skip it altogether (they would have anyways because they weren't
interested in successful overloads) or defer until after further checks
take place much like the check required for PR9323 to avoid marking
unused copy constructors.

llvm-svn: 126503
2011-02-25 19:41:05 +00:00
Douglas Gregor be8705bd3f CMake: add version information into the clang executable and libclang
shared library.

llvm-svn: 126502
2011-02-25 19:24:02 +00:00
Matt Beaumont-Gay f4aec20e97 s/clang-cc1/clang_cc1
llvm-svn: 126501
2011-02-25 19:09:01 +00:00
Fariborz Jahanian bff158dc67 Print optional message for attr(unavailable) in C++ mode.
// rdar://9046492

llvm-svn: 126499
2011-02-25 18:38:59 +00:00
Douglas Gregor a6ce608b97 Push nested-name-specifier source-location information into
pseudo-destructor expressions. Also, clean up some
template-instantiation and type-checking issues with
pseudo-destructors.

llvm-svn: 126498
2011-02-25 18:19:59 +00:00
Fariborz Jahanian 40c5e1ada7 Teach objc-rewriter to pass -fobjc-exceptions along.
llvm-svn: 126497
2011-02-25 17:24:55 +00:00
Douglas Gregor c05ba2ef12 Push nested-name-specifier source location information into namespace
aliases.

llvm-svn: 126496
2011-02-25 17:08:07 +00:00
Douglas Gregor 6f8af8ac39 Make sure to give CXXScopeSpec::SetInvalid() a valid source
range. Fixes four new failures in the GCC testsuite.

llvm-svn: 126495
2011-02-25 16:51:05 +00:00
Douglas Gregor 12441b3bc5 Push nested-name-specifier source location information into using directives.
llvm-svn: 126489
2011-02-25 16:33:46 +00:00
Douglas Gregor f29ba48c7f Direct testing of source-location information on using declarations, via libclang
llvm-svn: 126487
2011-02-25 16:13:46 +00:00
Douglas Gregor 1017641937 Switch a few CXXScopeSpec::MakeTrivial() calls over to appropriate
NestedNameSpecifierLoc handling.

llvm-svn: 126486
2011-02-25 16:07:42 +00:00
Douglas Gregor 0499ab6c35 Maintain nested-name-specifier source-location information through
instantiation of using declarations (all three forms).

llvm-svn: 126485
2011-02-25 15:54:31 +00:00
Peter Collingbourne 54f43b87dc Rename test/Sema/expr-comma-c89.c to expr-comma-c99.c. Spotted by
Anton Lokhmotov.

llvm-svn: 126482
2011-02-25 12:37:11 +00:00
Chandler Carruth a28097da4f Rough fix for PR9323 that prevents Clang from marking copy constructor
declarations as referenced when in fact we're not going to even form
a call in the AST. This is significant because we attempt to allow as an
extension classes with intentionally private and undefined copy
constructors to have temporaries bound to references, and so shouldn't
warn about the lack of definition for that copy constructor when the
class is internal.

Doug, John wasn't really satisfied with the presence of overloading at
all. This is a stop-gap and there may be a better solution. If you can
give me some hints for how you'd prefer to see this solved, I'll happily
switch things over.

llvm-svn: 126480
2011-02-25 08:52:25 +00:00
Chandler Carruth ebd3375ba2 Give this warning a flag that can be used to turn it off in old, crufty,
legacy code that contains dead code paths referring to such
declarations.

llvm-svn: 126478
2011-02-25 06:53:20 +00:00
Chandler Carruth 6a4e8e38f2 Add support for ArchLinux, patch by Kevin Winchester.
llvm-svn: 126476
2011-02-25 06:39:53 +00:00
John McCall a2c4e72a55 Formatting, etc.
llvm-svn: 126475
2011-02-25 05:21:17 +00:00
John McCall 1b93f1ba9f Tame an assert; the scope depth of a jump destination does not
necessarily enclose the innermost normal cleanup depth, because
the top of the jump scope stack might be an EH cleanup or EH scope.
Fixes PR9303.

llvm-svn: 126472
2011-02-25 04:19:13 +00:00
Douglas Gregor 144548072d Use NestedNameSpecifierLoc within out-of-line variables, function, and
tag definitions. Also, add support for template instantiation of
NestedNameSpecifierLocs.

llvm-svn: 126470
2011-02-25 02:25:35 +00:00
Ted Kremenek b6f9ab6378 Teach TextDiagnosticPrinter to print out '-Werror' in addition to the warning flag for a warning mapped to an error.
For example:

t.c:7:9: error: using the result of an assignment as a condition without parentheses [-Werror,-Wparentheses]

llvm-svn: 126466
2011-02-25 01:28:26 +00:00
Douglas Gregor 4d0779a754 Nth time's a charm?
llvm-svn: 126461
2011-02-25 00:46:48 +00:00
Douglas Gregor 61e58aecbc CMake target check.deps only exists when LLVM_INCLUDE_TESTS
llvm-svn: 126460
2011-02-25 00:43:05 +00:00
Douglas Gregor a9d87bc6ac Update UsingDecl, UnresolvedUsingTypenameDecl, and
UnresolvedUsingValueDecl to use NestedNameSpecifierLoc rather than the
extremely-lossy NestedNameSpecifier/SourceRange pair it used to use,
improving source-location information.

Various infrastructure updates to support NestedNameSpecifierLoc:
  - AST/PCH (de-)serialization
  - Recursive AST visitor
  - libclang traversal (including the first tests of this
    functionality)

llvm-svn: 126459
2011-02-25 00:36:19 +00:00
Douglas Gregor 49709e75bb LLVM_INCLUDE_TESTS applies to unit tests, not the normal Clang tests
llvm-svn: 126458
2011-02-25 00:32:30 +00:00
Douglas Gregor 0e066c0238 Don't include Clang's unit tests if LLVM's unit tests aren't being built
llvm-svn: 126455
2011-02-25 00:12:04 +00:00
Argyrios Kyrtzidis 17bee3e70a Intoduce '-analyzer-checker-help' flag which outputs a list of all available static analyzer checkers.
This is pretty basic for now, eventually checkers should be grouped according to package, hidden checkers should be indicated etc.

llvm-svn: 126454
2011-02-25 00:09:51 +00:00
Chandler Carruth 4322a2864e Fix the rest of PR9316 along with some other bugs spotted by inspection.
I tried to add test cases for these, but I can't because variables
aren't warned on the way functions are and the codegen layer appears to
use different logic for determining that 'a' and 'g' in the test case
should receive C mangling. I've included the test so that if we ever
switch the codegen layer to use these functions, we won't regress due to
latent bugs.

llvm-svn: 126453
2011-02-25 00:05:02 +00:00
Ted Kremenek a8890833f2 Don't warn about using PredefinedExprs as format string literals. These never can be a real security issue.
Fixes PR 9314.

llvm-svn: 126447
2011-02-24 23:03:04 +00:00
Argyrios Kyrtzidis b388f77ad9 [analyzer] Remove '-analyzer-experimental-internal-checks' flag, it doesn't have any checkers associated with it anymore.
llvm-svn: 126440
2011-02-24 21:43:08 +00:00
Argyrios Kyrtzidis 51695bbb0a [analyzer] Allow a checker to be hidden even if its package is hidden & enabled.
For example, if 'core.experimental.UnreachableCode' is hidden, it should not be enabled with 'core.experimental'.
Note that this requires llvm commit r126436.

llvm-svn: 126439
2011-02-24 21:42:52 +00:00
Argyrios Kyrtzidis 8b08906411 [analyzer] Migrate CastSizeChecker to CheckerV2.
llvm-svn: 126438
2011-02-24 21:42:49 +00:00
Fariborz Jahanian 74405b02f9 Fix a rewrite bug. // rdar://9039342
llvm-svn: 126435
2011-02-24 21:29:21 +00:00
Rafael Espindola eb4fd01f7a Use private linkage to avoid symbol conflicts in corner cases like the one
in PR9301.

llvm-svn: 126422
2011-02-24 20:31:44 +00:00
Chandler Carruth 9682a2fd3a Likely fix for PR9316 and other unknown bugs: don't use the anonynmous
namespace blanket rule for variables and functions declared 'extern
"C"'.

llvm-svn: 126400
2011-02-24 19:03:39 +00:00
Douglas Gregor 869ad45f8f Retain complete source-location information for C++
nested-name-specifiers throughout the parser, and provide a new class
(NestedNameSpecifierLoc) that contains a nested-name-specifier along
with its type-source information.

Right now, this information is completely useless, because we don't
actually store the source-location information anywhere in the
AST. Call this Step 1/N.

llvm-svn: 126391
2011-02-24 17:54:50 +00:00
Chandler Carruth e721185799 Simplify messages as requested by Chris.
llvm-svn: 126389
2011-02-24 17:13:15 +00:00
Axel Naumann 016538ad2a From Vassil Vassilev:
Add an interface for last resort, unqualified lookup. It can provide results for unqualified lookup when Sema fails to find anything itself.

llvm-svn: 126387
2011-02-24 16:47:47 +00:00
Daniel Dunbar 30cdc7022b Revert "Use CharUnits values for Size and DataSize outside of the bitfield
layout", it broke some GCC tests.

llvm-svn: 126386
2011-02-24 16:40:53 +00:00
Argyrios Kyrtzidis c08d89e6c2 Allow passing a list of comma separated checker names to -analyzer-checker, e.g:
-analyzer-checker=cocoa,unix

llvm-svn: 126372
2011-02-24 08:42:20 +00:00
Argyrios Kyrtzidis dd407f423b [analyzer] Migrate ArrayBoundChecker to CheckerV2.
llvm-svn: 126371
2011-02-24 08:42:12 +00:00
Argyrios Kyrtzidis 8f38c3843d [analyzer] Don't pass a GRState to CheckerManager::runCheckersForLocation, terrible mistake.
If the state is new, make sure an ExplodedNode is associated with it.

llvm-svn: 126370
2011-02-24 08:42:04 +00:00
Argyrios Kyrtzidis 7bc0141043 [analyzer] Migrate ReturnPointerRangeChecker to CheckerV2.
llvm-svn: 126369
2011-02-24 08:41:57 +00:00
Chris Lattner abcf38a064 compute the integer width, not the memory width here. We want to know that
_Bool is 1 bit, not 8.  This fixes an assertion on the testcase, which is
PR9304 and rdar://9045501.

llvm-svn: 126368
2011-02-24 07:31:28 +00:00
Chris Lattner d767a0300e Reimplement DefineTypeSize in terms of APInt. This eliminates some
magic integer arithmetic and allows it to work with types larger
than 64 bits.

llvm-svn: 126365
2011-02-24 06:54:56 +00:00
Chris Lattner 190aa10fe6 rework processing of unavailable and deprecated attributes to avoid
unneeded allocation of an empty StringLiteral when these don't have
a message.

llvm-svn: 126364
2011-02-24 05:42:24 +00:00
Ted Kremenek d813801384 Fix tiny error in CFG construction for BinaryConditionalOperators, making sure the branch always has two successors. Also teach Environment::getSVal() about OpaqueValueExprs.
This fixes a crash reported in PR9287, and also fixes a false positive involving the value of such ternary
expressions not properly getting propagated.

llvm-svn: 126362
2011-02-24 03:09:15 +00:00
Chandler Carruth f8da8c7fa7 Tweak this test a bit further to make it easier on grep. Who knows what
characters get dropped into the regular expression from %t.

llvm-svn: 126361
2011-02-24 02:39:40 +00:00
Douglas Gregor d7295bad84 Test case for previous commit
llvm-svn: 126360
2011-02-24 02:37:39 +00:00
Douglas Gregor 7b26ff912f Teach NestedNameSpecifier to keep track of namespace aliases the same
way it keeps track of namespaces. Previously, we would map from the
namespace alias to its underlying namespace when building a
nested-name-specifier, losing source information in the process.

llvm-svn: 126358
2011-02-24 02:36:08 +00:00
Ken Dyck 8e74e79145 Use CharUnits values for Size and DataSize outside of the bitfield layout
methods, when they are known to be exact multiples of the width of the char
type. 

llvm-svn: 126357
2011-02-24 02:12:14 +00:00
Ken Dyck 3c215f2fd1 Use Context.getCharWidth() in place of literal '8's in assertions.
llvm-svn: 126356
2011-02-24 01:33:05 +00:00
Ken Dyck ecfc75529f Make the Size and DataSize members more CharUnits-friendly by wrapping them
with getter and setter methods in both bit units and CharUnits. This will help
simplify some of the unit mismatch in the parts of the code where sizes are
known to be exact multiples of the width of the char type.

Assertions in the getters help guard against accidentally converting to
CharUnits when sizes are not exact multiples of the char width.

llvm-svn: 126354
2011-02-24 01:13:28 +00:00
Argyrios Kyrtzidis 4769e9376e [analyzer] Remove unused functions from CheckerManager.
llvm-svn: 126352
2011-02-24 01:05:37 +00:00
Argyrios Kyrtzidis 785459a2a9 [analyzer] Migrate StreamChecker to CheckerV2.
llvm-svn: 126351
2011-02-24 01:05:33 +00:00
Argyrios Kyrtzidis c26f15dbad [analyzer] Migrate CStringChecker to CheckerV2.
llvm-svn: 126350
2011-02-24 01:05:30 +00:00
Douglas Gregor 2ab3fee3f3 Tweak the CXXScopeSpec API a bit, so that we require the
nested-name-specifier and source range to be set at the same time.

llvm-svn: 126347
2011-02-24 00:49:34 +00:00
Douglas Gregor 90c9972fb2 Teach CXXScopeSpec to handle the extension of a nested-name-specifier
with another component in the nested-name-specifiers, updating its
representation (a NestedNameSpecifier) and source-location information
(currently a SourceRange) simultaneously. This is groundwork for
adding source-location information to nested-name-specifiers.

llvm-svn: 126346
2011-02-24 00:17:56 +00:00
Chandler Carruth 60ed89dc54 Handle value dependent LHS as well as RHS. Test both of these, they
don't seem to have been covered by our tests previously.

This should fix bootstrap failure.

llvm-svn: 126345
2011-02-24 00:03:53 +00:00
Chandler Carruth 220617c1ba Clean up the CMake test execution by nuking this directory before we try
to create it. Lit doesn't apparently clean up test directories
effectively, and so this broke randomly on subsequent runs.

Also XFAIL the test on windows, as there's not much hope for these
commands doing the right thing there.

Paired with Nick Lewycky.

llvm-svn: 126344
2011-02-23 23:52:14 +00:00
Chandler Carruth 4c6fdca035 Implement a warning for known shift overflows on constant shift
expressions. Consider the code:

  int64_t i = 10 << 30;

This compiles fine, but most developers expect it to produce the value
for 10 gigs, not -2 gigs. This is actually undefined behavior because
the LHS is a signed integer type.

The warning is currently gated behind -Wshift-overflow.

There is a special case where only the sign bit is overridden that gets
a custom error message and is by default ignored. This case is much less
likely to cause observed buggy behavior, it's just undefined behavior
according to the spec. This warning can be enabled with
-Wshift-sign-overflow.

Original patch by Oleg Slezberg, with style tweaks and some correctness
fixes by me.

llvm-svn: 126342
2011-02-23 23:34:11 +00:00