summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Make PragmaPackStack be a private class in SemaAttr and make itsChris Lattner2009-02-171-1/+1
| | | | | | instance in Sema be a pimpl. llvm-svn: 64718
* move attribute(packed) sema support out of SemaDecl into a new SemaAttr.cpp ↵Chris Lattner2009-02-171-94/+0
| | | | | | file. llvm-svn: 64711
* Support IRgen of sqrt -> llvm.sqrt, pow -> llvm.pow.Daniel Dunbar2009-02-161-0/+9
| | | | | | | | | | | | | | | | - Define pow[lf]?, sqrt[lf]? as builtins. - Add -fmath-errno option which binds to LangOptions.MathErrno - Add new builtin flag Builtin::Context::isConstWithoutErrno for functions which can be marked as const if errno isn't respected for math functions. Sema automatically marks these functions as const when they are defined, if MathErrno=0. - IRgen uses const attribute on sqrt and pow library functions to decide if it can use the llvm intrinsic. llvm-svn: 64689
* diagnose uses of deprecated typenames and tags.Chris Lattner2009-02-161-15/+29
| | | | | | We now pass all the deprecation tests in the objc.dg suite. llvm-svn: 64679
* Supply the header corresponding to a library builtin as a separate argument ↵Douglas Gregor2009-02-161-1/+1
| | | | | | to the LIBBUILTIN macro llvm-svn: 64676
* When merging from a function with a prototype to a function without aDouglas Gregor2009-02-161-5/+26
| | | | | | prototype, synthesize ParmVarDecls for prototype-less FunctionDecl. llvm-svn: 64666
* Remove FindIvarDeclaration. Use lookupInstanceVariable is is functionallyFariborz Jahanian2009-02-161-1/+1
| | | | | | the same. llvm-svn: 64657
* add assertionChris Lattner2009-02-161-0/+1
| | | | llvm-svn: 64652
* When a function with a prototype is redeclared without a prototype,Douglas Gregor2009-02-161-0/+17
| | | | | | | merge the prototype into the redeclaration (and make a note in the declaration). Fixes PR3588. llvm-svn: 64641
* Adopt a more principled approach to invalid declarations:Douglas Gregor2009-02-161-59/+84
| | | | | | | | | | | | | | | | | | | | | | | - If a declaration is an invalid redeclaration of an existing name, complain about the invalid redeclaration then avoid adding it to the AST (we can still parse the definition or initializer, if any). - If the declaration is invalid but there is no prior declaration with that name, introduce the invalid declaration into the AST (for later error recovery). - If the declaration is an invalid redeclaration of a builtin that starts with __builtin_, we produce an error and drop the redeclaration. If it is an invalid redeclaration of a library builtin (e.g., malloc, printf), warn (don't error!) and drop the redeclaration. If a user attempts to define a builtin, produce an error and (if it's a library builtin like malloc) suggest -ffreestanding. This addresses <rdar://problem/6097585> and PR2892. However, PR3588 is still going to cause some problems when builtins are redeclared without a prototype. llvm-svn: 64639
* lots of trailing whitespaceChris Lattner2009-02-151-1/+1
| | | | llvm-svn: 64613
* Refactor the deprecated and unavailable checks into a newChris Lattner2009-02-151-3/+2
| | | | | | | | | DiagnoseUseOfDeprecatedDecl method. This ensures that they are treated consistently. This gets us 'unavailable' support on a few new types of decls, and makes sure we consistently silence deprecated when the caller is also deprecated. llvm-svn: 64612
* Add hook to add attributes to function declarations that we knowDouglas Gregor2009-02-141-4/+69
| | | | | | | | | | | | | | | | 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-1/+13
| | | | | | | | 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-1/+1
| | | | | | | | | | | | | | | | | | | | | 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
* Implicitly declare certain C library functions (malloc, strcpy, memmove,Douglas Gregor2009-02-131-16/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Tighten checking of the "overloadable" attribute. If any function by aDouglas Gregor2009-02-131-14/+13
| | | | | | | | | | | | | | | | | | | given name in a given scope is marked as "overloadable", every function declaration and definition with that same name and in that same scope needs to have the "overloadable" attribute. Essentially, the "overloadable" attribute is not part of attribute merging, so it must be specified even for redeclarations. This keeps users from trying to be too sneaky for their own good: double sin(double) __attribute__((overloadable)); // too sneaky #include <math.h> Previously, this would have made "sin" overloadable, and therefore given it a mangled name. Now, we get an error inside math.h when we see a (re)declaration of "sin" that doesn't have the "overloadable" attribute. llvm-svn: 64414
* Initial implementation of function overloading in C.Douglas Gregor2009-02-111-3/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds a new attribute, "overloadable", that enables C++ function overloading in C. The attribute can only be added to function declarations, e.g., int *f(int) __attribute__((overloadable)); If the "overloadable" attribute exists on a function with a given name, *all* functions with that name (and in that scope) must have the "overloadable" attribute. Sets of overloaded functions with the "overloadable" attribute then follow the normal C++ rules for overloaded functions, e.g., overloads must have different parameter-type-lists from each other. When calling an overloaded function in C, we follow the same overloading rules as C++, with three extensions to the set of standard conversions: - A value of a given struct or union type T can be converted to the type T. This is just the identity conversion. (In C++, this would go through a copy constructor). - A value of pointer type T* can be converted to a value of type U* if T and U are compatible types. This conversion has Conversion rank (it's considered a pointer conversion in C). - A value of type T can be converted to a value of type U if T and U are compatible (and are not both pointer types). This conversion has Conversion rank (it's considered to be a new kind of conversion unique to C, a "compatible" conversion). Known defects (and, therefore, next steps): 1) The standard-conversion handling does not understand conversions involving _Complex or vector extensions, so it is likely to get these wrong. We need to add these conversions. 2) All overloadable functions with the same name will have the same linkage name, which means we'll get a collision in the linker (if not sooner). We'll need to mangle the names of these functions. llvm-svn: 64336
* Implement Declarator::getSourceRange().Sebastian Redl2009-02-091-2/+3
| | | | llvm-svn: 64151
* Make Sema::getTypeName return the opaque pointer of a QualType ratherDouglas Gregor2009-02-091-12/+18
| | | | | | | | | | | | | | | | than a Decl, which gives us some more flexibility to express the results with the type system. There are no clients using this flexibility yet, but it's meant to be able to describe qualified names as written in the source (e.g., "foo::type") or template-ids that name a class template specialization (e.g., "std::vector<INT>"). DeclSpec's TST_typedef has become TST_typename, to reflect its use to describe types found by name (that may or may not be typedefs). The type representation of a DeclSpec with TST_typename is an opaque QualType pointer. All users of TST_typedef, both direct and indirect, have been updated for these changes. llvm-svn: 64141
* Fix redundant errors with missing default arguments in member declarations.Sebastian Redl2009-02-081-2/+5
| | | | llvm-svn: 64085
* Fix redundant errors for redefinitions with multiple existing definitions.Sebastian Redl2009-02-081-0/+2
| | | | llvm-svn: 64081
* Overhaul of Stmt allocation:Ted Kremenek2009-02-071-10/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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
* Clean up an already-fixed FIXMEDouglas Gregor2009-02-061-7/+1
| | | | llvm-svn: 63975
* Semantic checking for class template declarations andDouglas Gregor2009-02-061-42/+5
| | | | | | | | | | | | | | | redeclarations. For example, checks that a class template redeclaration has the same template parameters as previous declarations. Detangled class-template checking from ActOnTag, whose logic was getting rather convoluted because it tried to handle C, C++, and C++ template semantics in one shot. Made some inroads toward eliminating extraneous "declaration does not declare anything" errors by adding an "error" type specifier. llvm-svn: 63973
* Diagnose attempts to define a namespace member out-of-line when noDouglas Gregor2009-02-061-47/+56
| | | | | | matching member exists. Thanks to Piotr Rak for reporting the problem! llvm-svn: 63939
* Improve documentation for Sema::getTypeName. Also, it's return type isDouglas Gregor2009-02-041-1/+11
| | | | | | DeclTy*, not TypeTy*. llvm-svn: 63756
* Basic representation of C++ class templates, from Andrew Sutton.Douglas Gregor2009-02-041-5/+41
| | | | llvm-svn: 63750
* Some name-lookup-related fixes, from Piotr Rak!Douglas Gregor2009-02-041-11/+11
| | | | | | | | | | | | | - 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
* Diagnose ambiguities in getTypeName. Fixes ↵Douglas Gregor2009-02-041-6/+6
| | | | | | http://llvm.org/bugs/show_bug.cgi?id=3475 llvm-svn: 63737
* When looking for a tag name via unqualified name lookup, only look inDouglas Gregor2009-02-031-1/+2
| | | | | | | scopes where the name would be considered a redeclaration if we know that we're declaring or defining that tag. llvm-svn: 63647
* Semantic analysis, ASTs, and unqualified name lookup support for C++Douglas Gregor2009-02-031-3/+20
| | | | | | using directives, from Piotr Rak! llvm-svn: 63646
* Simplify the way in which we inject the names of tag definitions andDouglas Gregor2009-02-031-19/+14
| | | | | | | | | | elaborated-type-specifier declarations into outer scopes while retaining their proper lexical scope. This way is simpler and more consistent with the way DeclContexts work, and also fixes http://llvm.org/bugs/show_bug.cgi?id=3430 llvm-svn: 63581
* emit diagnostic when casting a ptr to a small int when doing static ↵Nuno Lopes2009-02-021-3/+12
| | | | | | initialization (addresses Eli's comments I believe) llvm-svn: 63562
* fix TryToFixInvalidVariablyModifiedType to reject negative array sizesNuno Lopes2009-02-021-3/+4
| | | | llvm-svn: 63557
* Add iterators to LookupResult, allowing one to iterate over theDouglas Gregor2009-02-021-25/+12
| | | | | | | non-ambiguous name lookup results without allocating any memory, e.g., for sets of overloaded functions. llvm-svn: 63549
* allow cast from array to int to be considered as constantNuno Lopes2009-02-021-2/+1
| | | | llvm-svn: 63519
* fix PR3459: improve compatibility with gcc when checking for constant exprsNuno Lopes2009-02-021-4/+3
| | | | llvm-svn: 63517
* Implement and test aggregate initialization in C++. Major changes:Douglas Gregor2009-01-301-17/+1
| | | | | | | | | | | | | | | | - Support initialization of reference members; complain if any reference members are left uninitialized. - Use C++ copy-initialization for initializing each element (falls back to constraint checking in C) - Make sure we diagnose when one tries to provide an initializer list for a non-aggregate. - Don't complain about empty initializers in C++ (they are permitted) - Unrelated but necessary: don't bother trying to convert the decl-specifier-seq to a type when we're dealing with a C++ constructor, destructor, or conversion operator; it results in spurious warnings. llvm-svn: 63431
* Switch Type::isAggregateType to use the C++ definition of "aggregateDouglas Gregor2009-01-301-0/+1
| | | | | | | | type" rather than the C definition. We do this because both C99 and Clang always use "aggregate type" as "aggregate or union type", and the C++ definition includes union types. llvm-svn: 63395
* Eliminated LookupCriteria, whose creation was causing a bottleneck forDouglas Gregor2009-01-301-152/+23
| | | | | | | | | | | | | | | | | | LookupName et al. Instead, use an enum and a bool to describe its contents. Optimized the C/Objective-C path through LookupName, eliminating any unnecessarily C++isms. Simplify IdentifierResolver::iterator, removing some code and arguments that are no longer used. Eliminated LookupDeclInScope/LookupDeclInContext, moving all callers over to LookupName, LookupQualifiedName, or LookupParsedName, as appropriate. All together, I'm seeing a 0.2% speedup on Cocoa.h with PTH and -disable-free. Plus, we're down to three name-lookup routines. llvm-svn: 63354
* Hack Sema::LookupDeclInScope() to avoid calling Sema::LookupName() when ↵Steve Naroff2009-01-291-36/+102
| | | | | | | | parsing C/ObjC. This results in a 1.7% improvement for "Cocoa.h". If we can figure out how to return a "Decl *", rather than a Sema::LookupResult(), we will likely bump the speedup from 1.7%->2.5%. I verified this, however couldn't get it to work without breaking a fair number of C++ test cases. Will discuss with Doug offline. llvm-svn: 63320
* Introduce a new expression node, ImplicitValueInitExpr, thatDouglas Gregor2009-01-291-5/+5
| | | | | | | | | | | | | 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
* move library-specific diagnostic headers into library private dirs. ReduceChris Lattner2009-01-291-1/+0
| | | | | | redundant #includes. Patch by Anders Johnsen! llvm-svn: 63271
* Move InitListChecker out of Sema.hDouglas Gregor2009-01-291-5/+3
| | | | llvm-svn: 63258
* Refactor Sema::LookupDecl() into 2 functions: LookupDeclInScope() and ↵Steve Naroff2009-01-291-28/+44
| | | | | | | | | | LookupDeclInContext(). The previous interface was very confusing. This is much more explicit, which will be easier to understand/optimize/convert. The plan is to eventually deprecate both of these functions. For now, I'm focused on performance. llvm-svn: 63256
* Code generation support for C99 designated initializers.Douglas Gregor2009-01-281-0/+9
| | | | | | | | | | | | | | | | | | | | 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
* Name change (isTypeName->getTypeName).Steve Naroff2009-01-281-2/+2
| | | | | | Since it doesn't return a bool, is shouldn't be prefixed with 'is'. llvm-svn: 63226
* Complete semantic checking for typedef redeclarations in C++. TheDouglas Gregor2009-01-281-12/+45
| | | | | | | rules are slightly different than in C, and now we handle both dialects properly. llvm-svn: 63211
* Remove 'NamespaceNameOnly' argument to Sema::LookupDecl(). It is unused.Steve Naroff2009-01-281-10/+6
| | | | | | Even though Sema::LookupDecl() is deprecated, it's still used all over the place. Simplifying the interface will make it easier to understand/optimize/convert. llvm-svn: 63210
OpenPOWER on IntegriCloud