summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaChecking.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Move the check for vprintf* functions inside of SemaCheckStringLiteral. ↵Anders Carlsson2009-06-281-25/+22
| | | | | | Fixes PR4470. llvm-svn: 74413
* Implement support for the format_arg attribute. Fixes PR4442.Anders Carlsson2009-06-271-0/+21
| | | | llvm-svn: 74369
* Move the static DeclAttrs map into ASTContext. Fixes <rdar://problem/6983177>.Douglas Gregor2009-06-181-3/+4
| | | | llvm-svn: 73702
* PR4142: Add %m format string specifier.Eli Friedman2009-06-021-0/+5
| | | | llvm-svn: 72726
* tweak non-null check to put the caret on the function, but underline theChris Lattner2009-05-251-2/+3
| | | | | | | | | | | | | | | | | | argument. This avoids the argument from being silenced when the argument is the NULL macro, which is defined in a system header. This also makes the output a bit nicer, e.g.: t.c:8:3: warning: null passed to a callee which requires a non-null argument func1(NULL, cp2, i1); ^ ~~~~ vs something like: t.c:8:10: warning: argument is null where non-null is required func1(NULL, cp2, i1); ^ llvm-svn: 72393
* Check on null arguments in the presense of nonnull attribute.Fariborz Jahanian2009-05-211-0/+14
| | | | llvm-svn: 72219
* add header to be built by gcc 4.3 on Linux.Zhongxing Xu2009-05-201-0/+1
| | | | llvm-svn: 72158
* Template instantiation for __builtin_shufflevector.Douglas Gregor2009-05-191-33/+69
| | | | llvm-svn: 72139
* more printf attribute on block declaration andFariborz Jahanian2009-05-181-0/+28
| | | | | | checking when block is envoked. In progress. llvm-svn: 72039
* Fix <rdar://problem/6880975> [format string] Assertion failed: (Arg < ↵Ted Kremenek2009-05-131-25/+27
| | | | | | | | | NumArgs && "Arg access out of range!"). For format string checking, only check the type of the format specifier for non-vararg functions. llvm-svn: 71672
* add support for __sync_nand_and_fetch and __sync_fetch_and_nand,Chris Lattner2009-05-131-9/+15
| | | | | | rdar://6880573 llvm-svn: 71636
* Fix the atomics sema code to convert operands to the argument typesChris Lattner2009-05-081-8/+19
| | | | | | | | | of the underlying _N builtin, not the the type of the pointee of the actual type. This ensures that atomics involving pointers end up using the correct integer type when they are resolved, avoiding aborts in codegen. llvm-svn: 71218
* reimplement __sync_* builtins to be variadic and to follow the sameChris Lattner2009-05-081-0/+184
| | | | | | | | | semantic rules that gcc and icc use. This implements the variadic and concrete versions as builtins and has sema do the disambiguation. There are probably a bunch of details to finish up but this seems like a large monotonic step forward :) llvm-svn: 71212
* Fix silly mistake that was breaking tests. Sorry for any inconvenience.Eli Friedman2009-05-031-1/+3
| | | | llvm-svn: 70664
* Add Sema support for __builtin_setjmp/__builtin_longjmp. The primary Eli Friedman2009-05-031-0/+15
| | | | | | | | | | | reason for adding these is to error out in CodeGen when trying to generate them instead of silently emitting a call to a non-existent function. (Note that it is not valid to lower these to setjmp/longjmp; in addition to that lowering being different from the intent, setjmp and longjmp require a larger buffer.) llvm-svn: 70658
* implement -Wformat-security properly, which is enabled by default.Chris Lattner2009-04-291-3/+10
| | | | | | This enables one specific class of non-literal format warnings. llvm-svn: 70368
* code simplification, no functionality change.Chris Lattner2009-04-291-33/+30
| | | | llvm-svn: 70367
* minor code cleanupChris Lattner2009-04-291-2/+2
| | | | llvm-svn: 70361
* Fixup semantic analysis for nested blocks, and allow block literalMike Stump2009-04-171-2/+3
| | | | | | | expressions that can be of static duration to be returned. Radar 6786551 llvm-svn: 69331
* Fix <rdar://problem/6786597> varargs not supported for Blocks under clang.Steve Naroff2009-04-151-2/+6
| | | | | | Teach Sema::SemaBuiltinVAStart() about blocks. llvm-svn: 69201
* Move/update recent FIXME (wrt UTF-8 checking for ObjC @-strings).Steve Naroff2009-04-131-0/+5
| | | | llvm-svn: 68982
* CodeGenModule::GetAddrOfConstantCFString():Steve Naroff2009-04-011-7/+0
| | | | | | | | | | - Finish up support for converting UTF8->UTF16 to support ObjC @"string" constants. Remove warning from CheckObjCString. As the FIXME in the test case indicates, I still have a bug to work out (apparently with \u handling). llvm-svn: 68245
* Fix <rdar://problem/6704086> by allowing the format string checking in Sema toTed Kremenek2009-03-201-21/+56
| | | | | | | | allow non-literal format strings that are variables that (a) permanently bind to a string constant and (b) whose string constants are resolvable within the same translation unit. llvm-svn: 67404
* When checking printf-arguments for functions with '__attribute__ ((format ↵Ted Kremenek2009-02-271-4/+6
| | | | | | | | | | (printf, X, Y)))' set HasVAListArg to true when 'Y' is 0 (i.e., ignore the data arguments). This fixes <rdar://problem/6623513>. llvm-svn: 65642
* Create a new TypeNodes.def file that enumerates all of the types,Douglas Gregor2009-02-261-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | giving them rough classifications (normal types, never-canonical types, always-dependent types, abstract type representations) and making it far easier to make sure that we've hit all of the cases when decoding types. Switched some switch() statements on the type class over to using this mechanism, and filtering out those things we don't care about. For example, CodeGen should never see always-dependent or non-canonical types, while debug info generation should never see always-dependent types. More switch() statements on the type class need to be moved over to using this approach, so that we'll get warnings when we add a new type then fail to account for it somewhere in the compiler. As part of this, some types have been renamed: TypeOfExpr -> TypeOfExprType FunctionTypeProto -> FunctionProtoType FunctionTypeNoProto -> FunctionNoProtoType There shouldn't be any functionality change... llvm-svn: 65591
* Arguments to unordered comparison builtins may need implicit casts.Daniel Dunbar2009-02-191-0/+6
| | | | | | - <rdar://problem/6094103> sema fails to promote type arguments to __builtin_isgreater (and friends) llvm-svn: 65059
* final string diagnostic issue (that I know about):Chris Lattner2009-02-181-16/+3
| | | | | | | | | | | | | | | | | we used to not account for escapes in strings with string concat. Before: t.m:5:20: warning: field width should have type 'int', but argument has type 'unsigned int' printf("\n\n" "\n\n%*d", (unsigned) 1, 1); ^ ~~~~~~~~~~~~ after: t.m:5:23: warning: field width should have type 'int', but argument has type 'unsigned int' printf("\n\n" "\n\n%*d", (unsigned) 1, 1); ^ ~~~~~~~~~~~~ llvm-svn: 64941
* Next step toward making string diagnostics correct: handleChris Lattner2009-02-181-5/+8
| | | | | | | | | | | | | escapes in the string for subtoken positioning. This gives us working examples like: t.m:5:16: warning: field width should have type 'int', but argument has type 'unsigned int' printf("\n\n%*d", (unsigned) 1, 1); ^ ~~~~~~~~~~~~ where before the caret pointed two spaces to the left. llvm-svn: 64940
* Fix some issues handling sub-token locations that come from macro expansions.Chris Lattner2009-02-181-8/+3
| | | | | | | | | | | | | | | We now emit: t.m:6:15: warning: field width should have type 'int', but argument has type 'unsigned int' printf(STR, (unsigned) 1, 1); ^ ~~~~~~~~~~~~ t.m:3:18: note: instantiated from: #define STR "abc%*ddef" ^ which has the correct location in the string literal in the note line. llvm-svn: 64936
* only get the spelling of a token to get its length if Chris Lattner2009-02-181-5/+12
| | | | | | it needs cleaning. llvm-svn: 64932
* use the full spelling of a string literal token so that trigraphsChris Lattner2009-02-181-1/+8
| | | | | | | | | | | | | | | | | | | | | and escaped newlines don't throw off the offset computation. On this testcase: printf("abc\ def" "%*d", (unsigned) 1, 1); Before: t.m:5:5: warning: field width should have type 'int', but argument has type 'unsigned int' def" ^ after: t.m:6:12: warning: field width should have type 'int', but argument has type 'unsigned int' "%*d", (unsigned) 1, 1); ^ ~~~~~~~~~~~~ llvm-svn: 64930
* Start improving diagnostics that relate to subcharacters of string literals.Chris Lattner2009-02-181-17/+80
| | | | | | | | | | | | | | | | | | | | First step, handle diagnostics in StringLiteral's that are due to token pasting. For example, we now handle: id str2 = @"foo" "bar" @"baz" " b\0larg"; // expected-warning {{literal contains NUL character}} Correctly: test/SemaObjC/exprs.m:17:15: warning: CFString literal contains NUL character " b\0larg"; // expected-warning {{literal contains NUL character}} ~~~^~~~~~~ There are several other related issues still to be done. llvm-svn: 64924
* rename CheckBuiltinCFStringArgument -> CheckObjCStringChris Lattner2009-02-181-4/+3
| | | | llvm-svn: 64894
* Add hook to add attributes to function declarations that we knowDouglas Gregor2009-02-141-33/+26
| | | | | | | | | | | | | | | | 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-4/+2
| | | | | | | | 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-31/+21
| | | | | | | | | | | | | | | | | | | | | 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-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
OpenPOWER on IntegriCloud