Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 1 | //===--- SemaChecking.cpp - Extra Semantic Checking -----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements extra semantic analysis beyond what is enforced |
| 11 | // by the C type system. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "Sema.h" |
| 16 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | c4a1dea | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclObjC.h" |
Ted Kremenek | 2324512 | 2007-08-20 16:18:38 +0000 | [diff] [blame] | 18 | #include "clang/AST/ExprCXX.h" |
Ted Kremenek | 7ff22b2 | 2008-06-16 18:00:42 +0000 | [diff] [blame] | 19 | #include "clang/AST/ExprObjC.h" |
Chris Lattner | 719e615 | 2009-02-18 19:21:10 +0000 | [diff] [blame] | 20 | #include "clang/Lex/LiteralSupport.h" |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 21 | #include "clang/Lex/Preprocessor.h" |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 22 | using namespace clang; |
| 23 | |
Chris Lattner | 6080008 | 2009-02-18 17:49:48 +0000 | [diff] [blame] | 24 | /// getLocationOfStringLiteralByte - Return a source location that points to the |
| 25 | /// specified byte of the specified string literal. |
| 26 | /// |
| 27 | /// Strings are amazingly complex. They can be formed from multiple tokens and |
| 28 | /// can have escape sequences in them in addition to the usual trigraph and |
| 29 | /// escaped newline business. This routine handles this complexity. |
| 30 | /// |
| 31 | SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL, |
| 32 | unsigned ByteNo) const { |
| 33 | assert(!SL->isWide() && "This doesn't work for wide strings yet"); |
| 34 | |
| 35 | // Loop over all of the tokens in this string until we find the one that |
| 36 | // contains the byte we're looking for. |
| 37 | unsigned TokNo = 0; |
| 38 | while (1) { |
| 39 | assert(TokNo < SL->getNumConcatenated() && "Invalid byte number!"); |
| 40 | SourceLocation StrTokLoc = SL->getStrTokenLoc(TokNo); |
| 41 | |
| 42 | // Get the spelling of the string so that we can get the data that makes up |
| 43 | // the string literal, not the identifier for the macro it is potentially |
| 44 | // expanded through. |
| 45 | SourceLocation StrTokSpellingLoc = SourceMgr.getSpellingLoc(StrTokLoc); |
| 46 | |
| 47 | // Re-lex the token to get its length and original spelling. |
| 48 | std::pair<FileID, unsigned> LocInfo = |
| 49 | SourceMgr.getDecomposedLoc(StrTokSpellingLoc); |
| 50 | std::pair<const char *,const char *> Buffer = |
| 51 | SourceMgr.getBufferData(LocInfo.first); |
| 52 | const char *StrData = Buffer.first+LocInfo.second; |
| 53 | |
| 54 | // Create a langops struct and enable trigraphs. This is sufficient for |
| 55 | // relexing tokens. |
| 56 | LangOptions LangOpts; |
| 57 | LangOpts.Trigraphs = true; |
| 58 | |
| 59 | // Create a lexer starting at the beginning of this token. |
| 60 | Lexer TheLexer(StrTokSpellingLoc, LangOpts, Buffer.first, StrData, |
| 61 | Buffer.second); |
| 62 | Token TheTok; |
| 63 | TheLexer.LexFromRawLexer(TheTok); |
| 64 | |
Chris Lattner | 443e53c | 2009-02-18 19:26:42 +0000 | [diff] [blame] | 65 | // Use the StringLiteralParser to compute the length of the string in bytes. |
| 66 | StringLiteralParser SLP(&TheTok, 1, PP); |
| 67 | unsigned TokNumBytes = SLP.GetStringLength(); |
Chris Lattner | d0d082f | 2009-02-18 18:34:12 +0000 | [diff] [blame] | 68 | |
Chris Lattner | 2197c96 | 2009-02-18 18:52:52 +0000 | [diff] [blame] | 69 | // If the byte is in this token, return the location of the byte. |
Chris Lattner | 6080008 | 2009-02-18 17:49:48 +0000 | [diff] [blame] | 70 | if (ByteNo < TokNumBytes || |
| 71 | (ByteNo == TokNumBytes && TokNo == SL->getNumConcatenated())) { |
Chris Lattner | 719e615 | 2009-02-18 19:21:10 +0000 | [diff] [blame] | 72 | unsigned Offset = |
| 73 | StringLiteralParser::getOffsetOfStringByte(TheTok, ByteNo, PP); |
| 74 | |
| 75 | // Now that we know the offset of the token in the spelling, use the |
| 76 | // preprocessor to get the offset in the original source. |
| 77 | return PP.AdvanceToTokenCharacter(StrTokLoc, Offset); |
Chris Lattner | 6080008 | 2009-02-18 17:49:48 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | // Move to the next string token. |
| 81 | ++TokNo; |
| 82 | ByteNo -= TokNumBytes; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 87 | /// CheckFunctionCall - Check a direct function call for various correctness |
| 88 | /// and safety properties not strictly enforced by the C type system. |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 89 | Action::OwningExprResult |
| 90 | Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) { |
| 91 | OwningExprResult TheCallResult(Owned(TheCall)); |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 92 | // Get the IdentifierInfo* for the called function. |
| 93 | IdentifierInfo *FnInfo = FDecl->getIdentifier(); |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 94 | |
| 95 | // None of the checks below are needed for functions that don't have |
| 96 | // simple names (e.g., C++ conversion functions). |
| 97 | if (!FnInfo) |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 98 | return move(TheCallResult); |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 99 | |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 100 | switch (FDecl->getBuiltinID(Context)) { |
Chris Lattner | 30ce344 | 2007-12-19 23:59:04 +0000 | [diff] [blame] | 101 | case Builtin::BI__builtin___CFStringMakeConstantString: |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 102 | assert(TheCall->getNumArgs() == 1 && |
Chris Lattner | 1b9a079 | 2007-12-20 00:26:33 +0000 | [diff] [blame] | 103 | "Wrong # arguments to builtin CFStringMakeConstantString"); |
Chris Lattner | 6903981 | 2009-02-18 06:01:06 +0000 | [diff] [blame] | 104 | if (CheckObjCString(TheCall->getArg(0))) |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 105 | return ExprError(); |
| 106 | return move(TheCallResult); |
Ted Kremenek | 49ff7a1 | 2008-07-09 17:58:53 +0000 | [diff] [blame] | 107 | case Builtin::BI__builtin_stdarg_start: |
Chris Lattner | 30ce344 | 2007-12-19 23:59:04 +0000 | [diff] [blame] | 108 | case Builtin::BI__builtin_va_start: |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 109 | if (SemaBuiltinVAStart(TheCall)) |
| 110 | return ExprError(); |
| 111 | return move(TheCallResult); |
Chris Lattner | 1b9a079 | 2007-12-20 00:26:33 +0000 | [diff] [blame] | 112 | case Builtin::BI__builtin_isgreater: |
| 113 | case Builtin::BI__builtin_isgreaterequal: |
| 114 | case Builtin::BI__builtin_isless: |
| 115 | case Builtin::BI__builtin_islessequal: |
| 116 | case Builtin::BI__builtin_islessgreater: |
| 117 | case Builtin::BI__builtin_isunordered: |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 118 | if (SemaBuiltinUnorderedCompare(TheCall)) |
| 119 | return ExprError(); |
| 120 | return move(TheCallResult); |
Eli Friedman | 6cfda23 | 2008-05-20 08:23:37 +0000 | [diff] [blame] | 121 | case Builtin::BI__builtin_return_address: |
| 122 | case Builtin::BI__builtin_frame_address: |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 123 | if (SemaBuiltinStackAddress(TheCall)) |
| 124 | return ExprError(); |
| 125 | return move(TheCallResult); |
Eli Friedman | d38617c | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 126 | case Builtin::BI__builtin_shufflevector: |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 127 | return SemaBuiltinShuffleVector(TheCall); |
| 128 | // TheCall will be freed by the smart pointer here, but that's fine, since |
| 129 | // SemaBuiltinShuffleVector guts it, but then doesn't release it. |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 130 | case Builtin::BI__builtin_prefetch: |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 131 | if (SemaBuiltinPrefetch(TheCall)) |
| 132 | return ExprError(); |
| 133 | return move(TheCallResult); |
Daniel Dunbar | d5f8a4f | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 134 | case Builtin::BI__builtin_object_size: |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 135 | if (SemaBuiltinObjectSize(TheCall)) |
| 136 | return ExprError(); |
Eli Friedman | 586d6a8 | 2009-05-03 06:04:26 +0000 | [diff] [blame^] | 137 | return move(TheCallResult); |
Eli Friedman | d875fed | 2009-05-03 04:46:36 +0000 | [diff] [blame] | 138 | case Builtin::BI__builtin_longjmp: |
| 139 | if (SemaBuiltinLongjmp(TheCall)) |
| 140 | return ExprError(); |
Eli Friedman | 586d6a8 | 2009-05-03 06:04:26 +0000 | [diff] [blame^] | 141 | return move(TheCallResult); |
Anders Carlsson | 71993dd | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 142 | } |
Daniel Dunbar | de45428 | 2008-10-02 18:44:07 +0000 | [diff] [blame] | 143 | |
| 144 | // FIXME: This mechanism should be abstracted to be less fragile and |
| 145 | // more efficient. For example, just map function ids to custom |
| 146 | // handlers. |
| 147 | |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 148 | // Printf checking. |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 149 | if (const FormatAttr *Format = FDecl->getAttr<FormatAttr>()) { |
| 150 | if (Format->getType() == "printf") { |
Ted Kremenek | 3d692df | 2009-02-27 17:58:43 +0000 | [diff] [blame] | 151 | bool HasVAListArg = Format->getFirstArg() == 0; |
| 152 | if (!HasVAListArg) { |
| 153 | if (const FunctionProtoType *Proto |
| 154 | = FDecl->getType()->getAsFunctionProtoType()) |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 155 | HasVAListArg = !Proto->isVariadic(); |
Ted Kremenek | 3d692df | 2009-02-27 17:58:43 +0000 | [diff] [blame] | 156 | } |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 157 | CheckPrintfArguments(TheCall, HasVAListArg, Format->getFormatIdx() - 1, |
Ted Kremenek | 3d692df | 2009-02-27 17:58:43 +0000 | [diff] [blame] | 158 | HasVAListArg ? 0 : Format->getFirstArg() - 1); |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 159 | } |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 160 | } |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 161 | |
| 162 | return move(TheCallResult); |
Anders Carlsson | 71993dd | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Chris Lattner | 6903981 | 2009-02-18 06:01:06 +0000 | [diff] [blame] | 165 | /// CheckObjCString - Checks that the argument to the builtin |
Anders Carlsson | 71993dd | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 166 | /// CFString constructor is correct |
Steve Naroff | fd94262 | 2009-04-13 20:26:29 +0000 | [diff] [blame] | 167 | /// FIXME: GCC currently emits the following warning: |
| 168 | /// "warning: input conversion stopped due to an input byte that does not |
| 169 | /// belong to the input codeset UTF-8" |
| 170 | /// Note: It might also make sense to do the UTF-16 conversion here (would |
| 171 | /// simplify the backend). |
Chris Lattner | 6903981 | 2009-02-18 06:01:06 +0000 | [diff] [blame] | 172 | bool Sema::CheckObjCString(Expr *Arg) { |
Chris Lattner | 56f3494 | 2008-02-13 01:02:39 +0000 | [diff] [blame] | 173 | Arg = Arg->IgnoreParenCasts(); |
Anders Carlsson | 71993dd | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 174 | StringLiteral *Literal = dyn_cast<StringLiteral>(Arg); |
| 175 | |
| 176 | if (!Literal || Literal->isWide()) { |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 177 | Diag(Arg->getLocStart(), diag::err_cfstring_literal_not_string_constant) |
| 178 | << Arg->getSourceRange(); |
Anders Carlsson | 9cdc4d3 | 2007-08-17 15:44:17 +0000 | [diff] [blame] | 179 | return true; |
Anders Carlsson | 71993dd | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | const char *Data = Literal->getStrData(); |
| 183 | unsigned Length = Literal->getByteLength(); |
| 184 | |
| 185 | for (unsigned i = 0; i < Length; ++i) { |
Anders Carlsson | 71993dd | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 186 | if (!Data[i]) { |
Chris Lattner | 6080008 | 2009-02-18 17:49:48 +0000 | [diff] [blame] | 187 | Diag(getLocationOfStringLiteralByte(Literal, i), |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 188 | diag::warn_cfstring_literal_contains_nul_character) |
| 189 | << Arg->getSourceRange(); |
Anders Carlsson | 71993dd | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 190 | break; |
| 191 | } |
| 192 | } |
| 193 | |
Anders Carlsson | 9cdc4d3 | 2007-08-17 15:44:17 +0000 | [diff] [blame] | 194 | return false; |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Chris Lattner | c27c665 | 2007-12-20 00:05:45 +0000 | [diff] [blame] | 197 | /// SemaBuiltinVAStart - Check the arguments to __builtin_va_start for validity. |
| 198 | /// Emit an error and return true on failure, return false on success. |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 199 | bool Sema::SemaBuiltinVAStart(CallExpr *TheCall) { |
| 200 | Expr *Fn = TheCall->getCallee(); |
| 201 | if (TheCall->getNumArgs() > 2) { |
Chris Lattner | 2c21a07 | 2008-11-21 18:44:24 +0000 | [diff] [blame] | 202 | Diag(TheCall->getArg(2)->getLocStart(), |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 203 | diag::err_typecheck_call_too_many_args) |
Chris Lattner | 2c21a07 | 2008-11-21 18:44:24 +0000 | [diff] [blame] | 204 | << 0 /*function call*/ << Fn->getSourceRange() |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 205 | << SourceRange(TheCall->getArg(2)->getLocStart(), |
| 206 | (*(TheCall->arg_end()-1))->getLocEnd()); |
Chris Lattner | 30ce344 | 2007-12-19 23:59:04 +0000 | [diff] [blame] | 207 | return true; |
| 208 | } |
Eli Friedman | 56f20ae | 2008-12-15 22:05:35 +0000 | [diff] [blame] | 209 | |
| 210 | if (TheCall->getNumArgs() < 2) { |
| 211 | return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_few_args) |
| 212 | << 0 /*function call*/; |
| 213 | } |
| 214 | |
Chris Lattner | c27c665 | 2007-12-20 00:05:45 +0000 | [diff] [blame] | 215 | // Determine whether the current function is variadic or not. |
| 216 | bool isVariadic; |
Steve Naroff | cd9c514 | 2009-04-15 19:33:47 +0000 | [diff] [blame] | 217 | if (CurBlock) |
| 218 | isVariadic = CurBlock->isVariadic; |
| 219 | else if (getCurFunctionDecl()) { |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 220 | if (FunctionProtoType* FTP = |
| 221 | dyn_cast<FunctionProtoType>(getCurFunctionDecl()->getType())) |
Eli Friedman | 56f20ae | 2008-12-15 22:05:35 +0000 | [diff] [blame] | 222 | isVariadic = FTP->isVariadic(); |
| 223 | else |
| 224 | isVariadic = false; |
| 225 | } else { |
Argyrios Kyrtzidis | 53d0ea5 | 2008-06-28 06:07:14 +0000 | [diff] [blame] | 226 | isVariadic = getCurMethodDecl()->isVariadic(); |
Eli Friedman | 56f20ae | 2008-12-15 22:05:35 +0000 | [diff] [blame] | 227 | } |
Chris Lattner | 30ce344 | 2007-12-19 23:59:04 +0000 | [diff] [blame] | 228 | |
Chris Lattner | c27c665 | 2007-12-20 00:05:45 +0000 | [diff] [blame] | 229 | if (!isVariadic) { |
Chris Lattner | 30ce344 | 2007-12-19 23:59:04 +0000 | [diff] [blame] | 230 | Diag(Fn->getLocStart(), diag::err_va_start_used_in_non_variadic_function); |
| 231 | return true; |
| 232 | } |
| 233 | |
| 234 | // Verify that the second argument to the builtin is the last argument of the |
| 235 | // current function or method. |
| 236 | bool SecondArgIsLastNamedArgument = false; |
Anders Carlsson | e2c1410 | 2008-02-13 01:22:59 +0000 | [diff] [blame] | 237 | const Expr *Arg = TheCall->getArg(1)->IgnoreParenCasts(); |
Anders Carlsson | 88cf226 | 2008-02-11 04:20:54 +0000 | [diff] [blame] | 238 | |
| 239 | if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(Arg)) { |
| 240 | if (const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(DR->getDecl())) { |
Chris Lattner | 30ce344 | 2007-12-19 23:59:04 +0000 | [diff] [blame] | 241 | // FIXME: This isn't correct for methods (results in bogus warning). |
| 242 | // Get the last formal in the current function. |
Anders Carlsson | 88cf226 | 2008-02-11 04:20:54 +0000 | [diff] [blame] | 243 | const ParmVarDecl *LastArg; |
Steve Naroff | cd9c514 | 2009-04-15 19:33:47 +0000 | [diff] [blame] | 244 | if (CurBlock) |
| 245 | LastArg = *(CurBlock->TheDecl->param_end()-1); |
| 246 | else if (FunctionDecl *FD = getCurFunctionDecl()) |
Chris Lattner | 371f258 | 2008-12-04 23:50:19 +0000 | [diff] [blame] | 247 | LastArg = *(FD->param_end()-1); |
Chris Lattner | 30ce344 | 2007-12-19 23:59:04 +0000 | [diff] [blame] | 248 | else |
Argyrios Kyrtzidis | 53d0ea5 | 2008-06-28 06:07:14 +0000 | [diff] [blame] | 249 | LastArg = *(getCurMethodDecl()->param_end()-1); |
Chris Lattner | 30ce344 | 2007-12-19 23:59:04 +0000 | [diff] [blame] | 250 | SecondArgIsLastNamedArgument = PV == LastArg; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | if (!SecondArgIsLastNamedArgument) |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 255 | Diag(TheCall->getArg(1)->getLocStart(), |
Chris Lattner | 30ce344 | 2007-12-19 23:59:04 +0000 | [diff] [blame] | 256 | diag::warn_second_parameter_of_va_start_not_last_named_argument); |
| 257 | return false; |
Eli Friedman | 6cfda23 | 2008-05-20 08:23:37 +0000 | [diff] [blame] | 258 | } |
Chris Lattner | 30ce344 | 2007-12-19 23:59:04 +0000 | [diff] [blame] | 259 | |
Chris Lattner | 1b9a079 | 2007-12-20 00:26:33 +0000 | [diff] [blame] | 260 | /// SemaBuiltinUnorderedCompare - Handle functions like __builtin_isgreater and |
| 261 | /// friends. This is declared to take (...), so we have to check everything. |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 262 | bool Sema::SemaBuiltinUnorderedCompare(CallExpr *TheCall) { |
| 263 | if (TheCall->getNumArgs() < 2) |
Chris Lattner | 2c21a07 | 2008-11-21 18:44:24 +0000 | [diff] [blame] | 264 | return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_few_args) |
| 265 | << 0 /*function call*/; |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 266 | if (TheCall->getNumArgs() > 2) |
| 267 | return Diag(TheCall->getArg(2)->getLocStart(), |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 268 | diag::err_typecheck_call_too_many_args) |
Chris Lattner | 2c21a07 | 2008-11-21 18:44:24 +0000 | [diff] [blame] | 269 | << 0 /*function call*/ |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 270 | << SourceRange(TheCall->getArg(2)->getLocStart(), |
| 271 | (*(TheCall->arg_end()-1))->getLocEnd()); |
Chris Lattner | 1b9a079 | 2007-12-20 00:26:33 +0000 | [diff] [blame] | 272 | |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 273 | Expr *OrigArg0 = TheCall->getArg(0); |
| 274 | Expr *OrigArg1 = TheCall->getArg(1); |
Chris Lattner | 1b9a079 | 2007-12-20 00:26:33 +0000 | [diff] [blame] | 275 | |
| 276 | // Do standard promotions between the two arguments, returning their common |
| 277 | // type. |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 278 | QualType Res = UsualArithmeticConversions(OrigArg0, OrigArg1, false); |
Daniel Dunbar | 403bc2b | 2009-02-19 19:28:43 +0000 | [diff] [blame] | 279 | |
| 280 | // Make sure any conversions are pushed back into the call; this is |
| 281 | // type safe since unordered compare builtins are declared as "_Bool |
| 282 | // foo(...)". |
| 283 | TheCall->setArg(0, OrigArg0); |
| 284 | TheCall->setArg(1, OrigArg1); |
Chris Lattner | 1b9a079 | 2007-12-20 00:26:33 +0000 | [diff] [blame] | 285 | |
| 286 | // If the common type isn't a real floating type, then the arguments were |
| 287 | // invalid for this operation. |
| 288 | if (!Res->isRealFloatingType()) |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 289 | return Diag(OrigArg0->getLocStart(), |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 290 | diag::err_typecheck_call_invalid_ordered_compare) |
Chris Lattner | d162584 | 2008-11-24 06:25:27 +0000 | [diff] [blame] | 291 | << OrigArg0->getType() << OrigArg1->getType() |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 292 | << SourceRange(OrigArg0->getLocStart(), OrigArg1->getLocEnd()); |
Chris Lattner | 1b9a079 | 2007-12-20 00:26:33 +0000 | [diff] [blame] | 293 | |
| 294 | return false; |
| 295 | } |
| 296 | |
Eli Friedman | 6cfda23 | 2008-05-20 08:23:37 +0000 | [diff] [blame] | 297 | bool Sema::SemaBuiltinStackAddress(CallExpr *TheCall) { |
| 298 | // The signature for these builtins is exact; the only thing we need |
| 299 | // to check is that the argument is a constant. |
| 300 | SourceLocation Loc; |
Chris Lattner | d1a0b6d | 2008-08-10 02:05:13 +0000 | [diff] [blame] | 301 | if (!TheCall->getArg(0)->isIntegerConstantExpr(Context, &Loc)) |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 302 | return Diag(Loc, diag::err_stack_const_level) << TheCall->getSourceRange(); |
Chris Lattner | d1a0b6d | 2008-08-10 02:05:13 +0000 | [diff] [blame] | 303 | |
Eli Friedman | 6cfda23 | 2008-05-20 08:23:37 +0000 | [diff] [blame] | 304 | return false; |
| 305 | } |
| 306 | |
Eli Friedman | d38617c | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 307 | /// SemaBuiltinShuffleVector - Handle __builtin_shufflevector. |
| 308 | // This is declared to take (...), so we have to check everything. |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 309 | Action::OwningExprResult Sema::SemaBuiltinShuffleVector(CallExpr *TheCall) { |
Eli Friedman | d38617c | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 310 | if (TheCall->getNumArgs() < 3) |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 311 | return ExprError(Diag(TheCall->getLocEnd(), |
| 312 | diag::err_typecheck_call_too_few_args) |
| 313 | << 0 /*function call*/ << TheCall->getSourceRange()); |
Eli Friedman | d38617c | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 314 | |
| 315 | QualType FAType = TheCall->getArg(0)->getType(); |
| 316 | QualType SAType = TheCall->getArg(1)->getType(); |
| 317 | |
| 318 | if (!FAType->isVectorType() || !SAType->isVectorType()) { |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 319 | Diag(TheCall->getLocStart(), diag::err_shufflevector_non_vector) |
| 320 | << SourceRange(TheCall->getArg(0)->getLocStart(), |
| 321 | TheCall->getArg(1)->getLocEnd()); |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 322 | return ExprError(); |
Eli Friedman | d38617c | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Chris Lattner | b77792e | 2008-07-26 22:17:49 +0000 | [diff] [blame] | 325 | if (Context.getCanonicalType(FAType).getUnqualifiedType() != |
| 326 | Context.getCanonicalType(SAType).getUnqualifiedType()) { |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 327 | Diag(TheCall->getLocStart(), diag::err_shufflevector_incompatible_vector) |
| 328 | << SourceRange(TheCall->getArg(0)->getLocStart(), |
| 329 | TheCall->getArg(1)->getLocEnd()); |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 330 | return ExprError(); |
Eli Friedman | d38617c | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | unsigned numElements = FAType->getAsVectorType()->getNumElements(); |
| 334 | if (TheCall->getNumArgs() != numElements+2) { |
| 335 | if (TheCall->getNumArgs() < numElements+2) |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 336 | return ExprError(Diag(TheCall->getLocEnd(), |
| 337 | diag::err_typecheck_call_too_few_args) |
| 338 | << 0 /*function call*/ << TheCall->getSourceRange()); |
| 339 | return ExprError(Diag(TheCall->getLocEnd(), |
| 340 | diag::err_typecheck_call_too_many_args) |
| 341 | << 0 /*function call*/ << TheCall->getSourceRange()); |
Eli Friedman | d38617c | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | for (unsigned i = 2; i < TheCall->getNumArgs(); i++) { |
| 345 | llvm::APSInt Result(32); |
Chris Lattner | d1a0b6d | 2008-08-10 02:05:13 +0000 | [diff] [blame] | 346 | if (!TheCall->getArg(i)->isIntegerConstantExpr(Result, Context)) |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 347 | return ExprError(Diag(TheCall->getLocStart(), |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 348 | diag::err_shufflevector_nonconstant_argument) |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 349 | << TheCall->getArg(i)->getSourceRange()); |
| 350 | |
Chris Lattner | d1a0b6d | 2008-08-10 02:05:13 +0000 | [diff] [blame] | 351 | if (Result.getActiveBits() > 64 || Result.getZExtValue() >= numElements*2) |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 352 | return ExprError(Diag(TheCall->getLocStart(), |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 353 | diag::err_shufflevector_argument_too_large) |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 354 | << TheCall->getArg(i)->getSourceRange()); |
Eli Friedman | d38617c | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | llvm::SmallVector<Expr*, 32> exprs; |
| 358 | |
Chris Lattner | d1a0b6d | 2008-08-10 02:05:13 +0000 | [diff] [blame] | 359 | for (unsigned i = 0, e = TheCall->getNumArgs(); i != e; i++) { |
Eli Friedman | d38617c | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 360 | exprs.push_back(TheCall->getArg(i)); |
| 361 | TheCall->setArg(i, 0); |
| 362 | } |
| 363 | |
Ted Kremenek | 8189cde | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 364 | return Owned(new (Context) ShuffleVectorExpr(exprs.begin(), numElements+2, |
| 365 | FAType, |
| 366 | TheCall->getCallee()->getLocStart(), |
| 367 | TheCall->getRParenLoc())); |
Eli Friedman | d38617c | 2008-05-14 19:38:39 +0000 | [diff] [blame] | 368 | } |
Chris Lattner | 30ce344 | 2007-12-19 23:59:04 +0000 | [diff] [blame] | 369 | |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 370 | /// SemaBuiltinPrefetch - Handle __builtin_prefetch. |
| 371 | // This is declared to take (const void*, ...) and can take two |
| 372 | // optional constant int args. |
| 373 | bool Sema::SemaBuiltinPrefetch(CallExpr *TheCall) { |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 374 | unsigned NumArgs = TheCall->getNumArgs(); |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 375 | |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 376 | if (NumArgs > 3) |
| 377 | return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_many_args) |
Chris Lattner | 2c21a07 | 2008-11-21 18:44:24 +0000 | [diff] [blame] | 378 | << 0 /*function call*/ << TheCall->getSourceRange(); |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 379 | |
| 380 | // Argument 0 is checked for us and the remaining arguments must be |
| 381 | // constant integers. |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 382 | for (unsigned i = 1; i != NumArgs; ++i) { |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 383 | Expr *Arg = TheCall->getArg(i); |
| 384 | QualType RWType = Arg->getType(); |
| 385 | |
| 386 | const BuiltinType *BT = RWType->getAsBuiltinType(); |
Daniel Dunbar | d5f8a4f | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 387 | llvm::APSInt Result; |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 388 | if (!BT || BT->getKind() != BuiltinType::Int || |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 389 | !Arg->isIntegerConstantExpr(Result, Context)) |
| 390 | return Diag(TheCall->getLocStart(), diag::err_prefetch_invalid_argument) |
| 391 | << SourceRange(Arg->getLocStart(), Arg->getLocEnd()); |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 392 | |
| 393 | // FIXME: gcc issues a warning and rewrites these to 0. These |
| 394 | // seems especially odd for the third argument since the default |
| 395 | // is 3. |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 396 | if (i == 1) { |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 397 | if (Result.getSExtValue() < 0 || Result.getSExtValue() > 1) |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 398 | return Diag(TheCall->getLocStart(), diag::err_argument_invalid_range) |
| 399 | << "0" << "1" << SourceRange(Arg->getLocStart(), Arg->getLocEnd()); |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 400 | } else { |
| 401 | if (Result.getSExtValue() < 0 || Result.getSExtValue() > 3) |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 402 | return Diag(TheCall->getLocStart(), diag::err_argument_invalid_range) |
| 403 | << "0" << "3" << SourceRange(Arg->getLocStart(), Arg->getLocEnd()); |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 407 | return false; |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 408 | } |
| 409 | |
Daniel Dunbar | d5f8a4f | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 410 | /// SemaBuiltinObjectSize - Handle __builtin_object_size(void *ptr, |
| 411 | /// int type). This simply type checks that type is one of the defined |
| 412 | /// constants (0-3). |
| 413 | bool Sema::SemaBuiltinObjectSize(CallExpr *TheCall) { |
| 414 | Expr *Arg = TheCall->getArg(1); |
| 415 | QualType ArgType = Arg->getType(); |
| 416 | const BuiltinType *BT = ArgType->getAsBuiltinType(); |
| 417 | llvm::APSInt Result(32); |
| 418 | if (!BT || BT->getKind() != BuiltinType::Int || |
| 419 | !Arg->isIntegerConstantExpr(Result, Context)) { |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 420 | return Diag(TheCall->getLocStart(), diag::err_object_size_invalid_argument) |
| 421 | << SourceRange(Arg->getLocStart(), Arg->getLocEnd()); |
Daniel Dunbar | d5f8a4f | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | if (Result.getSExtValue() < 0 || Result.getSExtValue() > 3) { |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 425 | return Diag(TheCall->getLocStart(), diag::err_argument_invalid_range) |
| 426 | << "0" << "3" << SourceRange(Arg->getLocStart(), Arg->getLocEnd()); |
Daniel Dunbar | d5f8a4f | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | return false; |
| 430 | } |
| 431 | |
Eli Friedman | 586d6a8 | 2009-05-03 06:04:26 +0000 | [diff] [blame^] | 432 | /// SemaBuiltinLongjmp - Handle __builtin_longjmp(void *env[5], int val). |
Eli Friedman | d875fed | 2009-05-03 04:46:36 +0000 | [diff] [blame] | 433 | /// This checks that val is a constant 1. |
| 434 | bool Sema::SemaBuiltinLongjmp(CallExpr *TheCall) { |
| 435 | Expr *Arg = TheCall->getArg(1); |
| 436 | llvm::APSInt Result(32); |
| 437 | if (!Arg->isIntegerConstantExpr(Result, Context) || Result != 1) |
| 438 | return Diag(TheCall->getLocStart(), diag::err_builtin_longjmp_invalid_val) |
| 439 | << SourceRange(Arg->getLocStart(), Arg->getLocEnd()); |
| 440 | |
| 441 | return false; |
| 442 | } |
| 443 | |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 444 | // Handle i > 1 ? "x" : "y", recursivelly |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 445 | bool Sema::SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall, |
| 446 | bool HasVAListArg, |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 447 | unsigned format_idx, unsigned firstDataArg) { |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 448 | |
| 449 | switch (E->getStmtClass()) { |
| 450 | case Stmt::ConditionalOperatorClass: { |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 451 | const ConditionalOperator *C = cast<ConditionalOperator>(E); |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 452 | return SemaCheckStringLiteral(C->getLHS(), TheCall, |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 453 | HasVAListArg, format_idx, firstDataArg) |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 454 | && SemaCheckStringLiteral(C->getRHS(), TheCall, |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 455 | HasVAListArg, format_idx, firstDataArg); |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | case Stmt::ImplicitCastExprClass: { |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 459 | const ImplicitCastExpr *Expr = cast<ImplicitCastExpr>(E); |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 460 | return SemaCheckStringLiteral(Expr->getSubExpr(), TheCall, HasVAListArg, |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 461 | format_idx, firstDataArg); |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | case Stmt::ParenExprClass: { |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 465 | const ParenExpr *Expr = cast<ParenExpr>(E); |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 466 | return SemaCheckStringLiteral(Expr->getSubExpr(), TheCall, HasVAListArg, |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 467 | format_idx, firstDataArg); |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 468 | } |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 469 | |
| 470 | case Stmt::DeclRefExprClass: { |
| 471 | const DeclRefExpr *DR = cast<DeclRefExpr>(E); |
| 472 | |
| 473 | // As an exception, do not flag errors for variables binding to |
| 474 | // const string literals. |
| 475 | if (const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl())) { |
| 476 | bool isConstant = false; |
| 477 | QualType T = DR->getType(); |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 478 | |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 479 | if (const ArrayType *AT = Context.getAsArrayType(T)) { |
| 480 | isConstant = AT->getElementType().isConstant(Context); |
| 481 | } |
| 482 | else if (const PointerType *PT = T->getAsPointerType()) { |
| 483 | isConstant = T.isConstant(Context) && |
| 484 | PT->getPointeeType().isConstant(Context); |
| 485 | } |
| 486 | |
| 487 | if (isConstant) { |
| 488 | const VarDecl *Def = 0; |
| 489 | if (const Expr *Init = VD->getDefinition(Def)) |
| 490 | return SemaCheckStringLiteral(Init, TheCall, |
| 491 | HasVAListArg, format_idx, firstDataArg); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | return false; |
| 496 | } |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 497 | |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 498 | case Stmt::ObjCStringLiteralClass: |
| 499 | case Stmt::StringLiteralClass: { |
| 500 | const StringLiteral *StrE = NULL; |
| 501 | |
| 502 | if (const ObjCStringLiteral *ObjCFExpr = dyn_cast<ObjCStringLiteral>(E)) |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 503 | StrE = ObjCFExpr->getString(); |
| 504 | else |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 505 | StrE = cast<StringLiteral>(E); |
| 506 | |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 507 | if (StrE) { |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 508 | CheckPrintfString(StrE, E, TheCall, HasVAListArg, format_idx, |
| 509 | firstDataArg); |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 510 | return true; |
| 511 | } |
| 512 | |
| 513 | return false; |
| 514 | } |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 515 | |
| 516 | default: |
| 517 | return false; |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | |
| 521 | |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 522 | /// CheckPrintfArguments - Check calls to printf (and similar functions) for |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 523 | /// correct use of format strings. |
| 524 | /// |
| 525 | /// HasVAListArg - A predicate indicating whether the printf-like |
| 526 | /// function is passed an explicit va_arg argument (e.g., vprintf) |
| 527 | /// |
| 528 | /// format_idx - The index into Args for the format string. |
| 529 | /// |
| 530 | /// Improper format strings to functions in the printf family can be |
| 531 | /// the source of bizarre bugs and very serious security holes. A |
| 532 | /// good source of information is available in the following paper |
| 533 | /// (which includes additional references): |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 534 | /// |
| 535 | /// FormatGuard: Automatic Protection From printf Format String |
| 536 | /// Vulnerabilities, Proceedings of the 10th USENIX Security Symposium, 2001. |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 537 | /// |
| 538 | /// Functionality implemented: |
| 539 | /// |
| 540 | /// We can statically check the following properties for string |
| 541 | /// literal format strings for non v.*printf functions (where the |
| 542 | /// arguments are passed directly): |
| 543 | // |
| 544 | /// (1) Are the number of format conversions equal to the number of |
| 545 | /// data arguments? |
| 546 | /// |
| 547 | /// (2) Does each format conversion correctly match the type of the |
| 548 | /// corresponding data argument? (TODO) |
| 549 | /// |
| 550 | /// Moreover, for all printf functions we can: |
| 551 | /// |
| 552 | /// (3) Check for a missing format string (when not caught by type checking). |
| 553 | /// |
| 554 | /// (4) Check for no-operation flags; e.g. using "#" with format |
| 555 | /// conversion 'c' (TODO) |
| 556 | /// |
| 557 | /// (5) Check the use of '%n', a major source of security holes. |
| 558 | /// |
| 559 | /// (6) Check for malformed format conversions that don't specify anything. |
| 560 | /// |
| 561 | /// (7) Check for empty format strings. e.g: printf(""); |
| 562 | /// |
| 563 | /// (8) Check that the format string is a wide literal. |
| 564 | /// |
Ted Kremenek | 6d43959 | 2008-03-03 16:50:00 +0000 | [diff] [blame] | 565 | /// (9) Also check the arguments of functions with the __format__ attribute. |
| 566 | /// (TODO). |
| 567 | /// |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 568 | /// All of these checks can be done by parsing the format string. |
| 569 | /// |
| 570 | /// For now, we ONLY do (1), (3), (5), (6), (7), and (8). |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 571 | void |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 572 | Sema::CheckPrintfArguments(const CallExpr *TheCall, bool HasVAListArg, |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 573 | unsigned format_idx, unsigned firstDataArg) { |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 574 | const Expr *Fn = TheCall->getCallee(); |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 575 | |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 576 | // CHECK: printf-like function is called with no format string. |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 577 | if (format_idx >= TheCall->getNumArgs()) { |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 578 | Diag(TheCall->getRParenLoc(), diag::warn_printf_missing_format_string) |
| 579 | << Fn->getSourceRange(); |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 580 | return; |
| 581 | } |
| 582 | |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 583 | const Expr *OrigFormatExpr = TheCall->getArg(format_idx)->IgnoreParenCasts(); |
Chris Lattner | 459e848 | 2007-08-25 05:36:18 +0000 | [diff] [blame] | 584 | |
Chris Lattner | 59907c4 | 2007-08-10 20:18:51 +0000 | [diff] [blame] | 585 | // CHECK: format string is not a string literal. |
| 586 | // |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 587 | // Dynamically generated format strings are difficult to |
| 588 | // automatically vet at compile time. Requiring that format strings |
| 589 | // are string literals: (1) permits the checking of format strings by |
| 590 | // the compiler and thereby (2) can practically remove the source of |
| 591 | // many format string exploits. |
Ted Kremenek | 7ff22b2 | 2008-06-16 18:00:42 +0000 | [diff] [blame] | 592 | |
| 593 | // Format string can be either ObjC string (e.g. @"%d") or |
| 594 | // C string (e.g. "%d") |
| 595 | // ObjC string uses the same format specifiers as C string, so we can use |
| 596 | // the same format string checking logic for both ObjC and C strings. |
Chris Lattner | 1cd3e1f | 2009-04-29 04:49:34 +0000 | [diff] [blame] | 597 | if (SemaCheckStringLiteral(OrigFormatExpr, TheCall, HasVAListArg, format_idx, |
| 598 | firstDataArg)) |
| 599 | return; // Literal format string found, check done! |
Ted Kremenek | 7ff22b2 | 2008-06-16 18:00:42 +0000 | [diff] [blame] | 600 | |
Chris Lattner | 1cd3e1f | 2009-04-29 04:49:34 +0000 | [diff] [blame] | 601 | // For vprintf* functions (i.e., HasVAListArg==true), we add a |
| 602 | // special check to see if the format string is a function parameter |
| 603 | // of the function calling the printf function. If the function |
| 604 | // has an attribute indicating it is a printf-like function, then we |
| 605 | // should suppress warnings concerning non-literals being used in a call |
| 606 | // to a vprintf function. For example: |
| 607 | // |
| 608 | // void |
| 609 | // logmessage(char const *fmt __attribute__ (format (printf, 1, 2)), ...) { |
| 610 | // va_list ap; |
| 611 | // va_start(ap, fmt); |
| 612 | // vprintf(fmt, ap); // Do NOT emit a warning about "fmt". |
| 613 | // ... |
| 614 | // |
| 615 | // |
| 616 | // FIXME: We don't have full attribute support yet, so just check to see |
| 617 | // if the argument is a DeclRefExpr that references a parameter. We'll |
| 618 | // add proper support for checking the attribute later. |
| 619 | if (HasVAListArg) |
| 620 | if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(OrigFormatExpr)) |
| 621 | if (isa<ParmVarDecl>(DR->getDecl())) |
| 622 | return; |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 623 | |
Chris Lattner | 655f141 | 2009-04-29 04:59:47 +0000 | [diff] [blame] | 624 | // If there are no arguments specified, warn with -Wformat-security, otherwise |
| 625 | // warn only with -Wformat-nonliteral. |
| 626 | if (TheCall->getNumArgs() == format_idx+1) |
| 627 | Diag(TheCall->getArg(format_idx)->getLocStart(), |
| 628 | diag::warn_printf_nonliteral_noargs) |
| 629 | << OrigFormatExpr->getSourceRange(); |
| 630 | else |
| 631 | Diag(TheCall->getArg(format_idx)->getLocStart(), |
| 632 | diag::warn_printf_nonliteral) |
| 633 | << OrigFormatExpr->getSourceRange(); |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 634 | } |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 635 | |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 636 | void Sema::CheckPrintfString(const StringLiteral *FExpr, |
| 637 | const Expr *OrigFormatExpr, |
| 638 | const CallExpr *TheCall, bool HasVAListArg, |
| 639 | unsigned format_idx, unsigned firstDataArg) { |
Ted Kremenek | d30ef87 | 2009-01-12 23:09:09 +0000 | [diff] [blame] | 640 | |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 641 | const ObjCStringLiteral *ObjCFExpr = |
| 642 | dyn_cast<ObjCStringLiteral>(OrigFormatExpr); |
| 643 | |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 644 | // CHECK: is the format string a wide literal? |
| 645 | if (FExpr->isWide()) { |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 646 | Diag(FExpr->getLocStart(), |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 647 | diag::warn_printf_format_string_is_wide_literal) |
| 648 | << OrigFormatExpr->getSourceRange(); |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 649 | return; |
| 650 | } |
| 651 | |
| 652 | // Str - The format string. NOTE: this is NOT null-terminated! |
Chris Lattner | b9fc856 | 2009-04-29 04:12:34 +0000 | [diff] [blame] | 653 | const char *Str = FExpr->getStrData(); |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 654 | |
| 655 | // CHECK: empty format string? |
Chris Lattner | b9fc856 | 2009-04-29 04:12:34 +0000 | [diff] [blame] | 656 | unsigned StrLen = FExpr->getByteLength(); |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 657 | |
| 658 | if (StrLen == 0) { |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 659 | Diag(FExpr->getLocStart(), diag::warn_printf_empty_format_string) |
| 660 | << OrigFormatExpr->getSourceRange(); |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 661 | return; |
| 662 | } |
| 663 | |
| 664 | // We process the format string using a binary state machine. The |
| 665 | // current state is stored in CurrentState. |
| 666 | enum { |
| 667 | state_OrdChr, |
| 668 | state_Conversion |
| 669 | } CurrentState = state_OrdChr; |
| 670 | |
| 671 | // numConversions - The number of conversions seen so far. This is |
| 672 | // incremented as we traverse the format string. |
| 673 | unsigned numConversions = 0; |
| 674 | |
| 675 | // numDataArgs - The number of data arguments after the format |
| 676 | // string. This can only be determined for non vprintf-like |
| 677 | // functions. For those functions, this value is 1 (the sole |
| 678 | // va_arg argument). |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 679 | unsigned numDataArgs = TheCall->getNumArgs()-firstDataArg; |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 680 | |
| 681 | // Inspect the format string. |
| 682 | unsigned StrIdx = 0; |
| 683 | |
| 684 | // LastConversionIdx - Index within the format string where we last saw |
| 685 | // a '%' character that starts a new format conversion. |
| 686 | unsigned LastConversionIdx = 0; |
| 687 | |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 688 | for (; StrIdx < StrLen; ++StrIdx) { |
Chris Lattner | 998568f | 2007-12-28 05:38:24 +0000 | [diff] [blame] | 689 | |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 690 | // Is the number of detected conversion conversions greater than |
| 691 | // the number of matching data arguments? If so, stop. |
| 692 | if (!HasVAListArg && numConversions > numDataArgs) break; |
| 693 | |
| 694 | // Handle "\0" |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 695 | if (Str[StrIdx] == '\0') { |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 696 | // The string returned by getStrData() is not null-terminated, |
| 697 | // so the presence of a null character is likely an error. |
Chris Lattner | 6080008 | 2009-02-18 17:49:48 +0000 | [diff] [blame] | 698 | Diag(getLocationOfStringLiteralByte(FExpr, StrIdx), |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 699 | diag::warn_printf_format_string_contains_null_char) |
| 700 | << OrigFormatExpr->getSourceRange(); |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 701 | return; |
| 702 | } |
| 703 | |
| 704 | // Ordinary characters (not processing a format conversion). |
| 705 | if (CurrentState == state_OrdChr) { |
| 706 | if (Str[StrIdx] == '%') { |
| 707 | CurrentState = state_Conversion; |
| 708 | LastConversionIdx = StrIdx; |
| 709 | } |
| 710 | continue; |
| 711 | } |
| 712 | |
| 713 | // Seen '%'. Now processing a format conversion. |
| 714 | switch (Str[StrIdx]) { |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 715 | // Handle dynamic precision or width specifier. |
| 716 | case '*': { |
| 717 | ++numConversions; |
| 718 | |
| 719 | if (!HasVAListArg && numConversions > numDataArgs) { |
Chris Lattner | 6080008 | 2009-02-18 17:49:48 +0000 | [diff] [blame] | 720 | SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, StrIdx); |
Ted Kremenek | 580b664 | 2007-10-12 20:51:52 +0000 | [diff] [blame] | 721 | |
Ted Kremenek | 580b664 | 2007-10-12 20:51:52 +0000 | [diff] [blame] | 722 | if (Str[StrIdx-1] == '.') |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 723 | Diag(Loc, diag::warn_printf_asterisk_precision_missing_arg) |
| 724 | << OrigFormatExpr->getSourceRange(); |
Ted Kremenek | 580b664 | 2007-10-12 20:51:52 +0000 | [diff] [blame] | 725 | else |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 726 | Diag(Loc, diag::warn_printf_asterisk_width_missing_arg) |
| 727 | << OrigFormatExpr->getSourceRange(); |
Ted Kremenek | 580b664 | 2007-10-12 20:51:52 +0000 | [diff] [blame] | 728 | |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 729 | // Don't do any more checking. We'll just emit spurious errors. |
| 730 | return; |
Ted Kremenek | 580b664 | 2007-10-12 20:51:52 +0000 | [diff] [blame] | 731 | } |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 732 | |
| 733 | // Perform type checking on width/precision specifier. |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 734 | const Expr *E = TheCall->getArg(format_idx+numConversions); |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 735 | if (const BuiltinType *BT = E->getType()->getAsBuiltinType()) |
| 736 | if (BT->getKind() == BuiltinType::Int) |
| 737 | break; |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 738 | |
Chris Lattner | 6080008 | 2009-02-18 17:49:48 +0000 | [diff] [blame] | 739 | SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, StrIdx); |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 740 | |
| 741 | if (Str[StrIdx-1] == '.') |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 742 | Diag(Loc, diag::warn_printf_asterisk_precision_wrong_type) |
Chris Lattner | d162584 | 2008-11-24 06:25:27 +0000 | [diff] [blame] | 743 | << E->getType() << E->getSourceRange(); |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 744 | else |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 745 | Diag(Loc, diag::warn_printf_asterisk_width_wrong_type) |
Chris Lattner | d162584 | 2008-11-24 06:25:27 +0000 | [diff] [blame] | 746 | << E->getType() << E->getSourceRange(); |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 747 | |
| 748 | break; |
| 749 | } |
| 750 | |
| 751 | // Characters which can terminate a format conversion |
| 752 | // (e.g. "%d"). Characters that specify length modifiers or |
| 753 | // other flags are handled by the default case below. |
| 754 | // |
| 755 | // FIXME: additional checks will go into the following cases. |
| 756 | case 'i': |
| 757 | case 'd': |
| 758 | case 'o': |
| 759 | case 'u': |
| 760 | case 'x': |
| 761 | case 'X': |
| 762 | case 'D': |
| 763 | case 'O': |
| 764 | case 'U': |
| 765 | case 'e': |
| 766 | case 'E': |
| 767 | case 'f': |
| 768 | case 'F': |
| 769 | case 'g': |
| 770 | case 'G': |
| 771 | case 'a': |
| 772 | case 'A': |
| 773 | case 'c': |
| 774 | case 'C': |
| 775 | case 'S': |
| 776 | case 's': |
| 777 | case 'p': |
| 778 | ++numConversions; |
| 779 | CurrentState = state_OrdChr; |
| 780 | break; |
| 781 | |
| 782 | // CHECK: Are we using "%n"? Issue a warning. |
| 783 | case 'n': { |
| 784 | ++numConversions; |
| 785 | CurrentState = state_OrdChr; |
Chris Lattner | 6080008 | 2009-02-18 17:49:48 +0000 | [diff] [blame] | 786 | SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, |
| 787 | LastConversionIdx); |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 788 | |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 789 | Diag(Loc, diag::warn_printf_write_back)<<OrigFormatExpr->getSourceRange(); |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 790 | break; |
| 791 | } |
Ted Kremenek | 7ff22b2 | 2008-06-16 18:00:42 +0000 | [diff] [blame] | 792 | |
| 793 | // Handle "%@" |
| 794 | case '@': |
| 795 | // %@ is allowed in ObjC format strings only. |
| 796 | if(ObjCFExpr != NULL) |
| 797 | CurrentState = state_OrdChr; |
| 798 | else { |
| 799 | // Issue a warning: invalid format conversion. |
Chris Lattner | 6080008 | 2009-02-18 17:49:48 +0000 | [diff] [blame] | 800 | SourceLocation Loc = |
| 801 | getLocationOfStringLiteralByte(FExpr, LastConversionIdx); |
Ted Kremenek | 7ff22b2 | 2008-06-16 18:00:42 +0000 | [diff] [blame] | 802 | |
Chris Lattner | d3a94e2 | 2008-11-20 06:06:08 +0000 | [diff] [blame] | 803 | Diag(Loc, diag::warn_printf_invalid_conversion) |
| 804 | << std::string(Str+LastConversionIdx, |
| 805 | Str+std::min(LastConversionIdx+2, StrLen)) |
| 806 | << OrigFormatExpr->getSourceRange(); |
Ted Kremenek | 7ff22b2 | 2008-06-16 18:00:42 +0000 | [diff] [blame] | 807 | } |
| 808 | ++numConversions; |
| 809 | break; |
| 810 | |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 811 | // Handle "%%" |
| 812 | case '%': |
| 813 | // Sanity check: Was the first "%" character the previous one? |
| 814 | // If not, we will assume that we have a malformed format |
| 815 | // conversion, and that the current "%" character is the start |
| 816 | // of a new conversion. |
| 817 | if (StrIdx - LastConversionIdx == 1) |
| 818 | CurrentState = state_OrdChr; |
| 819 | else { |
| 820 | // Issue a warning: invalid format conversion. |
Chris Lattner | 6080008 | 2009-02-18 17:49:48 +0000 | [diff] [blame] | 821 | SourceLocation Loc = |
| 822 | getLocationOfStringLiteralByte(FExpr, LastConversionIdx); |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 823 | |
Chris Lattner | d3a94e2 | 2008-11-20 06:06:08 +0000 | [diff] [blame] | 824 | Diag(Loc, diag::warn_printf_invalid_conversion) |
| 825 | << std::string(Str+LastConversionIdx, Str+StrIdx) |
| 826 | << OrigFormatExpr->getSourceRange(); |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 827 | |
| 828 | // This conversion is broken. Advance to the next format |
| 829 | // conversion. |
| 830 | LastConversionIdx = StrIdx; |
| 831 | ++numConversions; |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 832 | } |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 833 | break; |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 834 | |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 835 | default: |
| 836 | // This case catches all other characters: flags, widths, etc. |
| 837 | // We should eventually process those as well. |
| 838 | break; |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 839 | } |
| 840 | } |
| 841 | |
| 842 | if (CurrentState == state_Conversion) { |
| 843 | // Issue a warning: invalid format conversion. |
Chris Lattner | 6080008 | 2009-02-18 17:49:48 +0000 | [diff] [blame] | 844 | SourceLocation Loc = |
| 845 | getLocationOfStringLiteralByte(FExpr, LastConversionIdx); |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 846 | |
Chris Lattner | d3a94e2 | 2008-11-20 06:06:08 +0000 | [diff] [blame] | 847 | Diag(Loc, diag::warn_printf_invalid_conversion) |
| 848 | << std::string(Str+LastConversionIdx, |
| 849 | Str+std::min(LastConversionIdx+2, StrLen)) |
| 850 | << OrigFormatExpr->getSourceRange(); |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 851 | return; |
| 852 | } |
| 853 | |
| 854 | if (!HasVAListArg) { |
| 855 | // CHECK: Does the number of format conversions exceed the number |
| 856 | // of data arguments? |
| 857 | if (numConversions > numDataArgs) { |
Chris Lattner | 6080008 | 2009-02-18 17:49:48 +0000 | [diff] [blame] | 858 | SourceLocation Loc = |
| 859 | getLocationOfStringLiteralByte(FExpr, LastConversionIdx); |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 860 | |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 861 | Diag(Loc, diag::warn_printf_insufficient_data_args) |
| 862 | << OrigFormatExpr->getSourceRange(); |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 863 | } |
| 864 | // CHECK: Does the number of data arguments exceed the number of |
| 865 | // format conversions in the format string? |
| 866 | else if (numConversions < numDataArgs) |
Chris Lattner | 925e60d | 2007-12-28 05:29:59 +0000 | [diff] [blame] | 867 | Diag(TheCall->getArg(format_idx+numConversions+1)->getLocStart(), |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 868 | diag::warn_printf_too_many_data_args) |
| 869 | << OrigFormatExpr->getSourceRange(); |
Ted Kremenek | 71895b9 | 2007-08-14 17:39:48 +0000 | [diff] [blame] | 870 | } |
| 871 | } |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 872 | |
| 873 | //===--- CHECK: Return Address of Stack Variable --------------------------===// |
| 874 | |
| 875 | static DeclRefExpr* EvalVal(Expr *E); |
| 876 | static DeclRefExpr* EvalAddr(Expr* E); |
| 877 | |
| 878 | /// CheckReturnStackAddr - Check if a return statement returns the address |
| 879 | /// of a stack variable. |
| 880 | void |
| 881 | Sema::CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, |
| 882 | SourceLocation ReturnLoc) { |
Chris Lattner | 56f3494 | 2008-02-13 01:02:39 +0000 | [diff] [blame] | 883 | |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 884 | // Perform checking for returned stack addresses. |
Steve Naroff | dd972f2 | 2008-09-05 22:11:13 +0000 | [diff] [blame] | 885 | if (lhsType->isPointerType() || lhsType->isBlockPointerType()) { |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 886 | if (DeclRefExpr *DR = EvalAddr(RetValExp)) |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 887 | Diag(DR->getLocStart(), diag::warn_ret_stack_addr) |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 888 | << DR->getDecl()->getDeclName() << RetValExp->getSourceRange(); |
Steve Naroff | c50a4a5 | 2008-09-16 22:25:10 +0000 | [diff] [blame] | 889 | |
| 890 | // Skip over implicit cast expressions when checking for block expressions. |
| 891 | if (ImplicitCastExpr *IcExpr = |
| 892 | dyn_cast_or_null<ImplicitCastExpr>(RetValExp)) |
| 893 | RetValExp = IcExpr->getSubExpr(); |
| 894 | |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 895 | if (BlockExpr *C = dyn_cast_or_null<BlockExpr>(RetValExp)) |
Mike Stump | 397195b | 2009-04-17 00:09:41 +0000 | [diff] [blame] | 896 | if (C->hasBlockDeclRefExprs()) |
| 897 | Diag(C->getLocStart(), diag::err_ret_local_block) |
| 898 | << C->getSourceRange(); |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 899 | } |
| 900 | // Perform checking for stack values returned by reference. |
| 901 | else if (lhsType->isReferenceType()) { |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 902 | // Check for a reference to the stack |
| 903 | if (DeclRefExpr *DR = EvalVal(RetValExp)) |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 904 | Diag(DR->getLocStart(), diag::warn_ret_stack_ref) |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 905 | << DR->getDecl()->getDeclName() << RetValExp->getSourceRange(); |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 906 | } |
| 907 | } |
| 908 | |
| 909 | /// EvalAddr - EvalAddr and EvalVal are mutually recursive functions that |
| 910 | /// check if the expression in a return statement evaluates to an address |
| 911 | /// to a location on the stack. The recursion is used to traverse the |
| 912 | /// AST of the return expression, with recursion backtracking when we |
| 913 | /// encounter a subexpression that (1) clearly does not lead to the address |
| 914 | /// of a stack variable or (2) is something we cannot determine leads to |
| 915 | /// the address of a stack variable based on such local checking. |
| 916 | /// |
Ted Kremenek | e8c600f | 2007-08-28 17:02:55 +0000 | [diff] [blame] | 917 | /// EvalAddr processes expressions that are pointers that are used as |
| 918 | /// references (and not L-values). EvalVal handles all other values. |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 919 | /// At the base case of the recursion is a check for a DeclRefExpr* in |
| 920 | /// the refers to a stack variable. |
| 921 | /// |
| 922 | /// This implementation handles: |
| 923 | /// |
| 924 | /// * pointer-to-pointer casts |
| 925 | /// * implicit conversions from array references to pointers |
| 926 | /// * taking the address of fields |
| 927 | /// * arbitrary interplay between "&" and "*" operators |
| 928 | /// * pointer arithmetic from an address of a stack variable |
| 929 | /// * taking the address of an array element where the array is on the stack |
| 930 | static DeclRefExpr* EvalAddr(Expr *E) { |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 931 | // We should only be called for evaluating pointer expressions. |
Steve Naroff | dd972f2 | 2008-09-05 22:11:13 +0000 | [diff] [blame] | 932 | assert((E->getType()->isPointerType() || |
| 933 | E->getType()->isBlockPointerType() || |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 934 | E->getType()->isObjCQualifiedIdType()) && |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 935 | "EvalAddr only works on pointers"); |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 936 | |
| 937 | // Our "symbolic interpreter" is just a dispatch off the currently |
| 938 | // viewed AST node. We then recursively traverse the AST by calling |
| 939 | // EvalAddr and EvalVal appropriately. |
| 940 | switch (E->getStmtClass()) { |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 941 | case Stmt::ParenExprClass: |
| 942 | // Ignore parentheses. |
| 943 | return EvalAddr(cast<ParenExpr>(E)->getSubExpr()); |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 944 | |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 945 | case Stmt::UnaryOperatorClass: { |
| 946 | // The only unary operator that make sense to handle here |
| 947 | // is AddrOf. All others don't make sense as pointers. |
| 948 | UnaryOperator *U = cast<UnaryOperator>(E); |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 949 | |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 950 | if (U->getOpcode() == UnaryOperator::AddrOf) |
| 951 | return EvalVal(U->getSubExpr()); |
| 952 | else |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 953 | return NULL; |
| 954 | } |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 955 | |
| 956 | case Stmt::BinaryOperatorClass: { |
| 957 | // Handle pointer arithmetic. All other binary operators are not valid |
| 958 | // in this context. |
| 959 | BinaryOperator *B = cast<BinaryOperator>(E); |
| 960 | BinaryOperator::Opcode op = B->getOpcode(); |
| 961 | |
| 962 | if (op != BinaryOperator::Add && op != BinaryOperator::Sub) |
| 963 | return NULL; |
| 964 | |
| 965 | Expr *Base = B->getLHS(); |
| 966 | |
| 967 | // Determine which argument is the real pointer base. It could be |
| 968 | // the RHS argument instead of the LHS. |
| 969 | if (!Base->getType()->isPointerType()) Base = B->getRHS(); |
| 970 | |
| 971 | assert (Base->getType()->isPointerType()); |
| 972 | return EvalAddr(Base); |
| 973 | } |
Steve Naroff | 61f40a2 | 2008-09-10 19:17:48 +0000 | [diff] [blame] | 974 | |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 975 | // For conditional operators we need to see if either the LHS or RHS are |
| 976 | // valid DeclRefExpr*s. If one of them is valid, we return it. |
| 977 | case Stmt::ConditionalOperatorClass: { |
| 978 | ConditionalOperator *C = cast<ConditionalOperator>(E); |
| 979 | |
| 980 | // Handle the GNU extension for missing LHS. |
| 981 | if (Expr *lhsExpr = C->getLHS()) |
| 982 | if (DeclRefExpr* LHS = EvalAddr(lhsExpr)) |
| 983 | return LHS; |
| 984 | |
| 985 | return EvalAddr(C->getRHS()); |
| 986 | } |
| 987 | |
Ted Kremenek | 54b5274 | 2008-08-07 00:49:01 +0000 | [diff] [blame] | 988 | // For casts, we need to handle conversions from arrays to |
| 989 | // pointer values, and pointer-to-pointer conversions. |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 990 | case Stmt::ImplicitCastExprClass: |
Douglas Gregor | 6eec8e8 | 2008-10-28 15:36:24 +0000 | [diff] [blame] | 991 | case Stmt::CStyleCastExprClass: |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 992 | case Stmt::CXXFunctionalCastExprClass: { |
Argyrios Kyrtzidis | 0835a3c | 2008-08-18 23:01:59 +0000 | [diff] [blame] | 993 | Expr* SubExpr = cast<CastExpr>(E)->getSubExpr(); |
Ted Kremenek | 54b5274 | 2008-08-07 00:49:01 +0000 | [diff] [blame] | 994 | QualType T = SubExpr->getType(); |
| 995 | |
Steve Naroff | dd972f2 | 2008-09-05 22:11:13 +0000 | [diff] [blame] | 996 | if (SubExpr->getType()->isPointerType() || |
| 997 | SubExpr->getType()->isBlockPointerType() || |
| 998 | SubExpr->getType()->isObjCQualifiedIdType()) |
Ted Kremenek | 54b5274 | 2008-08-07 00:49:01 +0000 | [diff] [blame] | 999 | return EvalAddr(SubExpr); |
| 1000 | else if (T->isArrayType()) |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 1001 | return EvalVal(SubExpr); |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 1002 | else |
Ted Kremenek | 54b5274 | 2008-08-07 00:49:01 +0000 | [diff] [blame] | 1003 | return 0; |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | // C++ casts. For dynamic casts, static casts, and const casts, we |
| 1007 | // are always converting from a pointer-to-pointer, so we just blow |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 1008 | // through the cast. In the case the dynamic cast doesn't fail (and |
| 1009 | // return NULL), we take the conservative route and report cases |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 1010 | // where we return the address of a stack variable. For Reinterpre |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 1011 | // FIXME: The comment about is wrong; we're not always converting |
| 1012 | // from pointer to pointer. I'm guessing that this code should also |
| 1013 | // handle references to objects. |
| 1014 | case Stmt::CXXStaticCastExprClass: |
| 1015 | case Stmt::CXXDynamicCastExprClass: |
| 1016 | case Stmt::CXXConstCastExprClass: |
| 1017 | case Stmt::CXXReinterpretCastExprClass: { |
| 1018 | Expr *S = cast<CXXNamedCastExpr>(E)->getSubExpr(); |
Steve Naroff | dd972f2 | 2008-09-05 22:11:13 +0000 | [diff] [blame] | 1019 | if (S->getType()->isPointerType() || S->getType()->isBlockPointerType()) |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 1020 | return EvalAddr(S); |
| 1021 | else |
| 1022 | return NULL; |
Chris Lattner | fae3f1f | 2007-12-28 05:31:15 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | // Everything else: we simply don't reason about them. |
| 1026 | default: |
| 1027 | return NULL; |
| 1028 | } |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | |
| 1032 | /// EvalVal - This function is complements EvalAddr in the mutual recursion. |
| 1033 | /// See the comments for EvalAddr for more details. |
| 1034 | static DeclRefExpr* EvalVal(Expr *E) { |
| 1035 | |
Ted Kremenek | e8c600f | 2007-08-28 17:02:55 +0000 | [diff] [blame] | 1036 | // We should only be called for evaluating non-pointer expressions, or |
| 1037 | // expressions with a pointer type that are not used as references but instead |
| 1038 | // are l-values (e.g., DeclRefExpr with a pointer type). |
| 1039 | |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 1040 | // Our "symbolic interpreter" is just a dispatch off the currently |
| 1041 | // viewed AST node. We then recursively traverse the AST by calling |
| 1042 | // EvalAddr and EvalVal appropriately. |
| 1043 | switch (E->getStmtClass()) { |
Douglas Gregor | 1a49af9 | 2009-01-06 05:10:23 +0000 | [diff] [blame] | 1044 | case Stmt::DeclRefExprClass: |
| 1045 | case Stmt::QualifiedDeclRefExprClass: { |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 1046 | // DeclRefExpr: the base case. When we hit a DeclRefExpr we are looking |
| 1047 | // at code that refers to a variable's name. We check if it has local |
| 1048 | // storage within the function, and if so, return the expression. |
| 1049 | DeclRefExpr *DR = cast<DeclRefExpr>(E); |
| 1050 | |
| 1051 | if (VarDecl *V = dyn_cast<VarDecl>(DR->getDecl())) |
Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 1052 | if(V->hasLocalStorage() && !V->getType()->isReferenceType()) return DR; |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 1053 | |
| 1054 | return NULL; |
| 1055 | } |
| 1056 | |
| 1057 | case Stmt::ParenExprClass: |
| 1058 | // Ignore parentheses. |
| 1059 | return EvalVal(cast<ParenExpr>(E)->getSubExpr()); |
| 1060 | |
| 1061 | case Stmt::UnaryOperatorClass: { |
| 1062 | // The only unary operator that make sense to handle here |
| 1063 | // is Deref. All others don't resolve to a "name." This includes |
| 1064 | // handling all sorts of rvalues passed to a unary operator. |
| 1065 | UnaryOperator *U = cast<UnaryOperator>(E); |
| 1066 | |
| 1067 | if (U->getOpcode() == UnaryOperator::Deref) |
| 1068 | return EvalAddr(U->getSubExpr()); |
| 1069 | |
| 1070 | return NULL; |
| 1071 | } |
| 1072 | |
| 1073 | case Stmt::ArraySubscriptExprClass: { |
| 1074 | // Array subscripts are potential references to data on the stack. We |
| 1075 | // retrieve the DeclRefExpr* for the array variable if it indeed |
| 1076 | // has local storage. |
Ted Kremenek | 2324512 | 2007-08-20 16:18:38 +0000 | [diff] [blame] | 1077 | return EvalAddr(cast<ArraySubscriptExpr>(E)->getBase()); |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | case Stmt::ConditionalOperatorClass: { |
| 1081 | // For conditional operators we need to see if either the LHS or RHS are |
| 1082 | // non-NULL DeclRefExpr's. If one is non-NULL, we return it. |
| 1083 | ConditionalOperator *C = cast<ConditionalOperator>(E); |
| 1084 | |
Anders Carlsson | 3907323 | 2007-11-30 19:04:31 +0000 | [diff] [blame] | 1085 | // Handle the GNU extension for missing LHS. |
| 1086 | if (Expr *lhsExpr = C->getLHS()) |
| 1087 | if (DeclRefExpr *LHS = EvalVal(lhsExpr)) |
| 1088 | return LHS; |
| 1089 | |
| 1090 | return EvalVal(C->getRHS()); |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | // Accesses to members are potential references to data on the stack. |
| 1094 | case Stmt::MemberExprClass: { |
| 1095 | MemberExpr *M = cast<MemberExpr>(E); |
| 1096 | |
| 1097 | // Check for indirect access. We only want direct field accesses. |
| 1098 | if (!M->isArrow()) |
| 1099 | return EvalVal(M->getBase()); |
| 1100 | else |
| 1101 | return NULL; |
| 1102 | } |
| 1103 | |
| 1104 | // Everything else: we simply don't reason about them. |
| 1105 | default: |
| 1106 | return NULL; |
| 1107 | } |
| 1108 | } |
Ted Kremenek | 588e5eb | 2007-11-25 00:58:00 +0000 | [diff] [blame] | 1109 | |
| 1110 | //===--- CHECK: Floating-Point comparisons (-Wfloat-equal) ---------------===// |
| 1111 | |
| 1112 | /// Check for comparisons of floating point operands using != and ==. |
| 1113 | /// Issue a warning if these are no self-comparisons, as they are not likely |
| 1114 | /// to do what the programmer intended. |
| 1115 | void Sema::CheckFloatComparison(SourceLocation loc, Expr* lex, Expr *rex) { |
| 1116 | bool EmitWarning = true; |
| 1117 | |
Ted Kremenek | 4e99a5f | 2008-01-17 16:57:34 +0000 | [diff] [blame] | 1118 | Expr* LeftExprSansParen = lex->IgnoreParens(); |
Ted Kremenek | 32e97b6 | 2008-01-17 17:55:13 +0000 | [diff] [blame] | 1119 | Expr* RightExprSansParen = rex->IgnoreParens(); |
Ted Kremenek | 588e5eb | 2007-11-25 00:58:00 +0000 | [diff] [blame] | 1120 | |
| 1121 | // Special case: check for x == x (which is OK). |
| 1122 | // Do not emit warnings for such cases. |
| 1123 | if (DeclRefExpr* DRL = dyn_cast<DeclRefExpr>(LeftExprSansParen)) |
| 1124 | if (DeclRefExpr* DRR = dyn_cast<DeclRefExpr>(RightExprSansParen)) |
| 1125 | if (DRL->getDecl() == DRR->getDecl()) |
| 1126 | EmitWarning = false; |
| 1127 | |
Ted Kremenek | 1b500bb | 2007-11-29 00:59:04 +0000 | [diff] [blame] | 1128 | |
| 1129 | // Special case: check for comparisons against literals that can be exactly |
| 1130 | // represented by APFloat. In such cases, do not emit a warning. This |
| 1131 | // is a heuristic: often comparison against such literals are used to |
| 1132 | // detect if a value in a variable has not changed. This clearly can |
| 1133 | // lead to false negatives. |
| 1134 | if (EmitWarning) { |
| 1135 | if (FloatingLiteral* FLL = dyn_cast<FloatingLiteral>(LeftExprSansParen)) { |
| 1136 | if (FLL->isExact()) |
| 1137 | EmitWarning = false; |
| 1138 | } |
| 1139 | else |
| 1140 | if (FloatingLiteral* FLR = dyn_cast<FloatingLiteral>(RightExprSansParen)){ |
| 1141 | if (FLR->isExact()) |
| 1142 | EmitWarning = false; |
| 1143 | } |
| 1144 | } |
| 1145 | |
Ted Kremenek | 588e5eb | 2007-11-25 00:58:00 +0000 | [diff] [blame] | 1146 | // Check for comparisons with builtin types. |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 1147 | if (EmitWarning) |
Ted Kremenek | 588e5eb | 2007-11-25 00:58:00 +0000 | [diff] [blame] | 1148 | if (CallExpr* CL = dyn_cast<CallExpr>(LeftExprSansParen)) |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 1149 | if (CL->isBuiltinCall(Context)) |
Ted Kremenek | 588e5eb | 2007-11-25 00:58:00 +0000 | [diff] [blame] | 1150 | EmitWarning = false; |
| 1151 | |
Sebastian Redl | 0eb2330 | 2009-01-19 00:08:26 +0000 | [diff] [blame] | 1152 | if (EmitWarning) |
Ted Kremenek | 588e5eb | 2007-11-25 00:58:00 +0000 | [diff] [blame] | 1153 | if (CallExpr* CR = dyn_cast<CallExpr>(RightExprSansParen)) |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 1154 | if (CR->isBuiltinCall(Context)) |
Ted Kremenek | 588e5eb | 2007-11-25 00:58:00 +0000 | [diff] [blame] | 1155 | EmitWarning = false; |
| 1156 | |
| 1157 | // Emit the diagnostic. |
| 1158 | if (EmitWarning) |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 1159 | Diag(loc, diag::warn_floatingpoint_eq) |
| 1160 | << lex->getSourceRange() << rex->getSourceRange(); |
Ted Kremenek | 588e5eb | 2007-11-25 00:58:00 +0000 | [diff] [blame] | 1161 | } |