summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Expr.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Change the AST generated for offsetof a bit so that it looks like a Eli Friedman2009-02-271-43/+0
| | | | | | | | normal expression, and change Evaluate and IRGen to evaluate it like a normal expression. This simplifies the code significantly, and fixes PR3396. llvm-svn: 65622
* Make isICE assert when Evaluate can't evaluate an ICE, as suggested byEli Friedman2009-02-271-26/+58
| | | | | | | Daniel. Some minor fixes/cleanup. Allow __builtin_choose_expr, __real__, and __imag__ in ICEs, following gcc's example. llvm-svn: 65610
* The middle operand in ?: is optional, really.Mike Stump2009-02-271-1/+1
| | | | llvm-svn: 65609
* Rewrite of isIntegerConstantExpr to be centered around Evaluate. This Eli Friedman2009-02-261-326/+172
| | | | | | | | | | | | | | | | | | | | | | | is a rather big change, but I think this is the direction we want to go; the code is significantly shorter now, and it doesn't duplicate Evaluate code. There shouldn't be any visible changes as far as I know. There has been some movement towards putting ICE handling into Evaluate (for example, VerifyIntegerConstantExpression uses Evaluate instead of isICE). This patch is sort of the opposite of the approach, making ICE handling work without Evaluate being aware of it. I think this approach is better because it separates the code that does the constant evaluation from code that's calculating a rather arbitrary predicate. The one thing I don't really like about this patch is that the handling of commas in C99 complicates it signficantly. (Seriously, what was the standards committee thinking when they wrote that part?) I think I've come up with a decent approach, but it doesn't feel ideal. I might add some way to check for evaluated commas from Evaluate in a subsequent patch; that said, it might not be worth bothering. llvm-svn: 65524
* first wave of fixes for @encode sema support. This is part of PR3648.Chris Lattner2009-02-241-1/+3
| | | | | | | The big difference here is that (like string literal) @encode has array type, not pointer type. llvm-svn: 65391
* We should not generate __weak write barrier on indirect referenceFariborz Jahanian2009-02-231-0/+2
| | | | | | | of a pointer to object; This patch does this odd behavior according to gcc. llvm-svn: 65334
* More objc gc work. Match gcc's treatment of ivar accessFariborz Jahanian2009-02-221-0/+27
| | | | | | | true a local pointer to objective-c object in generating write barriers. llvm-svn: 65290
* Improvements to ASTContext::getDeclAlignInBytes; fixes the testcase in Eli Friedman2009-02-221-20/+7
| | | | | | | | | PR3254 and part of PR3433. The isICE changes are necessary to keep the computed results consistent with Evaluate. llvm-svn: 65258
* A few small tweaks to isConstantInitializer. (No test because this Eli Friedman2009-02-201-3/+9
| | | | | | isn't getting used by Sema or CodeGen at the moment...) llvm-svn: 65107
* rip out __builtin_overloadChris Lattner2009-02-181-12/+0
| | | | llvm-svn: 64961
* teach child iterators to walk into the child string of an ObjCStringLiteral,Chris Lattner2009-02-181-2/+2
| | | | | | so it shows up in -ast-dump. llvm-svn: 64901
* privatize all of the string literal memory allocation/creationChris Lattner2009-02-181-47/+21
| | | | | | stuff behind a private static function. llvm-svn: 64898
* change the StringLiteral AST node to track all of the SourceLocations of Chris Lattner2009-02-181-6/+22
| | | | | | | | the various PPTokens that are pasted together to make it. In the course of working on this, I discovered ParseObjCStringLiteral which needs some work. I'll tackle it next. llvm-svn: 64892
* isICE was evaluating ?: incorrectly with missing-gcc-LHS extension.Daniel Dunbar2009-02-181-3/+16
| | | | | | | Add assert to isICE that, on success, result must be the same as EvaluateAsInt()... this enforces a minimum level of sanity. llvm-svn: 64865
* Convert isIntegerConstantExpr to use ASTContext::MakeIntValue. Daniel Dunbar2009-02-181-39/+29
| | | | | | | | | | | | | | | - This idiom ensures that the result will have the right width and type. - Tested on most of x86_64/llvm-test to satisfy my paranoia. - This fixes at least the following bugs: o UnaryTypeTraitExpr wasn't setting the width correctly. o Arithmetic on _Bool wasn't setting the width correctly. And probably a number more. llvm-svn: 64864
* Rename UnaryTypeTraitExpr::Evaluate to EvaluateTrait to not collideDaniel Dunbar2009-02-171-1/+1
| | | | | | with Expr::Evaluate(). llvm-svn: 64850
* Unbreak clang.Daniel Dunbar2009-02-161-1/+1
| | | | | | | | Doug: please verify that it is expected that LastIdx can be less that NumInits. And perhaps add a comment so that Chris doesn't break your code. :) llvm-svn: 64688
* fix long lines.Chris Lattner2009-02-161-8/+12
| | | | llvm-svn: 64684
* introduce and use a new ExtVectorElementExpr::isArrow method, at Eli's ↵Chris Lattner2009-02-161-0/+6
| | | | | | suggestion llvm-svn: 64681
* Add hook to add attributes to function declarations that we knowDouglas Gregor2009-02-141-4/+4
| | | | | | | | | | | | | | | | about, whether they are builtins or not. Use this to add the appropriate "format" attribute to NSLog, NSLogv, asprintf, and vasprintf, and to translate builtin attributes (from Builtins.def) into actual attributes on the function declaration. Use the "printf" format attribute on function declarations to determine whether we should do format string checking, rather than looking at an ad hoc list of builtins and "known" function names. Be a bit more careful about when we consider a function a "builtin" in C++. llvm-svn: 64561
* Several related changes: Chris Lattner2009-02-141-38/+103
| | | | | | | | | | | | | | | 1) implement parser and sema support for reading and verifying attribute(warnunusedresult). 2) rename hasLocalSideEffect to isUnusedResultAWarning, inverting the sense of its result. 3) extend isUnusedResultAWarning to directly return the loc and range info that should be reported to the user. Make it substantially more precise in some cases than what was previously reported. 4) teach isUnusedResultAWarning about CallExpr to decls that are pure/const/warnunusedresult, fixing a fixme. 5) change warn_attribute_wrong_decl_type to not pass in english strings, instead, pass in integers and use %select. llvm-svn: 64543
* Implicitly declare certain C library functions (malloc, strcpy, memmove,Douglas Gregor2009-02-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | etc.) when we perform name lookup on them. This ensures that we produce the correct signature for these functions, which has two practical impacts: 1) When we're supporting the "implicit function declaration" feature of C99, these functions will be implicitly declared with the right signature rather than as a function returning "int" with no prototype. See PR3541 for the reason why this is important (hint: GCC always predeclares these functions). 2) If users attempt to redeclare one of these library functions with an incompatible signature, we produce a hard error. This patch does a little bit of work to give reasonable error messages. For example, when we hit case #1 we complain that we're implicitly declaring this function with a specific signature, and then we give a note that asks the user to include the appropriate header (e.g., "please include <stdlib.h> or explicitly declare 'malloc'"). In case #2, we show the type of the implicit builtin that was incorrectly declared, so the user can see the problem. We could do better here: for example, when displaying this latter error message we say something like: 'strcpy' was implicitly declared here with type 'char *(char *, char const *)' but we should really print out a fake code line showing the declaration, like this: 'strcpy' was implicitly declared here as: char *strcpy(char *, char const *) This would also be good for printing built-in candidates with C++ operator overloading. The set of C library functions supported by this patch includes all functions from the C99 specification's <stdlib.h> and <string.h> that (a) are predefined by GCC and (b) have signatures that could cause codegen issues if they are treated as functions with no prototype returning and int. Future work could extend this set of functions to other C library functions that we know about. llvm-svn: 64504
* Fix va_arg bug noticed by Eli, __builtin_va_arg is not an l-valueDaniel Dunbar2009-02-121-1/+1
| | | | | | designating an object. llvm-svn: 64371
* CallExpr now uses ASTContext's allocate to allocate/delete its array of ↵Ted Kremenek2009-02-091-5/+16
| | | | | | subexpressions. llvm-svn: 64162
* Deallocate the StringLiteral itself in StringLiteral::Destroy() and ↵Ted Kremenek2009-02-091-1/+2
| | | | | | deallocate the string data before running StringLiteral's destructor. llvm-svn: 64146
* Allocate the subexpression array for OberloadExpr from ASTContext's allocator.Ted Kremenek2009-02-091-0/+7
| | | | llvm-svn: 64145
* Make const-initialized const integral variables I-C-Es in C++.Sebastian Redl2009-02-071-0/+11
| | | | llvm-svn: 64015
* Overhaul of Stmt allocation:Ted Kremenek2009-02-071-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Made allocation of Stmt objects using vanilla new/delete a *compiler error* by making this new/delete "protected" within class Stmt. - Now the only way to allocate Stmt objects is by using the new operator that takes ASTContext& as an argument. This ensures that all Stmt nodes are allocated from the same (pool) allocator. - Naturally, these two changes required that *all* creation sites for AST nodes use new (ASTContext&). This is a large patch, but the majority of the changes are just this mechanical adjustment. - The above changes also mean that AST nodes can no longer be deallocated using 'delete'. Instead, one most do StmtObject->Destroy(ASTContext&) or do ASTContextObject.Deallocate(StmtObject) (the latter not running the 'Destroy' method). Along the way I also... - Made CompoundStmt allocate its array of Stmt* using the allocator in ASTContext (previously it used std::vector). There are a whole bunch of other Stmt classes that need to be similarly changed to ensure that all memory allocated for ASTs comes from the allocator in ASTContext. - Added a new smart pointer ExprOwningPtr to Sema.h. This replaces the uses of llvm::OwningPtr within Sema, as llvm::OwningPtr used 'delete' to free memory instead of a Stmt's 'Destroy' method. Big thanks to Doug Gregor for helping with the acrobatics of making 'new/delete' private and the new smart pointer ExprOwningPtr! llvm-svn: 63997
* Implement dereferencing of pointers-to-member.Sebastian Redl2009-02-071-0/+6
| | | | llvm-svn: 63983
* Move StringLiteral to allocate its internal string data using the allocator inTed Kremenek2009-02-061-5/+7
| | | | | | | | | | | ASTContext. This required changing all clients to pass in the ASTContext& to the constructor of StringLiteral. I also changed all allocations of StringLiteral to use new(ASTContext&). Along the way, I updated a bunch of new()'s in StmtSerialization.cpp to use the allocator from ASTContext& (not complete). llvm-svn: 63958
* Basic representation of C++ class templates, from Andrew Sutton.Douglas Gregor2009-02-041-0/+1
| | | | llvm-svn: 63750
* Make CodeGen produce an error if we come across a non-constant initializer ↵Douglas Gregor2009-01-291-1/+1
| | | | | | list that involves the GNU array-range designator extension llvm-svn: 63327
* Introduce a new expression node, ImplicitValueInitExpr, thatDouglas Gregor2009-01-291-1/+12
| | | | | | | | | | | | | represents an implicit value-initialization of a subobject of a particular type. This replaces the (ab)use of CXXZeroValueInitExpr within initializer lists for the "holes" that occur due to the use of C99 designated initializers. The new test case is currently XFAIL'd, because CodeGen's ConstExprEmitter (in lib/CodeGen/CGExprConstant.cpp) needs to be taught to value-initialize when it sees ImplicitValueInitExprs. llvm-svn: 63317
* Clean up designated initialization of unions, so that CodeGen doesn'tDouglas Gregor2009-01-291-1/+2
| | | | | | have to try to guess which member is being initialized. llvm-svn: 63315
* Remove Expr::hasSideEffects. It doesn't work anywayDouglas Gregor2009-01-281-6/+0
| | | | llvm-svn: 63254
* Code generation support for C99 designated initializers.Douglas Gregor2009-01-281-2/+26
| | | | | | | | | | | | | | | | | | | | The approach I've taken in this patch is relatively straightforward, although the code itself is non-trivial. Essentially, as we process an initializer list we build up a fully-explicit representation of the initializer list, where each of the subobject initializations occurs in order. Designators serve to "fill in" subobject initializations in a non-linear way. The fully-explicit representation makes initializer lists (both with and without designators) easy to grok for codegen and later semantic analyses. We keep the syntactic form of the initializer list linked into the AST for those clients interested in exactly what the user wrote. Known limitations: - Designating a member of a union that isn't the first member may result in bogus initialization (we warn about this) - GNU array-range designators are not supported (we warn about this) llvm-svn: 63242
* Finish making AST BumpPtrAllocation runtime configurable (based on ↵Steve Naroff2009-01-271-4/+3
| | | | | | | | | | | -disable-free). snaroff% time ../../Release-Asserts/bin/clang INPUTS/Cocoa_h.m 0.179u 0.051s 0:00.23 95.6% 0+0k 0+0io 0pf+0w snaroff% time ../../Release-Asserts/bin/clang INPUTS/Cocoa_h.m -disable-free 0.169u 0.052s 0:00.22 95.4% 0+0k 0+0io 0pf+0w llvm-svn: 63153
* Fix compile error from r62953.Sebastian Redl2009-01-251-1/+2
| | | | llvm-svn: 62959
* One more case for Expr::isConstantInitializer; I think this covers Eli Friedman2009-01-251-0/+2
| | | | | | everything that we aren't intending to implement in Expr::Evaluate. llvm-svn: 62953
* Enhancements to Expr::isConstantInitializer to deal with a few Eli Friedman2009-01-251-6/+25
| | | | | | cases it couldn't deal with before. llvm-svn: 62952
* Rename Expr::isConstantExpr to Expr::isConstantInitializer; this more Eli Friedman2009-01-251-4/+3
| | | | | | | | accurately states what the function is trying to do and how it is different from Expr::isEvaluatable. Also get rid of a parameter that is both unused and inaccurate. llvm-svn: 62951
* Initial implementation of semantic analysis and ASTs for C99Douglas Gregor2009-01-221-0/+111
| | | | | | | | | | | | | | | | | | designated initializers. This implementation should cover all of the constraints in C99 6.7.8, including long, complex designations and computing the size of incomplete array types initialized with a designated initializer. Please see the new test-case and holler if you find cases where this doesn't work. There are still some wrinkles with GNU's anonymous structs and anonymous unions (it isn't clear how these should work; we'll just follow GCC's lead) and with designated initializers for the members of a union. I'll tackle those very soon. CodeGen is still nonexistent, and there's some leftover code in the parser's representation of designators that I'll also need to clean up. llvm-svn: 62737
* Support evaluation of vector constant expressions, and codegen of same.Nate Begeman2009-01-181-0/+5
| | | | llvm-svn: 62455
* A couple more vector component access fixes.Nate Begeman2009-01-181-0/+11
| | | | llvm-svn: 62443
* Update support for vector component access on ExtVectors.Nate Begeman2009-01-181-5/+8
| | | | llvm-svn: 62440
* Patch to supprt case of readonly property being Fariborz Jahanian2009-01-121-13/+1
| | | | | | | | assigned to when it has user declared setter method defined in the class implementation (but no declaration in the class itself). llvm-svn: 62098
* Add QualifiedDeclRefExpr, which retains additional source-locationDouglas Gregor2009-01-061-2/+5
| | | | | | | | | | | | | | | | | | | information for declarations that were referenced via a qualified-id, e.g., N::C::value. We keep track of the location of the start of the nested-name-specifier. Note that the difference between QualifiedDeclRefExpr and DeclRefExpr does have an effect on the semantics of function calls in two ways: 1) The use of a qualified-id instead of an unqualified-id suppresses argument-dependent lookup 2) If the name refers to a virtual function, the qualified-id version will call the function determined statically while the unqualified-id version will call the function determined dynamically (by looking up the appropriate function in the vtable). Neither of these features is implemented yet, but we do print out qualified names for QualifiedDeclRefExprs as part of the AST printing. llvm-svn: 61789
* PODness and Type TraitsSebastian Redl2009-01-051-0/+4
| | | | | | | | | | | | | | | Make C++ classes track the POD property (C++ [class]p4) Track the existence of a copy assignment operator. Implicitly declare the copy assignment operator if none is provided. Implement most of the parsing job for the G++ type traits extension. Fully implement the low-hanging fruit of the type traits: __is_pod: Whether a type is a POD. __is_class: Whether a type is a (non-union) class. __is_union: Whether a type is a union. __is_enum: Whether a type is an enum. __is_polymorphic: Whether a type is polymorphic (C++ [class.virtual]p1). llvm-svn: 61746
* Add support for calls to overloaded member functions. Things to note:Douglas Gregor2008-12-221-5/+6
| | | | | | | | | | | | - Overloading has to cope with having both static and non-static member functions in the overload set. - The call may or may not have an implicit object argument, depending on the syntax (x.f() vs. f()) and the context (static vs. non-static member function). - We now generate MemberExprs for implicit member access expression. - We now cope with mutable whenever we're building MemberExprs. llvm-svn: 61329
* Add support for member references (E1.E2, E1->E2) with C++ semantics,Douglas Gregor2008-12-201-16/+53
| | | | | | | | | | which can refer to static data members, enumerators, and member functions as well as to non-static data members. Implement correct lvalue computation for member references in C++. Compute the result type of non-static data members of reference type properly. llvm-svn: 61294
OpenPOWER on IntegriCloud