Commit Graph

205 Commits

Author SHA1 Message Date
Chris Lattner 4ebae65d6a make our existing "switch on bool" warning work for C. Since
the result of comparisons are 'int' in C, it doesn't work to
test just the result type of the expression.

llvm-svn: 101576
2010-04-16 23:34:13 +00:00
Douglas Gregor b33eed0ced Collapse the three separate initialization paths in
TryStaticImplicitCast (for references, class types, and everything
else, respectively) into a single invocation of
InitializationSequence.

One of the paths (for class types) was the only client of
Sema::TryInitializationByConstructor, which I have eliminated. This
also simplified the interface for much of the cast-checking logic,
eliminating yet more code.

I've kept the representation of C++ functional casts with <> 1
arguments the same, despite the fact that I hate it. That fix will
come soon. To satisfy my paranoia, I've bootstrapped + tested Clang
with these changes.

llvm-svn: 101549
2010-04-16 22:09:46 +00:00
John McCall 2351cb9139 Devote a special diagnostic to the typo
(void*) someFunction(5, 10, 15, 20);
where the cast is presumably meant to be to 'void'.

llvm-svn: 100574
2010-04-06 22:24:14 +00:00
Douglas Gregor a771f46c82 Reinstate my CodeModificationHint -> FixItHint renaming patch, without
the C-only "optimization".

llvm-svn: 100022
2010-03-31 17:46:05 +00:00
Douglas Gregor 30e631862f Revert r100008, which inexplicably breaks the clang-i686-darwin10 builder
llvm-svn: 100018
2010-03-31 17:25:35 +00:00
Douglas Gregor 3baad0d4f7 Rename CodeModificationHint to FixItHint, since we've been using the
term "fix-it" everywhere and even *I* get tired of long names
sometimes. No functionality change.

llvm-svn: 100008
2010-03-31 15:31:50 +00:00
John McCall 16df1e59f2 Propagate the "found declaration" (i.e. the using declaration instead of
the underlying/instantiated decl) through a lot of API, including "intermediate"
MemberExprs required for (e.g.) template instantiation.  This is necessary
because of the access semantics of member accesses to using declarations:
only the base class *containing the using decl* need be accessible from the
naming class.

This allows us to complete an access-controlled selfhost, if there are no
recent regressions.

llvm-svn: 99936
2010-03-30 21:47:33 +00:00
Fariborz Jahanian 5cab26d058 Add Support for 'warn_unused_result" attribute on
objective-c methods. (radar 7418262).

llvm-svn: 99903
2010-03-30 18:22:15 +00:00
Douglas Gregor 8933623b91 Optimize PartialDiagnostic's memory-allocation behavior by placing a
cache of PartialDiagnostic::Storage objects into an allocator within
the ASTContext. This eliminates a significant amount of malloc
traffic, for a 10% performance improvement in -fsyntax-only wall-clock
time with 403.gcc's combine.c.

Also, eliminate the RequireNonAbstractType hack I put in earlier,
which was but a symptom of this larger problem.

Fixes <rdar://problem/7806091>.

llvm-svn: 99849
2010-03-29 23:34:08 +00:00
John McCall c493a73240 Improve the unused-value check to look into comma expressions and filter out
voids in sub-expressions.  Patch by Mike M!

Fixes PR4806.

llvm-svn: 98335
2010-03-12 07:11:26 +00:00
Douglas Gregor 9a28e84b32 Keep an explicit stack of function and block scopes, each element of
which has the label map, switch statement stack, etc. Previously, we
had a single set of maps in Sema (for the function) along with a stack
of block scopes. However, this lead to funky behavior with nested
functions, e.g., in the member functions of local classes.

The explicit-stack approach is far cleaner, and we retain a 1-element
cache so that we're not malloc/free'ing every time we enter a
function. Fixes PR6382.

Also, tweaked the unused-variable warning suppression logic to look at
errors within a given Scope rather than within a given function. The
prior code wasn't looking at the right number-of-errors count when
dealing with blocks, since the block's count would be deallocated
before we got to ActOnPopScope. This approach works with nested
blocks/functions, and gives tighter error recovery.

llvm-svn: 97518
2010-03-01 23:15:13 +00:00
Douglas Gregor a070ffa7b8 Don't warn about case-value conversions from a negative value to a
larger unsigned value, since this is implementation-defined
behavior. (We previously suppressed this warning when converting from
a signed value to an unsigned value of the same size).

llvm-svn: 97430
2010-03-01 01:04:55 +00:00
Douglas Gregor e5ad57a3ed Don't diagnose overflow in case statements when the conversion is a
signed<->unsigned conversion with the same bit width. Fixes
<rdar://problem/7658121>.

llvm-svn: 96545
2010-02-18 00:56:01 +00:00
Douglas Gregor 12ea0f4ef9 For -Wswitch-enum warnings, be sure to look through typedefs of enum
types. Fixes <rdar://problem/7643909>.

llvm-svn: 96531
2010-02-17 23:29:11 +00:00
Douglas Gregor 50dc219e8b When we have a dependent direct initializer but not a dependent
variable type, we can (and should) still check for completeness of the
variable's type. Do so, to work around an assertion that shows up in
Boost's shared_ptr.

llvm-svn: 95934
2010-02-11 22:55:30 +00:00
Douglas Gregor bd683973c1 Warn when cases are missing from a switch on a value of enumeration
type (-Wswitch), from Michal! 

llvm-svn: 95592
2010-02-08 22:24:16 +00:00
John McCall ab26cfa58d Standardize the parsing of function type attributes in a way that
follows (as conservatively as possible) gcc's current behavior:  attributes
written on return types that don't apply there are applied to the function
instead, etc.  Only parse CC attributes as type attributes, not as decl attributes;
don't accepet noreturn as a decl attribute on ValueDecls, either (it still
needs to apply to other decls, like blocks).  Consistently consume CC/noreturn
information throughout codegen;  enforce this by removing their default values
in CodeGenTypes::getFunctionInfo().

llvm-svn: 95436
2010-02-05 21:31:56 +00:00
Sam Weinig a16b0dd1ae Implement Doug's suggestion. Eliminate the Stmts pointer from CXXTryStmt and instead allocate the statements after the object.
llvm-svn: 95199
2010-02-03 03:56:39 +00:00
Sam Weinig ebcea988c2 Remove the SmallVector from CXXTryStmt.
llvm-svn: 95190
2010-02-03 02:09:59 +00:00
Douglas Gregor b92a1565c3 Implement the lvalue-to-rvalue conversion where needed. The
lvalue-to-rvalue conversion adjusts lvalues of qualified, non-class
type to rvalue expressions of the unqualified variant of that
type. For example, given:

  const int i;
  (void)(i + 17);

the lvalue-to-rvalue conversion for the subexpression "i" will turn it
from an lvalue expression (a DeclRefExpr) with type 'const int' into
an rvalue expression with type 'int'. Both C and C++ mandate this
conversion, and somehow we've slid through without implementing it. 

We now have both DefaultFunctionArrayConversion and
DefaultFunctionArrayLvalueConversion, and which gets used depends on
whether we do the lvalue-to-rvalue conversion or not. Generally, we do
the lvalue-to-rvalue conversion, but there are a few notable
exceptions:
  - the left-hand side of a '.' operator
  - the left-hand side of an assignment
  - a C++ throw expression
  - a subscript expression that's subscripting a vector

Making this change exposed two issues with blocks:
  - we were deducing const-qualified return types of non-class type
  from a block return, which doesn't fit well
  - we weren't always setting the known return type of a block when it
  was provided with the ^return-type syntax

Fixes the current Clang-on-Clang compile failure and PR6076.

llvm-svn: 95167
2010-02-03 00:27:59 +00:00
Chandler Carruth 00216980fb Really trivial patch to accept pointer to const void in indirect goto. Despite
the lack of documentation, this matches the behavior of GCC.

llvm-svn: 94954
2010-01-31 10:26:25 +00:00
Anders Carlsson 98323d29b6 Remove the SmallVectors from AsmStmt. Fixes PR6105.
llvm-svn: 94926
2010-01-30 23:19:41 +00:00
Anders Carlsson 9a020f9a3a Use IdentifierInfo * instead of std::string for the AsmStmt names.
llvm-svn: 94925
2010-01-30 22:25:16 +00:00
Anders Carlsson 96fe0b5b96 Combine AsmStmt::setOutputsAndInputs and AsmStmt::setClobbers.
llvm-svn: 94918
2010-01-30 19:34:25 +00:00
Anders Carlsson 0b0a122fde StringRef-ize the TargetInfo::ConstraintInfo constructor.
llvm-svn: 94916
2010-01-30 18:33:31 +00:00
Anders Carlsson 6f923f89c3 Get rid of another old PerformCopyInitialization call.
llvm-svn: 94819
2010-01-29 18:30:20 +00:00
Anders Carlsson aaeef07280 Implement instantiation of AsmStmts (Crazy, I know)
llvm-svn: 94361
2010-01-24 05:50:09 +00:00
Chris Lattner 8fd2d01118 fix PR6034, a crash on invalid where the switch stack would get
unbalanced.

llvm-svn: 94347
2010-01-24 01:50:29 +00:00
John McCall ad371258aa Give UnresolvedSet the ability to store access specifiers for each declaration.
Change LookupResult to use UnresolvedSet.  Also extract UnresolvedSet into its
own header and make it templated over an inline capacity.

llvm-svn: 93959
2010-01-20 00:46:10 +00:00
Mike Stump 314825bc8a Implement goto inside of blocks.
llvm-svn: 93945
2010-01-19 23:08:01 +00:00
Mike Stump 90be58afce Remember if the AsmStmt came from Microsoft-style inline assembly code.
llvm-svn: 92526
2010-01-04 22:37:17 +00:00
Benjamin Kramer d20ef75b91 Remove some dead variables clang-analyzer found.
llvm-svn: 92162
2009-12-25 15:43:36 +00:00
Douglas Gregor 1b3039344b Switch InitializedEntity from TypeLoc down to just QualTypes, since we don't use the location information but we did spend a bunch of time building faked-up TypeLocs
llvm-svn: 91905
2009-12-22 15:35:07 +00:00
Nuno Lopes 518e370719 fix PR4010: add support for the warn_unused_result for function pointers
llvm-svn: 91803
2009-12-20 23:11:08 +00:00
Douglas Gregor 4a2ce65dbf Try to de-bork DISABLE_SMART_POINTERS build
llvm-svn: 91696
2009-12-18 17:31:58 +00:00
Douglas Gregor e1314a64b8 Switch the initialization required by return statements over to the
new InitializationSequence. This fixes some bugs (e.g., PR5808),
changed some diagnostics, and caused more churn than expected. What's
new:

  - InitializationSequence now has a "C conversion sequence" category
    and step kind, which falls back to
  - Changed the diagnostics for returns to always have the result type
    of the function first and the type of the expression second.
    CheckSingleAssignmentConstraints to peform checking in C. 
  - Improved ASTs for initialization of return values. The ASTs now
    capture all of the temporaries we need to create, but
    intentionally do not bind the tempoary that is actually returned,
    so that it won't get destroyed twice.
  - Make sure to perform an (elidable!) copy of the class object that
    is returned from a class.
  - Fix copy elision in CodeGen to properly see through the
    subexpressions that occur with elidable copies.
  - Give "new" its own entity kind; as with return values and thrown
    objects, we don't bind the expression so we don't call a
    destructor for it.

Note that, with this patch, I've broken returning move-only types in
C++0x. We'll fix it later, when we tackle NRVO.

llvm-svn: 91669
2009-12-18 05:02:21 +00:00
Douglas Gregor 7c3bbdfd28 Fix semantic diagnostics that embed English works, from Nicola Gigante!
llvm-svn: 91503
2009-12-16 03:45:30 +00:00
Anders Carlsson 6e997b2993 ShouldDestroyTemporaries? I don't think so.
llvm-svn: 91450
2009-12-15 20:51:39 +00:00
Douglas Gregor 7fdcbaf291 Fix a thinko where we weren't always performing unary conversions on the switch condition, fixing PR5612
llvm-svn: 89864
2009-11-25 15:17:36 +00:00
Douglas Gregor 3ff3af4ff9 When the condition of a switch() statement is semantically invalid,
still parse the body of the switch to try to avoid spurious
diagnostics. Fixes PR5606.

llvm-svn: 89847
2009-11-25 06:20:02 +00:00
Douglas Gregor 110755548b Refactor ActOnFinishSwitchStmt to simplify it further
llvm-svn: 89843
2009-11-25 05:02:21 +00:00
Douglas Gregor 852d53e712 Refactor ActOnFinishSwitchStmt to simplify and reduce nesting
llvm-svn: 89842
2009-11-25 04:55:54 +00:00
Douglas Gregor 7bab5ff8e7 Eliminate CXXConditionDeclExpr with extreme prejudice.
All statements that involve conditions can now hold on to a separate
condition declaration (a VarDecl), and will use a DeclRefExpr
referring to that VarDecl for the condition expression. ForStmts now
have such a VarDecl (I'd missed those in previous commits).

Also, since this change reworks the Action interface for
if/while/switch/for, use FullExprArg for the full expressions in those
expressions, to ensure that we're emitting

Note that we are (still) not generating the right cleanups for
condition variables in for statements. That will be a follow-on
commit.

llvm-svn: 89817
2009-11-25 00:27:52 +00:00
Douglas Gregor 680f861d74 Clean up the AST for while loops and fix several problems with
cleanups for while loops: 

1) Make sure that we destroy the condition variable of a while statement each time through the loop for, e.g.,

   while (shared_ptr<WorkInt> p = getWorkItem()) {
         // ...
         }

2) Make sure that we always enter a new cleanup scope for the body of the while loop, even when there is no compound expression, e.g.,

   while (blah)
     RAIIObject raii(blah+1);

llvm-svn: 89800
2009-11-24 21:15:44 +00:00
Douglas Gregor dcf1962405 Explicitly store the condition variable within switch statements, and
make sure that this variable is destroyed when we exit the switch
statement.

llvm-svn: 89776
2009-11-24 17:07:59 +00:00
Douglas Gregor 633caca353 Explicitly track the condition variable within an "if" statement,
rather than burying it in a CXXConditionDeclExpr (that occassionally
hides behind implicit conversions). Similar changes for
switch, while, and do-while will follow, then the removal of
CXXConditionDeclExpr. This commit is the canary.

llvm-svn: 89717
2009-11-23 23:44:04 +00:00
Douglas Gregor 378e1923b6 Require a class type to be complete before probing its conversion
functions for a switch condition's conversion to integral or
enumeration type. 

llvm-svn: 89656
2009-11-23 13:53:21 +00:00
Douglas Gregor d0c22e0d10 Implement conversion from a switch condition with class type to an
integral or enumeration type (vi user-defined conversions). Fixes PR5518.

llvm-svn: 89655
2009-11-23 13:46:08 +00:00
Fariborz Jahanian e774fa6412 Don't issue spurious diagnostic with Obj-C fast enumeration.
(radar 7409165).

llvm-svn: 89400
2009-11-19 22:12:37 +00:00
Douglas Gregor 1b8fe5b716 First part of changes to eliminate problems with cv-qualifiers and
sugared types. The basic problem is that our qualifier accessors
(getQualifiers, getCVRQualifiers, isConstQualified, etc.) only look at
the current QualType and not at any qualifiers that come from sugared
types, meaning that we won't see these qualifiers through, e.g.,
typedefs:

  typedef const int CInt;
  typedef CInt Self;

Self.isConstQualified() currently returns false!

Various bugs (e.g., PR5383) have cropped up all over the front end due
to such problems. I'm addressing this problem by splitting each
qualifier accessor into two versions: 

  - the "local" version only returns qualifiers on this particular
    QualType instance
  - the "normal" version that will eventually combine qualifiers from this
    QualType instance with the qualifiers on the canonical type to
    produce the full set of qualifiers.

This commit adds the local versions and switches a few callers from
the "normal" version (e.g., isConstQualified) over to the "local"
version (e.g., isLocalConstQualified) when that is the right thing to
do, e.g., because we're printing or serializing the qualifiers. Also,
switch a bunch of
  
  Context.getCanonicalType(T1).getUnqualifiedType() == Context.getCanonicalType(T2).getQualifiedType()

expressions over to 

  Context.hasSameUnqualifiedType(T1, T2)

llvm-svn: 88969
2009-11-16 21:35:15 +00:00