summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Expr.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Update documentation of HasSideEffects to match its callers' expectations, andRichard Smith2012-08-071-20/+18
| | | | | | | | | | | | update implementation to match. An elidable, non-trivial constructor call is a side-effect under this definition, but wasn't under the old one, because we are not required to evaluate it even though it may have an effect. Also rationalize checking for volatile reads: just look for lvalue-to-rvalue conversions on volatile glvalues, and ignore whether a DeclRefExpr etc is for a volatile variable. llvm-svn: 161393
* Teach Expr::HasSideEffects about all the Expr types, and fix a bug where itRichard Smith2012-08-071-0/+215
| | | | | | | | | | | | | | | | | | | was mistakenly classifying dynamic_casts which might throw as having no side effects. Switch it from a visitor to a switch, so it is kept up-to-date as future Expr nodes are added. Move it from ExprConstant.cpp to Expr.cpp, since it's not really related to constant expression evaluation. Since we use HasSideEffect to determine whether to emit an unused global with internal linkage, this has the effect of suppressing emission of globals in some cases. I've left many of the Objective-C cases conservatively assuming that the expression has side-effects. I'll leave it to someone with better knowledge of Objective-C than mine to improve them. llvm-svn: 161388
* Handle the case where the base type is not dependent, but the derived one is.Rafael Espindola2012-07-171-0/+3
| | | | | | Fixes pr13353.cpp. llvm-svn: 160393
* Drop the ASTContext.h include from Stmt.h and fix up transitive users.Benjamin Kramer2012-07-041-0/+28
| | | | | | | | | | | | | | This required moving the ctors for IntegerLiteral and FloatingLiteral out of line which shouldn't change anything as they are usually called through Create methods that are already out of line. ASTContext::Deallocate has been a nop for a long time, drop it from ASTVector and make it independent from ASTContext.h Pass the StorageAllocator directly to AccessedEntity so it doesn't need to have a definition of ASTContext around. llvm-svn: 159718
* Fix another issue with devirtualizing calls to final methods by passing themRafael Espindola2012-06-281-16/+22
| | | | | | | | the correct this pointer. There is some potential for sharing a bit more code with canDevirtualizeMemberFunctionCalls, but that can be done in an independent patch. llvm-svn: 159326
* Implement John McCall's review of r159212 other than the this pointer notRafael Espindola2012-06-271-6/+1
| | | | | | being updated. Will fix that in a second. llvm-svn: 159280
* During codegen of a virtual call we would extract any casts in the expressionRafael Espindola2012-06-261-0/+31
| | | | | | | | to see if we had an underlying final class or method, but we would then use the cast type to do the call, resulting in a direct call to the wrong method. llvm-svn: 159212
* Make the ".*" operator work correctly when the base is a prvalue and the ↵Eli Friedman2012-06-151-0/+4
| | | | | | field has a non-trivial copy constructor. PR13097. llvm-svn: 158578
* Moved the StringLiteral printing code from StmtPrinter into the StringLiteralRichard Trieu2012-06-131-0/+93
| | | | | | | class and have StmtPrinter and StmtDumper refer to it. This fixes an assertion failure when dumping wchar string literals. llvm-svn: 158417
* PR13099: Teach -Wformat about raw string literals, UTF-8 strings and Unicode ↵Richard Smith2012-06-131-1/+2
| | | | | | escape sequences. llvm-svn: 158390
* Remove unused variable.Dmitri Gribenko2012-06-121-5/+0
| | | | llvm-svn: 158343
* A minor tweak to the new volatile lvalue warning: don't warn on "(void)x", ↵Eli Friedman2012-05-241-25/+22
| | | | | | where "x" refers to a local variable. This should silence a useless warning in compiler-rt and other places. llvm-svn: 157414
* Add a warning to diagnose statements in C++ like "*(volatile int*)x;". ↵Eli Friedman2012-05-241-48/+73
| | | | | | Conceptually, this is part of -Wunused-value, but I added a separate flag -Wunused-volatile-lvalue so it doesn't get turned off by accident with -Wno-unused-value. I also made a few minor improvements to existing unused value warnings in the process. <rdar://problem/11516811>. llvm-svn: 157362
* The Lexer constructor expects a source location at the start of theArgyrios Kyrtzidis2012-05-111-2/+2
| | | | | | | | file buffer, not at the start of lexing. Fixes assertion hit in format diagnostics. rdar://11418366 llvm-svn: 156647
* Use raw_ostream in TypePrinter and eliminate uses of temporary std::strings.Argyrios Kyrtzidis2012-05-051-3/+1
| | | | | | Part of rdar://10796159 llvm-svn: 156228
* Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.Richard Smith2012-04-171-325/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | We have a new flavor of exception specification, EST_Uninstantiated. A function type with this exception specification carries a pointer to a FunctionDecl, and the exception specification for that FunctionDecl is instantiated (if needed) and used in the place of the function type's exception specification. When a function template declaration with a non-trivial exception specification is instantiated, the specialization's exception specification is set to this new 'uninstantiated' kind rather than being instantiated immediately. Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs on-demand. Also, any odr-use of a function triggers the instantiation of its exception specification (the exception specification could be needed by IRGen). In passing, fix two places where a DeclRefExpr was created but the corresponding function was not actually marked odr-used. We used to get away with this, but don't any more. Also fix a bug where instantiating an exception specification which refers to function parameters resulted in a crash. We still have the same bug in default arguments, which I'll be looking into next. This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to parse (and, in very limited testing, support) all of libstdc++4.7's standard headers. llvm-svn: 154886
* PR12226: don't generate wrong code if a braced string literal is used toRichard Smith2012-04-151-0/+10
| | | | | | | | | initialize an array of unsigned char. Outside C++11 mode, this bug was benign, and just resulted in us emitting a constant which was double the required length, padded with 0s. In C++11, it resulted in us generating an array whose first element was something like i8 ptrtoint ([n x i8]* @str to i8). llvm-svn: 154756
* Implement __atomic_fetch_nand and __atomic_nand_fetch to complete our set ofRichard Smith2012-04-131-0/+2
| | | | | | GNU __atomic builtins. llvm-svn: 154659
* Implement support for 18 of the GNU-compatible __atomic builtins.Richard Smith2012-04-121-11/+35
| | | | | | | | | | | | This is not quite sufficient for libstdc++'s <atomic>: we still need __atomic_test_and_set and __atomic_clear, and may need a more complete __atomic_is_lock_free implementation. We are also missing an implementation of __atomic_always_lock_free, __atomic_nand_fetch, and __atomic_fetch_nand, but those aren't needed for libstdc++. llvm-svn: 154579
* AtomicExpr: make ASTStmtReader a friend and remove setters. Also fix savingRichard Smith2012-04-101-0/+21
| | | | | | | of an uninitialized Stmt* in serialization of __atomic_init and add a test of atomics serialization. llvm-svn: 154448
* Improve the printing of __PRETTY_FUNCTION__ more provide moreDouglas Gregor2012-04-101-9/+69
| | | | | | information and more closely match GCC's, from Nikola Smiljanic! llvm-svn: 154430
* ObjCBoolLiterals (__objc_yes/__objc_no) behave like C++ booleans ↵Jordy Rose2012-03-121-1/+1
| | | | | | (true/false). They are NOT objects. llvm-svn: 152564
* Unify naming of LangOptions variable/get function across the Clang stack ↵David Blaikie2012-03-111-6/+6
| | | | | | | | | | (Lex to AST). The member variable is always "LangOpts" and the member function is always "getLangOpts". Reviewed by Chris Lattner llvm-svn: 152536
* Remove BlockDeclRefExpr and introduce a bit on DeclRefExpr toJohn McCall2012-03-101-27/+8
| | | | | | | | track whether the referenced declaration comes from an enclosing local context. I'm amenable to suggestions about the exact meaning of this bit. llvm-svn: 152491
* [AST] Define a few more key getLocStart() implementations.Daniel Dunbar2012-03-091-0/+18
| | | | | | | - This cuts the # of getSourceRange calls by 60% on OGF/NSBezierPath-OAExtensions.m. llvm-svn: 152412
* [AST] Reimplement Stmt::getLoc{Start,End} to dispatch to subclass overloads.Daniel Dunbar2012-03-091-1/+3
| | | | | | | | - getSourceRange() can be very expensive, we should try to avoid it if at all possible. In conjunction with the previous commit I measured a ~2% speedup on 403.gcc/combine.c and a 3% speedup on OmniGroupFrameworks/NSBezierPath-OAExtensions.m. llvm-svn: 152411
* [AST] Add {DeclRefExpr,MemberExpr,ImplicitCastExpr}::{getLocStart,getLocEnd} ↵Daniel Dunbar2012-03-091-14/+26
| | | | | | | | methods. - There are probably a lot more of these worth adding, but these are a start at hitting some of the exprs for which getSourceRange().getBegin() is a poor substitute for getLocStart(). llvm-svn: 152410
* [AST] Reduce Decl::getASTContext() calls.Daniel Dunbar2012-03-091-11/+12
| | | | | | | - This function is not at all free; pass it around along some hot paths instead of recomputing it deep inside various VarDecl methods. llvm-svn: 152363
* AST representation for user-defined literals, plus just enough of semanticRichard Smith2012-03-071-2/+4
| | | | | | | | | | | | | | | | | | | | | analysis to make the AST representation testable. They are represented by a new UserDefinedLiteral AST node, which is a sugared CallExpr. All semantic properties, including full CodeGen support, are achieved for free by this representation. UserDefinedLiterals can never be dependent, so no custom instantiation behavior is required. They are mangled as if they were direct calls to the underlying literal operator. This matches g++'s apparent behavior (but not its actual mangling, which is broken for literal-operator-ids). User-defined *string* literals are now fully-operational, but the semantic analysis is quite hacky and needs more work. No other forms of user-defined literal are created yet, but the AST support for them is present. This patch committed after midnight because we had already hit the quota for new kinds of literal yesterday. llvm-svn: 152211
* Add clang support for new Objective-C literal syntax for NSDictionary, NSArray,Ted Kremenek2012-03-061-0/+121
| | | | | | | | | | | | | NSNumber, and boolean literals. This includes both Sema and Codegen support. Included is also support for new Objective-C container subscripting. My apologies for the large patch. It was very difficult to break apart. The patch introduces changes to the driver as well to cause clang to link in additional runtime support when needed to support the new language features. Docs are forthcoming to document the implementation and behavior of these features. llvm-svn: 152137
* Fix a couple -Wuninitialized warnings from gcc. Reported by David Greene.Eli Friedman2012-02-291-1/+2
| | | | llvm-svn: 151754
* ArrayRef'ize various functions in the AST/Parser/Sema.Ahmed Charles2012-02-251-12/+2
| | | | llvm-svn: 151447
* Revert r151357. That unreachable is reachable...Nick Lewycky2012-02-241-11/+8
| | | | llvm-svn: 151359
* Silence gcc warnings pointing out that CharByteWidth could be usedNick Lewycky2012-02-241-8/+11
| | | | | | uninitialized. While there, restyle this function! No functionality change. llvm-svn: 151357
* Implement a new type trait __is_trivially_constructible(T, Args...)Douglas Gregor2012-02-241-0/+1
| | | | | | | | | | | | | | | | that provides the behavior of the C++11 library trait std::is_trivially_constructible<T, Args...>, which can't be implemented purely as a library. Since __is_trivially_constructible can have zero or more arguments, I needed to add Yet Another Type Trait Expression Class, this one handling arbitrary arguments. The next step will be to migrate UnaryTypeTrait and BinaryTypeTrait over to this new, more general TypeTrait class. Fixes the Clang side of <rdar://problem/10895483> / PR12038. llvm-svn: 151352
* Seriously, are injected-class-names that hard?Douglas Gregor2012-02-231-1/+1
| | | | llvm-svn: 151241
* Provide the __is_trivially_assignable type trait, which providesDouglas Gregor2012-02-231-0/+55
| | | | | | | compiler support for the std::is_trivially_assignable library type trait. llvm-svn: 151240
* Generate an AST for the conversion from a lambda closure type to aDouglas Gregor2012-02-221-0/+7
| | | | | | | | | | | | | | | block pointer that returns a block literal which captures (by copy) the lambda closure itself. Some aspects of the block literal are left unspecified, namely the capture variable (which doesn't actually exist) and the body (which will be filled in by IRgen because it can't be written as an AST). Because we're switching to this model, this patch also eliminates tracking the copy-initialization expression for the block capture of the conversion function, since that information is now embedded in the synthesized block literal. -1 side tables FTW. llvm-svn: 151131
* ObjCMessageExpr: Don't leave SelLocsKind uninitialized when the send is ↵Benjamin Kramer2012-02-201-1/+1
| | | | | | | | implicit. Fixes PR11929. Found by valgrind. llvm-svn: 150943
* Basic code generation support for std::initializer_list.Sebastian Redl2012-02-171-3/+4
| | | | | | | | | | | | | | | | | | | | | | | We now generate temporary arrays to back std::initializer_list objects initialized with braces. The initializer_list is then made to point at the array. We support both ptr+size and start+end forms, although the latter is untested. Array lifetime is correct for temporary std::initializer_lists (e.g. call arguments) and local variables. It is untested for new expressions and member initializers. Things left to do: Massively increase the amount of testing. I need to write tests for start+end init lists, temporary objects created as a side effect of initializing init list objects, new expressions, member initialization, creation of temporary objects (e.g. std::vector) for initializer lists, and probably more. Get lifetime "right" for member initializers and new expressions. Not that either are very useful. Implement list-initialization of array new expressions. llvm-svn: 150803
* Block expressions always have a prototyped function type; expose thisJohn McCall2012-02-171-3/+4
| | | | | | in the AST accessor and micro-optimize it very slightly. llvm-svn: 150787
* Revert "Revert "Make CXXNewExpr contain only a single initialier, and not ↵Sebastian Redl2012-02-161-4/+1
| | | | | | | | hold the used constructor itself."" This reintroduces commit r150682 with a fix for the Bullet benchmark crash. llvm-svn: 150685
* Revert "Make CXXNewExpr contain only a single initialier, and not hold the ↵Sebastian Redl2012-02-161-1/+4
| | | | | | | | | | used constructor itself." It leads to a compiler crash in the Bullet benchmark. This reverts commit r12014. llvm-svn: 150684
* Make CXXNewExpr contain only a single initialier, and not hold the used ↵Sebastian Redl2012-02-161-4/+1
| | | | | | | | | | constructor itself. Holding the constructor directly makes no sense when list-initialized arrays come into play. The constructor is now held in a CXXConstructExpr, if construction is what is done. The new design can also distinguish properly between list-initialization and direct-initialization, as well as implicit default-initialization constructors and explicit value-initialization constructors. Finally, doing it this way removes redundance from the AST because CXXNewExpr doesn't try to handle both the allocation and the initialization responsibilities. This breaks the static analysis of new expressions. I've filed PR12014 to track this. llvm-svn: 150682
* Split reinterpret_casts of member pointers out from CK_BitCast; thisJohn McCall2012-02-151-0/+7
| | | | | | | | | | | | | | | | | | | | | is general goodness because representations of member pointers are not always equivalent across member pointer types on all ABIs (even though this isn't really standard-endorsed). Take advantage of the new information to teach IR-generation how to do these reinterprets in constant initializers. Make sure this works when intermingled with hierarchy conversions (although this is not part of our motivating use case). Doing this in the constant-evaluator would probably have been better, but that would require a *lot* of extra structure in the representation of constant member pointers: you'd really have to track an arbitrary chain of hierarchy conversions and reinterpretations in order to get this right. Ultimately, this seems less complex. I also wasn't quite sure how to extend the constant evaluator to handle foldings that we don't actually want to treat as extended constant expressions. llvm-svn: 150551
* Pending clear answer from WG21 on whether core issue 903 is intended to apply toRichard Smith2012-02-141-4/+11
| | | | | | | C++11 or just C++17, restrict the set of null pointer constants in C++11 mode back to those which were considered null in C++98. llvm-svn: 150510
* Represent C++ direct initializers as ParenListExprs before semantic analysisSebastian Redl2012-02-111-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | instead of having a special-purpose function. - ActOnCXXDirectInitializer, which was mostly duplication of AddInitializerToDecl (leading e.g. to PR10620, which Eli fixed a few days ago), is dropped completely. - MultiInitializer, which was an ugly hack I added, is dropped again. - We now have the infrastructure in place to distinguish between int x = {1}; int x({1}); int x{1}; -- VarDecl now has getInitStyle(), which indicates which of the above was used. -- CXXConstructExpr now has a flag to indicate that it represents list- initialization, although this is not yet used. - InstantiateInitializer was renamed to SubstInitializer and simplified. - ActOnParenOrParenListExpr has been replaced by ActOnParenListExpr, which always produces a ParenListExpr. Placed that so far failed to convert that back to a ParenExpr containing comma operators have been fixed. I'm pretty sure I could have made a crashing test case before this. The end result is a (I hope) considerably cleaner design of initializers. More importantly, the fact that I can now distinguish between the various initialization kinds means that I can get the tricky generalized initializer test cases Johannes Schaub supplied to work. (This is not yet done.) This commit passed self-host, with the resulting compiler passing the tests. I hope it doesn't break more complicated code. It's a pretty big change, but one that I feel is necessary. llvm-svn: 150318
* Switch the ObjC*Decl raw_stream overloads to take a reference, for ↵Benjamin Kramer2012-02-071-1/+1
| | | | | | consistency with NamedDecls. llvm-svn: 149981
* Introduce basic ASTs for lambda expressions. This covers:Douglas Gregor2012-02-071-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | - Capturing variables by-reference and by-copy within a lambda - The representation of lambda captures - The creation of the non-static data members in the lambda class that store the captured variables - The initialization of the non-static data members from the captured variables - Pretty-printing lambda expressions There are a number of FIXMEs, both explicit and implied, including: - Creating a field for a capture of 'this' - Improved diagnostics for initialization failures when capturing variables by copy - Dealing with temporaries created during said initialization - Template instantiation - AST (de-)serialization - Binding and returning the lambda expression; turning it into a proper temporary - Lots and lots of semantic constraints - Parameter pack captures llvm-svn: 149977
* Basic: import SmallString<> into clang namespaceDylan Noblesmith2012-02-051-2/+2
| | | | | | | (I was going to fix the TODO about DenseMap too, but that would break self-host right now. See PR11922.) llvm-svn: 149799
OpenPOWER on IntegriCloud