summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExpr.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Restructure the API in Type based on a conversation with Richard Smith.Chandler Carruth2011-06-201-1/+4
| | | | | | | | | | | This makes 'isPointerLikeType' a little less confusing, and pulls the decay check into a separate interface that is much more clear and concrete. Also, just implement these as logical wrappers around other predicates. Having a switch based implementation isn't likely to be necessary. We can try to optimize them later if they show up on a profile. llvm-svn: 133405
* Add test cases for false positives on -Wnull-arithmetic from RichardChandler Carruth2011-06-191-25/+8
| | | | | | | | | | | | | Trieu, and fix them by checking for array and function types as well as pointer types. I've added a predicate method on Type to bundle together the logic we're using here: isPointerLikeType(). I'd welcome better names for this predicate, this is the best I came up with. It's implemented as a switch to be a touch lighter weight than all the chained isa<...> casts that would result otherwise. llvm-svn: 133383
* Add a minor hack to avoid using isNullPointerConstant on a hot path. Fixes ↵Eli Friedman2011-06-171-6/+5
| | | | | | | | -O0 compile-time regressions from r133196. rdar://9629775 . llvm-svn: 133290
* Don't emit 'unavailable' errors inside an unavailable function. rdar://9623855.Argyrios Kyrtzidis2011-06-171-12/+14
| | | | llvm-svn: 133264
* Objective-C fast enumeration loop variables are not retained in ARC, butJohn McCall2011-06-171-10/+13
| | | | | | | | | | | | they should still be officially __strong for the purposes of errors, block capture, etc. Make a new bit on variables, isARCPseudoStrong(), and set this for 'self' and these enumeration-loop variables. Change the code that was looking for the old patterns to look for this bit, and change IR generation to find this bit and treat the resulting variable as __unsafe_unretained for the purposes of init/destroy in the two places it can come up. llvm-svn: 133243
* Implement proper support for generating code for compound literals inDouglas Gregor2011-06-171-2/+3
| | | | | | | | | | | | | C++, which means: - binding the temporary as needed in Sema, so that we generate the appropriate call to the destructor, and - emitting the compound literal into the appropriate location for the aggregate, rather than trying to emit it as a temporary and memcpy() it. Fixes PR10138 / <rdar://problem/9615901>. llvm-svn: 133235
* Check for placeholder expressions before promoting an argument passedDouglas Gregor2011-06-171-1/+5
| | | | | | through an ellipsis. Fixes <rdar://problem/9623945>. llvm-svn: 133219
* Add a new warning when a NULL constant is used in arithmetic operations. ↵Richard Trieu2011-06-161-0/+54
| | | | | | | | The warning will fire on cases such as: int x = 1 + NULL; llvm-svn: 133196
* Allow comparison between block pointers and NULL pointerDouglas Gregor2011-06-161-2/+4
| | | | | | constants. Fixes PR10145. llvm-svn: 133179
* arc: diagnose dereferencing a __weak pointer which may beFariborz Jahanian2011-06-161-0/+10
| | | | | | null at any time. // rdar://9612030 llvm-svn: 133168
* Refactor parentheses suggestion notes to have less code duplication andChandler Carruth2011-06-161-63/+36
| | | | | | | | | | be more consistent in how parenthesized ranges which hit macros are handled. Also makes the code significantly shorter, and the diagnostics when macros are present a bit more useful. Pair programmed w/ Matthew. llvm-svn: 133122
* Cleanup the parameter naming style.Chandler Carruth2011-06-161-8/+8
| | | | llvm-svn: 133120
* Automatic Reference Counting.John McCall2011-06-151-32/+197
| | | | | | | | | | Language-design credit goes to a lot of people, but I particularly want to single out Blaine Garst and Patrick Beard for their contributions. Compiler implementation credit goes to Argyrios, Doug, Fariborz, and myself, in no particular order. llvm-svn: 133103
* Warn on "void f(int a[10]) { sizeof(a); }"Nico Weber2011-06-151-0/+14
| | | | llvm-svn: 133036
* Sema: show shift result in hexadecimalTed Kremenek2011-06-151-3/+8
| | | | | | | | | | | | | | | | | Change the output for -Wshift-overflow and -Wshift-sign-overflow to an unsigned hexadecimal. It makes more sense for looking at bits than a signed decimal does. Also, change the diagnostic's wording from "overrides" to "sets". This uses a new optional argument in APInt::toString() that adds the '0x' prefix to hexademical numbers. This fixes PR 9651. Patch by nobled@dreamwidth.org! llvm-svn: 133033
* Properly diagnose using abstract and incomplete types in va_argDavid Majnemer2011-06-141-5/+17
| | | | | | | - Move a test from test/SemaTemplate/instantiate-expr-3.cpp, it did not belong there - Incomplete and abstract types are considered hard errors llvm-svn: 132979
* Give a diagnostic when using non-POD types in a va_argDavid Majnemer2011-06-131-1/+5
| | | | llvm-svn: 132905
* Implement support for C++11 in-class initialization of non-static data members.Richard Smith2011-06-111-13/+23
| | | | llvm-svn: 132878
* Implement Objective-C Related Result Type semantics.Douglas Gregor2011-06-111-8/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Related result types apply Cocoa conventions to the type of message sends and property accesses to Objective-C methods that are known to always return objects whose type is the same as the type of the receiving class (or a subclass thereof), such as +alloc and -init. This tightens up static type safety for Objective-C, so that we now diagnose mistakes like this: t.m:4:10: warning: incompatible pointer types initializing 'NSSet *' with an expression of type 'NSArray *' [-Wincompatible-pointer-types] NSSet *array = [[NSArray alloc] init]; ^ ~~~~~~~~~~~~~~~~~~~~~~ /System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:72:1: note: instance method 'init' is assumed to return an instance of its receiver type ('NSArray *') - (id)init; ^ It also means that we get decent type inference when writing code in Objective-C++0x: auto array = [[NSMutableArray alloc] initWithObjects:@"one", @"two",nil]; // ^ now infers NSMutableArray* rather than id llvm-svn: 132868
* Handle overloaded operators in ?: precedence warningHans Wennborg2011-06-091-38/+78
| | | | | | | | | | | | | | This is a follow-up to r132565, and should address the rest of PR9969: Warn about cases such as int foo(A a, bool b) { return a + b ? 1 : 2; // user probably meant a + (b ? 1 : 2); } also when + is an overloaded operator call. llvm-svn: 132784
* Modify a diagnostic introduced in r132612 to emit QualTypes directlyPeter Collingbourne2011-06-081-2/+2
| | | | | | | This fixes a memory error on FreeBSD (and is the right thing to do in any case). llvm-svn: 132750
* Add support for builtin astype:Tanya Lattner2011-06-041-0/+20
| | | | | | | __builtin_astype(): Used to reinterpreted as another data type of the same size using for both scalar and vector data types. Added test case. llvm-svn: 132612
* Warn about missing parentheses for conditional operator.Hans Wennborg2011-06-031-39/+107
| | | | | | | | | | Warn in cases such as "x + someCondition ? 42 : 0;", where the condition expression looks arithmetic, and has a right-hand side that looks boolean. This (partly) addresses http://llvm.org/bugs/show_bug.cgi?id=9969 llvm-svn: 132565
* Implement comparisons between nullptr and Objective-C objectDouglas Gregor2011-06-011-2/+2
| | | | | | pointers. Fixes PR10052. llvm-svn: 132397
* Expand the coverage of the warning for constants on the RHS of logical operands:Chandler Carruth2011-05-311-6/+8
| | | | | | | | | | | | return f() || -1; where the user meant to write '|'. This bootstraps without any additional warnings. Patch by Richard Trieu. llvm-svn: 132327
* Fix a regression in the source locations for unary trait expressions.Chandler Carruth2011-05-291-10/+5
| | | | | | | | | | | I tried to use an assert to prove that I could remove each of the arguments I did, but ended up writing my assert with inverted logic. Doh! Reported by Xi Wang on cfe-dev. I have manually verified the source locations and ranges for these using -ast-dump. I tried writing a test case that would catch these, but these expressions aren't exposed in the c-index-test's token annotation utility. llvm-svn: 132284
* Enhance Clang to start instantiating static data member definitionsChandler Carruth2011-05-271-6/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | within class templates when they are necessary to complete the type of the member. The canonical example is code like: template <typename T> struct S { static const int arr[]; static const int x; static int f(); }; template <typename T> const int S<T>::arr[] = { 1, 2, 3 }; template <typename T> const int S<T>::x = sizeof(arr) / sizeof(arr[0]); template <typename T> int S<T>::f() { return x; } int x = S<int>::f(); We need to instantiate S<T>::arr's definition to pick up its initializer and complete the array type. This involves new code to specially handle completing the type of an expression where the type alone is insufficient. It also requires *updating* the expression with the newly completed type. Fortunately, all the other infrastructure is already in Clang to do the instantiation, do the completion, and prune out the unused bits of code that result from this instantiation. This addresses the initial bug in PR10001, and will be a step to fleshing out other cases where we need to work harder to complete an expression's type. Who knew we still had missing C++03 "features"? llvm-svn: 132172
* Extract two more methods from the unary type trait checking. TheseChandler Carruth2011-05-261-19/+41
| | | | | | | | | | provide re-usable forms of the rest of the custom validation done here. Still no functionality changed here. With this it should be possible to have an expression-centric code path and a type-centric code path which don't duplicate logic. llvm-svn: 132118
* Remove a no longer relevant comment. It was just repeating theChandler Carruth2011-05-261-2/+1
| | | | | | | information in the previous comment which was preserved and moved with the vec_step implementation code. llvm-svn: 132117
* Extract the vec_step trait operand checking to a stand alone function.Chandler Carruth2011-05-261-15/+21
| | | | | | | It has little overlap with other traits' requirements, so the resulting code is actually simpler. llvm-svn: 132116
* Add a convenience interface for checking expression arguments to unaryChandler Carruth2011-05-261-25/+48
| | | | | | | | | | | | | traits which uses the information embedded in the expression. Use this to simplify several interfaces which repeated information embedded in the expression through explicit arguments. I added an assertion that the only extra piece of data to come in from the parser matches what is stored in the expression. No functionality change intended here. Also cleaned up the doxygen comments for some of these methods and some formatting oddities. llvm-svn: 132115
* Fix our handling of the warning when one tries to pass aDouglas Gregor2011-05-211-7/+27
| | | | | | | | | | | | non-POD/non-trivial object throuugh a C-style varargs. The warning itself was default-mapped to error, but can be downgraded, but we were treating it in Sema like a hard error, silently dropping the call. Instead, treat this problem like a warning, and do what the warning says we do: abort at runtime. To do so, we fake up a __builtin_trap() expression that gets evaluated as part of the argument. llvm-svn: 131805
* Implement C++0x semantics for passing non-POD classes through varargs.Douglas Gregor2011-05-211-5/+25
| | | | llvm-svn: 131792
* Make sure we actually generate defaulted copy constructors; caught byAlexis Hunt2011-05-141-1/+1
| | | | | | Howard Hinnant. Thanks! llvm-svn: 131349
* What I hope to be an implementation of defaulted copy assignmentAlexis Hunt2011-05-141-1/+1
| | | | | | operators. llvm-svn: 131338
* Defaulting copy constructors now works reasonably well.Alexis Hunt2011-05-131-3/+2
| | | | | | One more special member to go llvm-svn: 131287
* HrmAlexis Hunt2011-05-121-1/+1
| | | | llvm-svn: 131259
* Make it so that we actually generate definitions for explicitlyAlexis Hunt2011-05-121-2/+2
| | | | | | | | | | defaulted default constructors. As it happens, making sure that we handle out-of-line defaulted functions properly will involved making sure that we actually parse them correctly, so that's coming after. llvm-svn: 131224
* Rename "hasTrivialConstructor" to "hasTrivialDefaultConstructor" andAlexis Hunt2011-05-091-1/+1
| | | | | | | modify the semantics slightly to accomodate default constructors (I hope). llvm-svn: 131087
* Implement Sema::isExprCallable.Matt Beaumont-Gay2011-05-041-107/+39
| | | | | | | | We can use this to produce nice diagnostics (and try to fixit-and-recover) in various cases where we might see "MyFunction" instead of "MyFunction()". The changes in SemaExpr are an example of how to use isExprCallable. llvm-svn: 130878
* Add a warning for when reinterpret_cast leads to undefined behavior, patch ↵Argyrios Kyrtzidis2011-05-021-1/+7
| | | | | | by Richard Trieu! llvm-svn: 130703
* Add a decl update when a static data member of a class template is ↵Sebastian Redl2011-04-291-0/+4
| | | | | | instantiated in a different PCH than its containing class. Otherwise we get double definition errors. Fixes a Boost.MPL problem that affects Boost.Accumulators and probably a lot more of Boost. llvm-svn: 130488
* When block-capturing a variable with a non-trivial destructor,John McCall2011-04-281-2/+12
| | | | | | | | | | make sure to mark the destructor. This normally isn't required, because the destructor should have been marked as part of the declaration of the local, but it's necessary when the variable is a parameter because it's the call sites that are responsible for those destructors. llvm-svn: 130372
* FixOverloadedFunctionReference needs to rebuild member accesses of John McCall2011-04-271-8/+12
| | | | | | | | instance methods to have bound-member type. Fixing that broke __unknown_anytype, which I've in turn fixed. llvm-svn: 130266
* Make yet another placeholder type, this one marking that an expression is a ↵John McCall2011-04-261-81/+55
| | | | | | | | | | | bound member function, i.e. something of the form 'x.f' where 'f' is a non-static member function. Diagnose this in the general case. Some of the new diagnostics are probably worse than the old ones, but we now get this right much more universally, and there's certainly room for improvement in the diagnostics. llvm-svn: 130239
* Emit a -Wnull-dereference warning for "*null" not just "*null = something". ↵Argyrios Kyrtzidis2011-04-261-19/+22
| | | | | | Addresses rdar://9269271. llvm-svn: 130207
* For the warnings related to -Wparentheses, display first the note about how ↵Argyrios Kyrtzidis2011-04-251-16/+16
| | | | | | | | to silence the warning and any other suggestion after that. Related to rdar://9300260. llvm-svn: 130169
* Implement a new identifier-classification scheme where SemaDouglas Gregor2011-04-241-9/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | performs name lookup for an identifier and resolves it to a type/expression/template/etc. in the same step. This scheme is intended to improve both performance (by reducing the number of redundant name lookups for a given identifier token) and error recovery (by giving Sema a chance to correct type names before the parser has decided that the identifier isn't a type name). For example, this allows us to properly typo-correct type names at the beginning of a statement: t.c:6:3: error: use of undeclared identifier 'integer'; did you mean 'Integer'? integer *i = 0; ^~~~~~~ Integer t.c:1:13: note: 'Integer' declared here typedef int Integer; ^ Previously, we wouldn't give a Fix-It because the typo correction occurred after the parser had checked whether "integer" was a type name (via Sema::getTypeName(), which isn't allowed to typo-correct) and therefore decided to parse "integer * i = 0" as an expression. By typo-correcting earlier, we typo-correct to the type name Integer and parse this as a declaration. Moreover, in this context, we can also typo-correct identifiers to keywords, e.g., t.c:7:3: error: use of undeclared identifier 'vid'; did you mean 'void'? vid *p = i; ^~~ void and recover appropriately. Note that this is very much a work-in-progress. The new Sema::ClassifyName is only used for expression-or-declaration disambiguation in C at the statement level. The next steps will be to make this work for the same disambiguation in C++ (where functional-style casts make some trouble), then push it further into the parser to eliminate more redundant name lookups. Fixes <rdar://problem/7963833> for C and starts us down the path of <rdar://problem/8172000>. llvm-svn: 130082
* "note" location of forward class used as receiver ofFariborz Jahanian2011-04-231-1/+1
| | | | | | | a 'deprecated' selector in the diagnostics for the selector. // rdar://9309223 llvm-svn: 130062
* For -Wlogical-op-parentheses, point at '&&', not '||'. Fixes rdar://9125333.Argyrios Kyrtzidis2011-04-221-6/+5
| | | | llvm-svn: 130009
OpenPOWER on IntegriCloud