summaryrefslogtreecommitdiffstats
path: root/clang/Sema/SemaExpr.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Implement parsing and code generation of Objective-C string literals.Anders Carlsson2007-08-211-0/+14
| | | | llvm-svn: 41238
* Return true in case of error, which is what other functions do.Anders Carlsson2007-08-171-1/+1
| | | | llvm-svn: 41140
* Add initial support for constant CFStrings.Anders Carlsson2007-08-171-1/+2
| | | | llvm-svn: 41136
* Fixed Sema::CheckEqualityOperands() and Sema::CheckRelationalOperands() to ↵Steve Naroff2007-08-161-28/+52
| | | | | | | | | | | | | deal more thoughtfully with incompatible pointers. This includes: - Emit a diagnostic when two pointers aren't compatible! - Promote one of the pointers/integers so we maintain the invariant expected by the code generator (i.e. that the left/right types match). - Upgrade the pointer/integer comparison diagnostic to include the types. llvm-svn: 41127
* Added support for additional format string checking for the printfTed Kremenek2007-08-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | family of functions. Previous functionality only included checking to see if the format string was a string literal. Now we check parse the format string (if it is a literal) and perform the following checks: (1) Warn if: number conversions (e.g. "%d") != number data arguments. (2) Warn about missing format strings (e.g., "printf()"). (3) Warn if the format string is not a string literal. (4) Warn about the use se of '%n' conversion. This conversion is discouraged for security reasons. (5) Warn about malformed conversions. For example '%;', '%v'; these are not valid. (6) Warn about empty format strings; e.g. printf(""). Although these can be optimized away by the compiler, they can be indicative of broken programmer logic. We may need to add additional support to see when such cases occur within macro expansion to avoid false positives. (7) Warn if the string literal is wide; e.g. L"%d". (8) Warn if we detect a '\0' character WITHIN the format string. Test cases are included. llvm-svn: 41076
* initial support for checking format strings, patch by Ted Kremenek:Chris Lattner2007-08-101-0/+8
| | | | | | "I've coded up some support in clang to flag warnings for non-constant format strings used in calls to printf-like functions (all the functions listed in "man fprintf"). Non-constant format strings are a source of many security exploits in C/C++ programs, and I believe are currently detected by gcc using the flag -Wformat-nonliteral." llvm-svn: 41003
* Make sure the arithmetic conversion are done for relation and equality ↵Steve Naroff2007-08-101-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | operators. This fixes the following... eypedef short S; int test(S X, long long Y) { return X < Y; } Before... (CompoundStmt 0x2905d00 (ReturnStmt 0x2905cf0 (BinaryOperator 0x2905cd0 'int' '<' (ImplicitCastExpr 0x2905cc0 'int' (DeclRefExpr 0x2905c80 'S':'short' Decl='X' 0x2905c20)) (DeclRefExpr 0x2905ca0 'long long' Decl='Y' 0x2905c50)))) After... (CompoundStmt 0x2b05c30 (ReturnStmt 0x2b05c20 (BinaryOperator 0x2b05c00 'int' '<' (ImplicitCastExpr 0x2b05bf0 'long long' (DeclRefExpr 0x2b05bb0 'S':'short' Decl='X' 0x2b05b50)) (DeclRefExpr 0x2b05bd0 'long long' Decl='Y' 0x2b05b80)))) llvm-svn: 40999
* Move the function/array conversion for ParmVarDecl's from ↵Steve Naroff2007-08-071-26/+0
| | | | | | | | | | Sema::ParseIdentifierExpr() to Sema::ParseParamDeclarator(). After discussing this with Chris, we decided this approach has more immediate benefit (though we loose some information in the AST). The comment below should describe more (if interested). llvm-svn: 40907
* Remove a space from "typeof" printing. It was causing the following error...Steve Naroff2007-08-051-1/+1
| | | | | | | | | | | | [dylan:clang/test/Parser] admin% ../../../../Debug/bin/clang -parse-ast-check typeof.c Warnings expected but not seen: Line 21: incompatible types assigning 'typeof(*pi) const' to 'int *' Warnings seen but not expected: Line 21: incompatible types assigning 'typeof(*pi) const' to 'int *' Also corrected a typo from my previous commit. llvm-svn: 40832
* Make sure the good old "function/array conversion" is done to function ↵Steve Naroff2007-08-051-1/+26
| | | | | | | | | | | | | | | | | | | parameters. This resulted in the following error... [dylan:clang/test/Parser] admin% cat parmvardecl_conversion.c // RUN: clang -parse-ast-check %s void f (int p[]) { p++; } [dylan:clang/test/Parser] admin% clang -parse-ast-check parmvardecl_conversion.c Errors seen but not expected: Line 3: cannot modify value of type 'int []' With this fix, the test case above succeeds. llvm-svn: 40831
* Restrict vector component access (using "." and "[]") to variables.Steve Naroff2007-08-031-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | Chris suggested this, since it simplifies the code generator. If this features is needed (and we don't think it is), we can revisit. The following test case now produces an error. [dylan:~/llvm/tools/clang] admin% cat t.c typedef __attribute__(( ocu_vector_type(4) )) float float4; static void test() { float4 vec4; vec4.rg.g; vec4.rg[1]; } [dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang t.c t.c:8:12: error: vector component access limited to variables vec4.rg.g; ^~ t.c:9:12: error: vector component access limited to variables vec4.rg[1]; ^~~ 2 diagnostics generated. llvm-svn: 40795
* Implement __builtin_choose_expr.Steve Naroff2007-08-031-0/+22
| | | | llvm-svn: 40794
* Rename AddrLabel and OCUVectorComponent -> AddrLabelExpr and ↵Chris Lattner2007-08-031-3/+3
| | | | | | OCUVectorElementExpr respectively. This is for consistency with other expr nodes end with *Expr. llvm-svn: 40785
* rename some helpers, have them return the idx of the field being accessed.Chris Lattner2007-08-021-6/+13
| | | | llvm-svn: 40764
* - Finish hooking up support for __builtin_types_compatible_p().Steve Naroff2007-08-011-2/+2
| | | | | | - Fix type printing code for recently added TypeOfExpr/TypeOfType. llvm-svn: 40700
* Add AST/Sema support for __builtin_types_compatible_p (a GNU extension).Steve Naroff2007-08-011-0/+12
| | | | | | Todo...still need to call the action from the parser... llvm-svn: 40693
* simplify some type checking code, don't explicitly accessChris Lattner2007-07-311-43/+37
| | | | | | canonical types. llvm-svn: 40652
* split the rest of the type predicates into pure predicates:Chris Lattner2007-07-311-6/+6
| | | | | | there is now an isXXXType and a getAsXXXType llvm-svn: 40646
* rename isReferenceType to follow the new scheme.Chris Lattner2007-07-311-2/+2
| | | | llvm-svn: 40640
* make isPointerType() a pure predicate, rename theChris Lattner2007-07-311-4/+4
| | | | | | existing one to getAsPointerType() llvm-svn: 40639
* Add parsing and AST support for GNU "typeof".Steve Naroff2007-07-311-1/+1
| | | | | | | Many small changes to lot's of files. Still some FIXME's, however the basic support is in place. llvm-svn: 40631
* Don't use canonical type for sema here. InChris Lattner2007-07-301-1/+1
| | | | | | | | | | | | | | | void func() { typedef int foo; foo *Y; **Y; // error } we now get: indirection requires pointer operand ('foo' invalid) instead of: indirection requires pointer operand ('int' invalid) llvm-svn: 40597
* Finish up semantic analysis for vector components.Steve Naroff2007-07-301-0/+4
| | | | llvm-svn: 40584
* Implement pretty diagnostics when doing on-the-fly vector sizing (for vector ↵Steve Naroff2007-07-291-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | component access). For example, before this commit, the following diagnostics would be emitted... ocu.c:49:12: error: incompatible types assigning 'float __attribute__((ocu_vector_type(3)))' to 'float4' vec4_2 = vec4.rgb; // shorten ~~~~~~ ^ ~~~~~~~~ ocu.c:51:7: error: incompatible types assigning 'float __attribute__((ocu_vector_type(2)))' to 'float' f = vec2.xx; // shorten ~ ^ ~~~~~~~ Now, the diagnostics look as you would expect... ocu.c:49:12: error: incompatible types assigning 'float3' to 'float4' vec4_2 = vec4.rgb; // shorten ~~~~~~ ^ ~~~~~~~~ ocu.c:51:7: error: incompatible types assigning 'float2' to 'float' f = vec2.xx; // shorten ~ ^ ~~~~~~~ llvm-svn: 40579
* Added a new expression, OCUVectorComponent.Steve Naroff2007-07-281-2/+1
| | | | llvm-svn: 40577
* Implement syntax/semantic analysis for OCU Vector Components.Steve Naroff2007-07-271-5/+61
| | | | | | Next step, AST support... llvm-svn: 40568
* Fix the following bogus diagnostic...reported by Jeroen.Steve Naroff2007-07-261-4/+5
| | | | | | | | | | | | | | | | | | | | | | #include <stdio.h> int main(void) { int test = 0; printf("Type is %s\n", (test >= 1 ? "short" : "char")); return (0); } It comes up with a diagnostic that's misleading upon first read. t.c:7:36: error: incompatible operand types ('char *' and 'char *') printf("Type is %s\n", (test >= 1 ? "short" : "char")); ^ ~~~~~~~ ~~~~~~ 1 diagnostic generated. llvm-svn: 40526
* Various improvements to Sema::ParseMemberReferenceExpr().Steve Naroff2007-07-261-23/+24
| | | | | | | | | | | - Added source range support to Diag's. - Used the new type predicate API to remove dealing with the canonical type explicitly. - Added Type::isRecordType(). - Removed some casts. - Removed a const qualifier from RecordType::getDecl(). llvm-svn: 40508
* - Fix commit in Parser.h (patch by Kevin Andre).Steve Naroff2007-07-251-4/+2
| | | | | | - Add comment and minor cleanup to yesterday's fix to ParseCallExpr(). llvm-svn: 40492
* Fix Sema::ParseCallExpr()...it wasn't doing the default array/function ↵Steve Naroff2007-07-241-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | promotions on it's argument types. This resulted in the following errors when compiling promote_types_in_proto.c test... [dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang test/Parser/promote_types_in_proto.c test/Parser/promote_types_in_proto.c:7:24: error: incompatible types passing 'char *[]' to function expecting 'char *const []' arrayPromotion(argv); ~~~~~~~~~~~~~~ ^~~~ test/Parser/promote_types_in_proto.c:8:27: error: incompatible types passing 'void (char *const [])' to function expecting 'void (char *const [])' functionPromotion(arrayPromotion); ~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~ 2 diagnostics generated. When fixing this, noticed that both ParseCallExpr() and ParseReturnStmt() were prematurely comparing types for equivalence. This is incorrect (since the expr. promotions haven't been done yet). To fix this, I moved the check "down" to Sema::CheckAssignmentConstraints(). I also converted Type::isArrayType() to the modern API (since I needed it). Still more Type predicates to convert. llvm-svn: 40475
* implement ast building and trivial semantic analysis of stmt exprs.Chris Lattner2007-07-241-0/+23
| | | | | | This implements test/Sema/stmt_exprs.c llvm-svn: 40465
* Implement code generation for __func__, __FUNCTION__ and __PRETTY_FUNCTION__Anders Carlsson2007-07-211-4/+13
| | | | llvm-svn: 40162
* fix a warning on some compilersChris Lattner2007-07-211-0/+1
| | | | llvm-svn: 40139
* Fix off-by-one error when emitting diagnostics. Also, make diagnosticChris Lattner2007-07-211-2/+3
| | | | | | | | | | | | | | a bit nicer for people who pass lots of extra arguments to calls by selecting them all instead of just the first one: arg-duplicate.c:13:13: error: too many arguments to function f3 (1, 1, 2, 3, 4); // expected-error {{too many arguments to function}} ^~~~~~~ This implements test/Sema/arg-duplicate.c, thanks to Neil for pointing out this crash. llvm-svn: 40136
* move some casts up to the entry of the function for clarity.Chris Lattner2007-07-211-23/+23
| | | | llvm-svn: 40135
* At one point there were going to be lexer and parser tokens.Chris Lattner2007-07-201-3/+3
| | | | | | | Since that point is now long gone, we should rename LexerToken to Token, as it is the only kind of token we have. llvm-svn: 40105
* Finish fixing crasher with compound literals.Steve Naroff2007-07-191-4/+5
| | | | | | | We still need to do sematic analysis (and implement initializers), however this should complete the parsing & ast building for compound literals. llvm-svn: 40067
* Work towards fixing crasher with compound literals...Steve Naroff2007-07-191-0/+22
| | | | | | | | | | | | | | | | Before this commit, we crashed in ParseBinOp... [dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang -parse-ast-check compound_literal.c SemaExpr.cpp:1298: failed assertion `(rhs != 0) && "ParseBinOp(): missing right expression"' With this commit, we still crash in the newly added action ParseCompoundLiteral (which is progress:-) [dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang -parse-ast-check compound_literal.c SemaExpr.cpp:478: failed assertion `(Op != 0) && "ParseCompoundLiteral(): missing expression"' The crash go away once the actions return AST nodes. I will do this in a separate commit. llvm-svn: 40032
* Cast to void is valid, patch by Benoit BoissinotChris Lattner2007-07-181-2/+3
| | | | llvm-svn: 40003
* Use the correct method for getting the ReferenceType from a QualType.Bill Wendling2007-07-171-2/+2
| | | | llvm-svn: 39960
* Change dyn_cast for reference types to be more like pointers and not need ↵Bill Wendling2007-07-171-4/+8
| | | | | | the canonical type. Also fix so that we're not expecting a return value from a void function llvm-svn: 39954
* Fix references:Bill Wendling2007-07-171-1/+5
| | | | | | | | According to the spec (C++ 5p6[expr]), we need to adjust "T&" to "T" before further analysis. We do this via the "implicit cast" thingy. llvm-svn: 39953
* Convert UsualArithmeticConversions to return "void". Now that we synthesize ↵Steve Naroff2007-07-171-57/+71
| | | | | | | | | | ImplicitCastExpr's, there is no compelling need to return the converted type. If both expression type's are arithmetic, then both types will always be the same. If they aren't (for pointer/int types, say), then the types will be different. The client is responsible for distinguishing... llvm-svn: 39947
* Implement semantic analysis for the cast operator.Steve Naroff2007-07-161-4/+16
| | | | llvm-svn: 39943
* Remove the 2 QualType references to method UsualArithmeticConversions. Last ↵Steve Naroff2007-07-161-27/+19
| | | | | | | | | | week, I added these to quickly fix a regression. Avoiding them entirely is a much cleaner solution. Clients of UsualArithmeticConversions should simply call getType() on the expression to get the converted type. In practice, only a small number of routines care about this. llvm-svn: 39934
* Change DefaultFunctionArrayConversions and UsualUnaryConversions to return ↵Steve Naroff2007-07-161-34/+49
| | | | | | | | | void. The caller needs to query the expression for the type. Since both these functions guarantee the expression contains a valid type, removed old/vacuous asserts (from code calling both of these routines). llvm-svn: 39930
* Fix a GCC warning:Chris Lattner2007-07-161-3/+5
| | | | | | | | SemaExpr.cpp:561: warning: dereferencing type-punned pointer will break strict-aliasing rules Patch by Benoit Boissinot! llvm-svn: 39928
* Now that isPointerType can return a pointer type, avoid stripping off typedefChris Lattner2007-07-161-3/+4
| | | | | | | | | | | | | | | | | | | information in the common case. On this invalid code: typedef float float4 __attribute__((vector_size(16))); typedef int int4 __attribute__((vector_size(16))); void test(float4 a, int4 *result, int i) { result[i] = a; } we now generate: t.c:5:15: error: incompatible types assigning 'float4' to 'int4' instead of: t.c:5:15: error: incompatible types assigning 'float4' to 'int __attribute__((vector_size(16)))' This implements test/Sema/typedef-retain.c llvm-svn: 39892
* Use the return value of isPointerType and isVectorType to significantly simplifyChris Lattner2007-07-161-36/+35
| | | | | | | ParseArraySubscriptExpr. Notably, the new code doesn't have to think about canonical types at all. llvm-svn: 39891
* rename variables to be more consistent. Always use LHS/RHS intead of T1/T2 ↵Chris Lattner2007-07-151-15/+12
| | | | | | sometimes. llvm-svn: 39889
OpenPOWER on IntegriCloud