summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/Sema.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Eliminate post-diagnostic hooks. Instead, implement a Sema-specificDouglas Gregor2009-03-201-0/+16
| | | | | | | variant of DiagnosticBuilder that emits the template instantiation backtrace when needed. llvm-svn: 67413
* Remove ActiveScope (revert ↵Steve Naroff2009-03-131-2/+0
| | | | | | | | http://llvm.org/viewvc/llvm-project?view=rev&revision=65694 and http://llvm.org/viewvc/llvm-project?view=rev&revision=66741). Will replace with something better today... llvm-svn: 66893
* Add type checking for tentative definitions at the end of theDouglas Gregor2009-03-101-0/+45
| | | | | | | | | translation unit. Thread the various declarations of variables via VarDecl::getPreviousDeclaration. llvm-svn: 66601
* Fix <rdar://problem/6451399> problems with labels and blocks.Steve Naroff2009-02-281-0/+2
| | | | | | | | | - Move the 'LabelMap' from Sema to Scope. To avoid layering problems, the second element is now a 'StmtTy *', which makes the LabelMap a bit more verbose to deal with. - Add 'ActiveScope' to Sema. Managed by ActOnStartOfFunctionDef(), ObjCActOnStartOfMethodDef(), ActOnBlockStmtExpr(). - Changed ActOnLabelStmt(), ActOnGotoStmt(), ActOnAddrLabel(), and ActOnFinishFunctionBody() to use the new ActiveScope. - Added FIXME to workaround in ActOnFinishFunctionBody() (for dealing with C++ nested functions). llvm-svn: 65694
* replace a dirty hack with a clean solution. Too bad we can't Chris Lattner2009-02-191-4/+12
| | | | | | use Blocks for our callbacks ;-) llvm-svn: 65083
* Fix a long standard problem with clang retaining "too much" sugar Chris Lattner2009-02-191-6/+29
| | | | | | | | | | | | | | | | | | | | | | | | | information about types. We often print diagnostics where we say "foo_t" is bad, but the user doesn't know how foo_t is declared (because it is a typedef). Fix this by expanding sugar when present in a diagnostic (and not one of a few special cases, like vectors). Before: t.m:5:2: error: invalid operands to binary expression ('typeof(P)' and 'typeof(F)') MAX(P, F); ^~~~~~~~~ t.m:1:78: note: instantiated from: #define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; }) ^ After: t.m:5:2: error: invalid operands to binary expression ('typeof(P)' (aka 'struct mystruct') and 'typeof(F)' (aka 'float')) MAX(P, F); ^~~~~~~~~ t.m:1:78: note: instantiated from: #define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; }) ^ llvm-svn: 65081
* Add hook to add attributes to function declarations that we knowDouglas Gregor2009-02-141-0/+1
| | | | | | | | | | | | | | | | 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
* Make it possible for builtins to expression FILE* arguments, so thatDouglas Gregor2009-02-141-2/+0
| | | | | | | | we can define builtins such as fprintf, vfprintf, and __builtin___fprintf_chk. Give a nice error message when we need to implicitly declare a function like fprintf. llvm-svn: 64526
* Extend builtin "attribute" syntax to include a notation forDouglas Gregor2009-02-141-13/+2
| | | | | | | | | | | | | | | | | | | | | printf-like functions, both builtin functions and those in the C library. The function-call checker now queries this attribute do determine if we have a printf-like function, rather than scanning through the list of "known functions IDs". However, there are 5 functions they are not yet "builtins", so the function-call checker handles them specifically still: - fprintf and vfprintf: the builtins mechanism cannot (yet) express FILE* arguments, so these can't be encoded. - NSLog: the builtins mechanism cannot (yet) express NSString* arguments, so this (and NSLogv) can't be encoded. - asprintf and vasprintf: these aren't part of the C99 standard library, so we really shouldn't be defining them as builtins in the general case (and we don't seem to have the machinery to make them builtins only on certain targets and depending on whether extensions are enabled). llvm-svn: 64512
* Overhaul of Stmt allocation:Ted Kremenek2009-02-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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 semantic analysis for the GNU flexible array initializationDouglas Gregor2009-02-041-4/+6
| | | | | | | | | | | | | extension. The interaction with designated initializers is a bit... interesting... but we follow GNU's lead and don't permit too much crazy code in this area. Also, make the "excess initializers" error message a bit more informative. Addresses PR2561: http://llvm.org/bugs/show_bug.cgi?id=2561 llvm-svn: 63785
* Some name-lookup-related fixes, from Piotr Rak!Douglas Gregor2009-02-041-2/+8
| | | | | | | | | | | | | - Changes Lookup*Name functions to return NamedDecls, instead of Decls. Unfortunately my recent statement that it will simplify lot of code, was not quite right, but it simplifies some... - Makes MergeLookupResult SmallPtrSet instead of vector, following Douglas suggestions. - Adds %qN format for printing qualified names to Diagnostic. - Avoids searching for using-directives in Scopes, which are not DeclScope, during unqualified name lookup. llvm-svn: 63739
* move library-specific diagnostic headers into library private dirs. ReduceChris Lattner2009-01-291-1/+0
| | | | | | redundant #includes. Patch by Anders Johnsen! llvm-svn: 63271
* Split the single monolithic DiagnosticKinds.def file into oneChris Lattner2009-01-271-1/+1
| | | | | | | | | .def file for each library. This means that adding a diagnostic to sema doesn't require all the other libraries to be rebuilt. Patch by Anders Johnsen! llvm-svn: 63111
* inline Sema::getLangOptions, rdar://6515190. This speeds upChris Lattner2009-01-221-5/+2
| | | | | | fsyntax-only with PTH by 3%. llvm-svn: 62774
* Initial implementation of semantic analysis and ASTs for C99Douglas Gregor2009-01-221-2/+2
| | | | | | | | | | | | | | | | | | 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
* Remove ScopedDecl, collapsing all of its functionality into Decl, soDouglas Gregor2009-01-201-4/+4
| | | | | | | | | | | | | | | | that every declaration lives inside a DeclContext. Moved several things that don't have names but were ScopedDecls (and, therefore, NamedDecls) to inherit from Decl rather than NamedDecl, including ObjCImplementationDecl and LinkageSpecDecl. Now, we don't store empty DeclarationNames for these things, nor do we try to insert them into DeclContext's lookup structure. The serialization tests are temporarily disabled. We'll re-enable them once we've sorted out the remaining ownership/serialiazation issues between DeclContexts and TranslationUnion, DeclGroups, etc. llvm-svn: 62562
* Vector codegen improvementsNate Begeman2009-01-181-1/+1
| | | | llvm-svn: 62458
* Addressed the issue in <rdar://problem/6479085>, where we failed toDouglas Gregor2009-01-091-1/+1
| | | | | | | | | | | | | | | rewrite @class declarations that showed up within linkage specifications because those @class declarations never made it any place where the rewriter could find them. Moved all of the ObjC*Decl nodes over to ScopedDecls, so that they can live in the appropriate top-level or transparent DeclContext near the top level, e.g., TranslationUnitDecl or LinkageSpecDecl. Objective-C declarations now show up in a traversal of the declarations in a DeclContext (they didn't before!). This way, the rewriter finds all Objective-C declarations within linkage specifications. llvm-svn: 61966
* This is a large/messy diff that unifies the ObjC AST's with DeclContext.Steve Naroff2009-01-081-1/+1
| | | | | | | | | | | | | | | - ObjCContainerDecl's (ObjCInterfaceDecl/ObjCCategoryDecl/ObjCProtocolDecl), ObjCCategoryImpl, & ObjCImplementation are all DeclContexts. - ObjCMethodDecl is now a ScopedDecl (so it can play nicely with DeclContext). - ObjCContainerDecl now does iteration/lookup using DeclContext infrastructure (no more linear search:-) - Removed ASTContext argument to DeclContext::lookup(). It wasn't being used and complicated it's use from an ObjC AST perspective. - Added Sema::ProcessPropertyDecl() and removed Sema::diagnosePropertySetterGetterMismatch(). - Simplified Sema::ActOnAtEnd() considerably. Still more work to do. - Fixed an incorrect casting assumption in Sema::getCurFunctionOrMethodDecl(), now that ObjCMethodDecl is a ScopedDecl. - Removed addPropertyMethods from ObjCInterfaceDecl/ObjCCategoryDecl/ObjCProtocolDecl. This passes all the tests on my machine. Since many of the changes are central to the way ObjC finds it's methods, I expect some fallout (and there are still a handful of FIXME's). Nevertheless, this should be a step in the right direction. llvm-svn: 61929
* Expr and Stmt must be destroyed with Destroy, not delete. Fixes PR/3245.Sebastian Redl2008-12-221-2/+2
| | | | llvm-svn: 61335
* Unifies the name-lookup mechanisms used in various parts of the ASTDouglas Gregor2008-12-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | and separates lexical name lookup from qualified name lookup. In particular: * Make DeclContext the central data structure for storing and looking up declarations within existing declarations, e.g., members of structs/unions/classes, enumerators in C++0x enums, members of C++ namespaces, and (later) members of Objective-C interfaces/implementations. DeclContext uses a lazily-constructed data structure optimized for fast lookup (array for small contexts, hash table for larger contexts). * Implement C++ qualified name lookup in terms of lookup into DeclContext. * Implement C++ unqualified name lookup in terms of qualified+unqualified name lookup (since unqualified lookup is not purely lexical in C++!) * Limit the use of the chains of declarations stored in IdentifierInfo to those names declared lexically. * Eliminate CXXFieldDecl, collapsing its behavior into FieldDecl. (FieldDecl is now a ScopedDecl). * Make RecordDecl into a DeclContext and eliminates its Members/NumMembers fields (since one can just iterate through the DeclContext to get the fields). llvm-svn: 60878
* change getCurFunctionDecl to skip through Block contexts to findChris Lattner2008-12-041-0/+20
| | | | | | | | the containing block. Introduce a new getCurFunctionOrMethodDecl method to check to see if we're in a function or objc method. Minor cleanups to other related places. This fixes rdar://6405429. llvm-svn: 60564
* Overload resolution for the operator new function. Member version is still ↵Sebastian Redl2008-12-031-1/+2
| | | | | | untested. llvm-svn: 60503
* Rename Selector::getName() to Selector::getAsString(), and addChris Lattner2008-11-241-3/+14
| | | | | | | | | | | | | a new NamedDecl::getAsString() method. Change uses of Selector::getName() to just pass in a Selector where possible (e.g. to diagnostics) instead of going through an std::string. This also adds new formatters for objcinstance and objcclass as described in the dox. llvm-svn: 59933
* add support for inserting a DeclarationName into a diagnostic directlyChris Lattner2008-11-231-5/+12
| | | | | | | without calling getAsString(). This implicitly puts quotes around the name, so diagnostics need to be tweaked to accommodate this. llvm-svn: 59916
* Genericize the qualtype formating callback to support any diag argument.Chris Lattner2008-11-231-3/+4
| | | | | | No functionality change. llvm-svn: 59908
* Add support for sending QualType's directly into diags and convert twoChris Lattner2008-11-231-0/+19
| | | | | | | | | | diags over to use this. QualTypes implicitly print single quotes around them for uniformity and future extension. Doing this requires a little function pointer dance to prevent libbasic from depending on libast. llvm-svn: 59907
* move the Diag method for Sema to be inline. This shrinks the release-assertsChris Lattner2008-11-221-6/+2
| | | | | | | | | clang executable (when built with gcc 4.2 on the mac) from 14519740 to 14495028 bytes. This shrinks individual object files as well: SemaChecking from 23580->22248, SemaDeclObjc from 61368->57376, SemaExpr from 115628->110516, as well as several others. llvm-svn: 59867
* Split the DiagnosticInfo class into two disjoint classes:Chris Lattner2008-11-221-1/+1
| | | | | | | | | | one for building up the diagnostic that is in flight (DiagnosticBuilder) and one for pulling structured information out of the diagnostic when formatting and presenting it. There is no functionality change with this patch. llvm-svn: 59849
* remove the last old-fashioned Diag method. Transition complete!Chris Lattner2008-11-201-5/+0
| | | | llvm-svn: 59714
* remove another old Diag method.Chris Lattner2008-11-201-6/+0
| | | | llvm-svn: 59713
* remove another old-school Diag method.Chris Lattner2008-11-201-6/+0
| | | | llvm-svn: 59712
* remove the type_info identifier cache. Compared to the costChris Lattner2008-11-201-2/+0
| | | | | | | | | | | of doing the lookup_decl, the hash lookup is cheap. Also, typeid doesn't happen enough in real world code to worry about it. I'd like to eventually get rid of KnownFunctionIDs from Sema also, but today is not that day. llvm-svn: 59711
* compared to the rest of the code in Sema::GetStdNamespace(),Chris Lattner2008-11-201-1/+0
| | | | | | | looking up the "std" identifier is trivial. Just do it, particularly since this is only done if the namespace hasn't already been looked up. llvm-svn: 59710
* remove some other identifiers that are looked up really early and onlyChris Lattner2008-11-201-6/+0
| | | | | | used in one cold place. llvm-svn: 59709
* instead of looking up super at startup time, Chris Lattner2008-11-201-2/+0
| | | | | | | just check for it when needed. It doesn't incur real cost in any hot paths. llvm-svn: 59708
* remove one more old-style Diag method.Chris Lattner2008-11-191-7/+2
| | | | llvm-svn: 59589
* Switch several more Sema Diag methods over. This simplifies theChris Lattner2008-11-191-21/+4
| | | | | | | | __builtin_prefetch code to only emit one diagnostic per builtin_prefetch. While this has nothing to do with the rest of the patch, the code seemed like overkill when I was updating it. llvm-svn: 59588
* start converting Sema over to using its canonical Diag method.Chris Lattner2008-11-181-17/+0
| | | | llvm-svn: 59561
* introduce the one true Diag method for Sema. Next up: kill all the others off.Chris Lattner2008-11-181-3/+3
| | | | llvm-svn: 59556
* This reworks some of the Diagnostic interfaces a bit to change how diagnosticsChris Lattner2008-11-181-23/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | are formed. In particular, a diagnostic with all its strings and ranges is now packaged up and sent to DiagnosticClients as a DiagnosticInfo instead of as a ton of random stuff. This has the benefit of simplifying the interface, making it more extensible, and allowing us to do more checking for things like access past the end of the various arrays passed in. In addition to introducing DiagnosticInfo, this also substantially changes how Diagnostic::Report works. Instead of being passed in all of the info required to issue a diagnostic, Report now takes only the required info (a location and ID) and returns a fresh DiagnosticInfo *by value*. The caller is then free to stuff strings and ranges into the DiagnosticInfo with the << operator. When the dtor runs on the DiagnosticInfo object (which should happen at the end of the statement), the diagnostic is actually emitted with all of the accumulated information. This is a somewhat tricky dance, but it means that the accumulated DiagnosticInfo is allowed to keep pointers to other expression temporaries without those pointers getting invalidated. This is just the minimal change to get this stuff working, but this will allow us to eliminate the zillions of variant "Diag" methods scattered throughout (e.g.) sema. For example, instead of calling: Diag(BuiltinLoc, diag::err_overload_no_match, typeNames, SourceRange(BuiltinLoc, RParenLoc)); We will soon be able to just do: Diag(BuiltinLoc, diag::err_overload_no_match) << typeNames << SourceRange(BuiltinLoc, RParenLoc)); This scales better to support arbitrary types being passed in (not just strings) in a type-safe way. Go operator overloading?! llvm-svn: 59502
* Change the diagnostics interface to take an array of pointers to Chris Lattner2008-11-181-8/+11
| | | | | | | | strings instead of array of strings. This reduces string copying in some not-very-important cases, but paves the way for future improvements. llvm-svn: 59494
* Fix <rdar://problem/6320086> parser rejects block capturing ivar.Steve Naroff2008-11-171-1/+4
| | | | llvm-svn: 59444
* Implement support for operator overloading using candidate operatorDouglas Gregor2008-11-121-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | functions for built-in operators, e.g., the builtin bool operator==(int const*, int const*) can be used for the expression "x1 == x2" given: struct X { operator int const*(); } x1, x2; The scheme for handling these built-in operators is relatively simple: for each candidate required by the standard, create a special kind of candidate function for the built-in. If overload resolution picks the built-in operator, we perform the appropriate conversions on the arguments and then let the normal built-in operator take care of it. There may be some optimization opportunity left: if we can reduce the number of built-in operator overloads we generate, overload resolution for these cases will go faster. However, one must be careful when doing this: GCC generates too few operator overloads in our little test program, and fails to compile it because none of the overloads it generates match. Note that we only support operator overload for non-member binary operators at the moment. The other operators will follow. As part of this change, ImplicitCastExpr can now be an lvalue. llvm-svn: 59148
* Implement C++ 'typeid' parsing and sema.Sebastian Redl2008-11-111-0/+4
| | | | llvm-svn: 59042
* Implement Sema support for C++ nested-name-specifiers.Argyrios Kyrtzidis2008-11-081-3/+3
| | | | llvm-svn: 58916
* Some cleanup of the cast checkers. Don't canonicalize types when not needed. ↵Sebastian Redl2008-11-041-7/+0
| | | | | | Use distinct diagnostics for distinct errors. llvm-svn: 58700
* Semantic analysis for C++ reinterpret_cast and const_cast. Patch by ↵Douglas Gregor2008-10-241-0/+7
| | | | | | Sebastian Redl. llvm-svn: 58094
* Add Sema implementation of #pragma pack stack. Daniel Dunbar2008-10-141-1/+1
| | | | | | | | | | | - Follows the MSVC (original) implementation, including support of pack(show) (useful for testing). - Implements support for named pack records which gcc seems to ignore (or implements incorrectly). - Not currently wired to anything, only functionality change is the type checking of the pragma. llvm-svn: 57476
OpenPOWER on IntegriCloud