Commit Graph

242 Commits

Author SHA1 Message Date
John McCall aab3e41eb2 Split FunctionScopeInfo and BlockScopeInfo into their own header.
llvm-svn: 112038
2010-08-25 08:40:02 +00:00
John McCall cc14d1fd23 More header elimination. The goal of all this is to allow Parser to
#include Sema.h while keeping all the AST declarations opaque.  That may
not be reasonably attainable, though.

llvm-svn: 111907
2010-08-24 08:50:51 +00:00
John McCall dadc575b1e OwningExprResult -> ExprResult. This patch brought to you by
M-x query-replace-regexp
\(Sema::\|Action::\|Parser::\|\)Owning\(Expr\|Stmt\)Result -> \2Result

llvm-svn: 111903
2010-08-24 06:29:42 +00:00
John McCall b268a282a4 Kill off ExprArg (now just Expr*) and StmtArg (now just Stmt*).
llvm-svn: 111863
2010-08-23 23:25:46 +00:00
John McCall 4887165193 DeclPtrTy -> Decl *
llvm-svn: 111733
2010-08-21 09:40:31 +00:00
Fariborz Jahanian b5a6246b91 Typo.
llvm-svn: 110965
2010-08-12 22:33:42 +00:00
Fariborz Jahanian 68e69ca9f9 Patch to issue warning when colllection expresion's type
does not implement 'countByEnumeratingWithState' API.
Implements radar 7634669.

llvm-svn: 110964
2010-08-12 22:25:42 +00:00
Douglas Gregor c3a6ade0bb Move Sema's headers into include/clang/Sema, renaming a few along the way.
llvm-svn: 110945
2010-08-12 20:07:10 +00:00
Fariborz Jahanian d539d098a4 IRGen support for functions returning objc object
types. Fixes PR7865.

llvm-svn: 110832
2010-08-11 17:37:35 +00:00
John McCall a95172baa0 Only run the jump-checker if there's a branch-protected scope *and* there's
a switch or goto somewhere in the function.  Indirect gotos trigger the
jump-checker regardless, because the conditions there are slightly more
elaborate and it's too marginal a case to be worth optimizing.

Turns off the jump-checker in a lot of cases in C++.  rdar://problem/7702918

llvm-svn: 109962
2010-08-01 00:26:45 +00:00
Dan Gohman 28ade550f4 Fix namespace polution.
llvm-svn: 109440
2010-07-26 21:25:24 +00:00
Douglas Gregor b412e174db Remove the vast majority of the Destroy methods from the AST library,
since we aren't going to be calling them ever.

llvm-svn: 109377
2010-07-25 18:17:45 +00:00
Douglas Gregor cb2b662283 Make the "unused result" warning a warning about run-time behavior, so
that we don't warn when there isn't going to be any computation anyway.

llvm-svn: 108442
2010-07-15 18:47:04 +00:00
Douglas Gregor 747eb7840a Reinstate the fix for PR7556. A silly use of isTrivial() was
suppressing copies of objects with trivial copy constructors.

llvm-svn: 107857
2010-07-08 06:14:04 +00:00
Douglas Gregor e182370eda Revert r107828 and r107827, the fix for PR7556, which seems to be
breaking bootstrap on Linux.

llvm-svn: 107837
2010-07-07 23:37:33 +00:00
Douglas Gregor 442612c285 Do not use CXXZeroValueInitExpr for class types. Instead, use
CXXConstructExpr/CXXTemporaryObjectExpr/CXXNewExpr as
appropriate. Fixes PR7556, and provides a slide codegen improvement
when copy-initializing a POD class type from a value-initialized
temporary. Previously, we weren't eliding the copy.

llvm-svn: 107827
2010-07-07 22:35:13 +00:00
Douglas Gregor 4799d03ce8 Implement C++ DR299, which allows an implicit conversion from a class
type to an integral or enumeration type in the size of an array new
expression, e.g.,

  new int[ConvertibleToInt(10)];

This is a GNU and C++0x extension.

llvm-svn: 107229
2010-06-30 00:20:43 +00:00
Douglas Gregor 5823da3ab0 Re-improve recovery when the condition of a switch statement does not
have integral or enumeration type, so that we still check the contents
of the switch body. My previous patch made this worse; now we're back
to where we were previously.

llvm-svn: 107223
2010-06-29 23:25:20 +00:00
Douglas Gregor f4ea725d38 Factor the conversion from a switch condition to an integral or
enumeration type out into a separate, reusable routine. The only
functionality change here is that we recover a little more
aggressively from ill-formed switch conditions.

llvm-svn: 107222
2010-06-29 23:17:37 +00:00
Douglas Gregor 56980d688b With packed enums, an enumerator's value may be stored in more bits
than the enumeration type itself takes. Fixes PR7477.

llvm-svn: 107163
2010-06-29 17:12:35 +00:00
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
Douglas Gregor 27b98eae80 Alter the internal representation of the condition variable in
if/while/switch/for statements to ensure that walking the children of
these statements actually works. Previously, we stored the condition
variable as a VarDecl. However, StmtIterator isn't able to walk from a
VarDecl to a set of statements, and would (in some circumstances) walk
beyond the end of the list of statements, cause Bad Behavior.

In this change, we've gone back to representing the condition
variables as DeclStmts. While not as memory-efficient as VarDecls, it
greatly simplifies iteration over the children. 

Fixes the remainder of <rdar://problem/8104754>.

llvm-svn: 106504
2010-06-21 23:44:13 +00:00
Douglas Gregor b90df60b3b Introduce Type::isIntegralOrEnumerationType(), to cover those places
in C++ that involve both integral and enumeration types. Convert all
of the callers to Type::isIntegralType() that are meant to work with
both integral and enumeration types over to
Type::isIntegralOrEnumerationType(), to prepare to eliminate
enumeration types as integral types.

llvm-svn: 106071
2010-06-16 00:17:44 +00:00
John McCall 45d30c3e36 When deciding whether an expression has the boolean nature, don't look through
explicit casts.  Fixes PR7359.

llvm-svn: 105871
2010-06-12 01:56:02 +00:00
John McCall d3dfbd6f4f If a switch condition is constant, don't warn about missing enum cases.
If a switch condition is constant, warn if there's no case for it.

Constant switch conditions do come up in reasonable template code.

llvm-svn: 104010
2010-05-18 03:19:21 +00:00
John McCall 8b07ec253d Substantially alter the design of the Objective C type AST by introducing
ObjCObjectType, which is basically just a pair of
  one of {primitive-id, primitive-Class, user-defined @class}
with
  a list of protocols.
An ObjCObjectPointerType is therefore just a pointer which always points to
one of these types (possibly sugared).  ObjCInterfaceType is now just a kind
of ObjCObjectType which happens to not carry any protocols.

Alter a rather large number of use sites to use ObjCObjectType instead of
ObjCInterfaceType.  Store an ObjCInterfaceType as a pointer on the decl rather
than hashing them in a FoldingSet.  Remove some number of methods that are no
longer used, at least after this patch.

By simplifying ObjCObjectPointerType, we are now able to easily remove and apply
pointers to Objective-C types, which is crucial for a certain kind of ObjC++
metaprogramming common in WebKit.

llvm-svn: 103870
2010-05-15 11:32:37 +00:00
Douglas Gregor 290c93ec0d Implement a simple form of the C++ named return value optimization for
return statements. We perform NRVO only when all of the return
statements in the function return the same variable. Fixes some link
failures in Boost.Interprocess (which is relying on NRVO), and
probably improves performance for some C++ applications.

llvm-svn: 103867
2010-05-15 06:46:45 +00:00
Douglas Gregor 6fd1b1802f Implement semantic analysis and an AST representation for the named
return value optimization. Sema marks return statements with their
NRVO candidates (which may or may not end up using the NRVO), then, at
the end of a function body, computes and marks those variables that
can be allocated into the return slot.

I've checked this locally with some debugging statements (not
committed), but there won't be any tests until CodeGen comes along.

llvm-svn: 103865
2010-05-15 06:01:05 +00:00
Douglas Gregor 222cf0efbc Recognize when the named return value optimization applies in a
"return" statement and mark the corresponding CXXConstructExpr as
elidable. Teach CodeGen that eliding a temporary is different from
eliding an object construction.

This is just a baby step toward NRVO.

llvm-svn: 103849
2010-05-15 00:13:29 +00:00
Douglas Gregor 12cc7eeb82 Fixed DISABLE_SMART_POINTERS breakage
llvm-svn: 103198
2010-05-06 21:39:56 +00:00
Douglas Gregor e60e41add9 Rework our handling of temporary objects within the conditions of
if/switch/while/do/for statements. Previously, we would end up either:

  (1) Forgetting to destroy temporaries created in the condition (!),
  (2) Destroying the temporaries created in the condition *before*
  converting the condition to a boolean value (or, in the case of a
  switch statement, to an integral or enumeral value), or
  (3) In a for statement, destroying the condition's temporaries at
  the end of the increment expression (!).

We now destroy temporaries in conditions at the right times. This
required some tweaking of the Parse/Sema interaction, since the parser
was building full expressions too early in many places.

Fixes PR7067.

llvm-svn: 103187
2010-05-06 17:25:47 +00:00
Douglas Gregor f356419bf5 Refactor Objective-C @catch parameter checking by detangling it from
function-parameter checking and splitting it into the normal
ActOn*/Build* pair in Sema. We now use VarDecl to represent the @catch
parameter rather than the ill-fitting ParmVarDecl.

llvm-svn: 102347
2010-04-26 17:32:49 +00:00
Douglas Gregor 96c79498fb Improve the AST representation of Objective-C @try/@catch/@finally
statements. Instead of the @try having a single @catch, where all of
the @catch's were chained (using an O(n^2) algorithm nonetheless),
@try just holds an array of its @catch blocks. The resulting AST is
slightly more compact (not important) and better represents the actual
language semantics (good).

llvm-svn: 102221
2010-04-23 22:50:49 +00:00
Chris Lattner db6d5cb892 Implement PR6845. We allow matching constraints to have different
input and output types when the smaller value isn't mentioned in the
asm string.  Extend this support from integers to also allowing 
fp values to be mismatched (if not mentioned in the asm string).

llvm-svn: 102188
2010-04-23 17:27:29 +00:00
Douglas Gregor f68a508586 Template instantiation for the Objective-C "fast enumeration"
statement, i.e., 

  for (element in collection) {
    // do something
  }

llvm-svn: 102138
2010-04-22 23:10:45 +00:00
Douglas Gregor 6148de71dd Template instantiation for Objective-C++ @synchronized statements.
llvm-svn: 102134
2010-04-22 22:01:21 +00:00
Douglas Gregor 2900c16b92 Implement template instantiation for Objective-C++ @throw statements.
llvm-svn: 102133
2010-04-22 21:44:01 +00:00
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