summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaChecking.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* 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
* Overhaul of Stmt allocation:Ted Kremenek2009-02-071-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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
* 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
* Convert more expression actions to smart pointers.Sebastian Redl2009-01-191-47/+52
| | | | | | Fix type of logical negation for C++. llvm-svn: 62475
* Patch by Roman Divacky:Ted Kremenek2009-01-121-9/+53
| | | | | | | | | Extend string-literal checking for printf() format string to handle conditional ternary operators where both sides are literals. This fixes PR 3319: http://llvm.org/bugs/show_bug.cgi?id=3319 llvm-svn: 62117
* Add QualifiedDeclRefExpr, which retains additional source-locationDouglas Gregor2009-01-061-1/+2
| | | | | | | | | | | | | | | | | | | 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
* Make error handling for va_start a bit more robust. Fixes PR3213.Eli Friedman2008-12-151-5/+14
| | | | llvm-svn: 61055
* change getCurFunctionDecl to skip through Block contexts to findChris Lattner2008-12-041-2/+2
| | | | | | | | 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
* Change a whole lot of diagnostics to take QualType's directly Chris Lattner2008-11-241-3/+3
| | | | | | | | instead of converting them to strings first. This also fixes a bunch of minor inconsistencies in the diagnostics emitted by clang and adds a bunch of FIXME's to DiagnosticKinds.def. llvm-svn: 59948
* Convert IdentifierInfo's to be printed the same as DeclarationNames Chris Lattner2008-11-231-3/+2
| | | | | | | | | | | | | | | | | | | | | with implicit quotes around them. This has a bunch of follow-on effects and requires tweaking to a whole lot of code. This causes a regression in two tests (xfailed) by causing it to emit things like: Line 10: duplicate interface declaration for category 'MyClass1' ('Category1') instead of: Line 10: duplicate interface declaration for category 'MyClass1(Category1)' I will fix this in a follow-up commit. As part of this, I had to start switching stuff to use ->getDeclName() instead of Decl::getName() for consistency. This is good, but I was planning to do this as an independent patch. There will be several follow-on patches to clean up some of the mess, but this patch is already too big. llvm-svn: 59917
* merge some simple call diagnostics.Chris Lattner2008-11-211-7/+9
| | | | llvm-svn: 59831
* remove another old-school Diag method.Chris Lattner2008-11-201-11/+11
| | | | llvm-svn: 59712
* stop calling II::getName() unnecesarily in semaChris Lattner2008-11-191-4/+3
| | | | llvm-svn: 59609
* remove one more old-style Diag method.Chris Lattner2008-11-191-28/+28
| | | | llvm-svn: 59589
* Switch several more Sema Diag methods over. This simplifies theChris Lattner2008-11-191-63/+53
| | | | | | | | __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
* Updated IdentifierResolver to deal with DeclarationNames. The names ofDouglas Gregor2008-11-171-1/+6
| | | | | | | | | | | | | | | | | | | | | C++ constructors, destructors, and conversion functions now have a FETokenInfo field that IdentifierResolver can access, so that these special names are handled just like ordinary identifiers. A few other Sema routines now use DeclarationNames instead of IdentifierInfo*'s. To validate this design, this code also implements parsing and semantic analysis for id-expressions that name conversion functions, e.g., return operator bool(); The new parser action ActOnConversionFunctionExpr takes the result of parsing "operator type-id" and turning it into an expression, using the IdentifierResolver with the DeclarationName of the conversion function. ActOnDeclarator pushes those conversion function names into scope so that the IdentifierResolver can find them, of course. llvm-svn: 59462
* Implement initialization of a reference (C++ [dcl.init.ref]) as partDouglas Gregor2008-10-291-1/+1
| | | | | | | | | | | | | | | | | | | of copy initialization. Other pieces of the puzzle: - Try/Perform-ImplicitConversion now handles implicit conversions that don't involve references. - Try/Perform-CopyInitialization uses CheckSingleAssignmentConstraints for C. PerformCopyInitialization is now used for all argument passing and returning values from a function. - Diagnose errors with declaring references and const values without an initializer. (Uses a new Action callback, ActOnUninitializedDecl). We do not yet have implicit conversion sequences for reference binding, which means that we don't have any overloading support for reference parameters yet. llvm-svn: 58353
* Rename ExplicitCCastExpr to CStyleCastExprDouglas Gregor2008-10-281-1/+1
| | | | llvm-svn: 58331
* Refactor the expression class hierarchy for casts. Most importantly:Douglas Gregor2008-10-271-19/+18
| | | | | | | | | | | | | | | | | | | | | | - CastExpr is the root of all casts - ImplicitCastExpr is (still) used for all explicit casts - ExplicitCastExpr is now the root of all *explicit* casts - ExplicitCCastExpr (new name needed!?) is a C-style cast in C or C++ - CXXFunctionalCastExpr inherits from ExplicitCastExpr - CXXNamedCastExpr inherits from ExplicitCastExpr and is the root of all of the C++ named cast expression types (static_cast, dynamic_cast, etc.) - Added classes CXXStaticCastExpr, CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr to Also, fixed returned-stack-addr.cpp, which broke once when we fixed reinterpret_cast to diagnose double->int* conversions and again when we eliminated implicit conversions to reference types. The fix is in both testcase and SemaChecking.cpp. Most of this patch is simply support for the renaming. There's very little actual change in semantics. llvm-svn: 58264
* Add support for format string checking of object-size checkingDaniel Dunbar2008-10-021-12/+20
| | | | | | | versions of sprintf and friends. - Added FIXME that this mechanism should be generalized. llvm-svn: 56962
* Sema::ActOnBlockReturnStmt(): Need to perform the UsualUnaryConversions on ↵Steve Naroff2008-09-161-1/+6
| | | | | | | | | the return type. Sema::CheckReturnStackAddr(): Make sure we skip over implicit casts. Added some more test cases... llvm-svn: 56254
* More semantic analysis for blocks...Steve Naroff2008-09-101-2/+2
| | | | llvm-svn: 56064
* More type checking for blocks. Still incomplete (will hopefully finish up ↵Steve Naroff2008-09-051-4/+11
| | | | | | this weekend). llvm-svn: 55862
* Add __builtin_object_size support.Daniel Dunbar2008-09-031-4/+29
| | | | | | | - Currently CodeGen always returns a conservative value for this (-1 or 0 depending on the context). llvm-svn: 55735
* Add ExplicitCastExpr to replace the current CastExpr, and have ↵Argyrios Kyrtzidis2008-08-181-8/+2
| | | | | | | | | | | ImplicitCastExpr and ExplicitCastExpr derive from a common base class (CastExpr): Expr -> CastExpr -> ExplicitCastExpr -> ImplicitCastExpr llvm-svn: 54955
* More #include cleaningDaniel Dunbar2008-08-111-9/+0
| | | | | | | | | | | - Kill unnecessary #includes in .cpp files. This is an automatic sweep so some things removed are actually used, but happen to be included by a previous header. I tried to get rid of the obvious examples and this was the easiest way to trim the #includes in one fell swoop. - We now return to regularly scheduled development. llvm-svn: 54632
* More #include cleaningDaniel Dunbar2008-08-111-0/+1
| | | | | | | | - Drop {Decl.h,DeclObjC.h,IdentifierTable.h} from Expr.h - Moved Sema::getCurMethodDecl() out of line (dependent on ObjCMethodDecl via dyn_cast). llvm-svn: 54629
* tighten up some code and some wording on diagnostics.Chris Lattner2008-08-101-27/+19
| | | | llvm-svn: 54607
* Fix <rdar://problem/6125909>.Ted Kremenek2008-08-071-18/+14
| | | | | | Unify logic in return-of-stack-check (Sema) for casts and implicit casts. llvm-svn: 54439
* change more instances of QualType::getCanonicalType to callChris Lattner2008-07-261-2/+2
| | | | | | ASTContext::getCanonicalType instead (PR2189) llvm-svn: 54105
* Format string errors should underling the format string, not the function name.Ted Kremenek2008-07-251-12/+15
| | | | llvm-svn: 54067
* Implement nans, prefetch, and trap builtins. Daniel Dunbar2008-07-211-0/+53
| | | | | | | This closes <rdar://problem/6080720>, support for __builtin_constant_p has been filed separately. llvm-svn: 53885
* Extend va_start checking to include __builtin_stdarg_start.Ted Kremenek2008-07-091-0/+1
| | | | llvm-svn: 53332
* Make a few related changes:Chris Lattner2008-06-301-2/+1
| | | | | | | | | | | | | | 1) add a new ASTContext::getFloatTypeSemantics method. 2) Use it from SemaExpr.cpp, CodeGenTypes.cpp and other places. 3) Change the TargetInfo.h get*Format methods to return their fltSemantics byref instead of by pointer. 4) Change CodeGenFunction::EmitBuiltinExpr to allow builtins which sometimes expand specially and othertimes fall back to libm. 5) Add support for __builtin_nan("") to codegen, cases that don't pass in an empty string are currently lowered to libm calls. 6) Fix codegen of __builtin_infl. llvm-svn: 52914
* Replace CurFunctionDecl and CurMethodDecl with methods getCurFunctionDecl() ↵Argyrios Kyrtzidis2008-06-281-6/+6
| | | | | | and getCurMethodDecl() that return the appropriate Decl through CurContext. llvm-svn: 52852
* Introduce preliminary support for NSString format-string checking.Ted Kremenek2008-06-161-2/+34
| | | | | | Patch by Nikita Zhuk! llvm-svn: 52336
* Add __builtin_frame_address and __builtin_return_address gcc builtins to Eli Friedman2008-05-201-1/+16
| | | | | | Sema. No codegen yet. llvm-svn: 51307
* Review nit.Eli Friedman2008-05-161-2/+2
| | | | llvm-svn: 51196
* Clean up ownership per review comment.Eli Friedman2008-05-161-24/+13
| | | | llvm-svn: 51195
* Fixed another regression introduced by r51113 caused by some refactoringTed Kremenek2008-05-151-3/+3
| | | | | | | | | | | | | | in Sema::CheckFunctionCall: http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20080512/005706.html The bug was that the logic from the helper methods used by CheckFunctionCall were being inverted (a subtle bug). This would cause the parser to discard any valid AST nodes involving several builtins (see patch). This removes the last regression failure I'm seeing in the test suite: Analysis-Apple/NoReturn. llvm-svn: 51168
* Implementation of __builtin_shufflevector, a portable builtin capable of Eli Friedman2008-05-141-7/+93
| | | | | | | | | expressing the full flexibility of the LLVM shufflevector instruction. The expected immediate usage is in *mmintrin.h, so that they don't depend on the mess of gcc-inherited (and not completely implemented) shuffle builtins. llvm-svn: 51113
* Make a major restructuring of the clang tree: introduce a top-levelChris Lattner2008-03-151-0/+802
lib dir and move all the libraries into it. This follows the main llvm tree, and allows the libraries to be built in parallel. The top level now enforces that all the libs are built before Driver, but we don't care what order the libs are built in. This speeds up parallel builds, particularly incremental ones. llvm-svn: 48402
OpenPOWER on IntegriCloud