blob: a62c73e8fb76617b7271b064e41599f5b45b8aed [file] [log] [blame]
Chris Lattner2e64c072007-08-10 20:18:51 +00001//===--- SemaChecking.cpp - Extra Semantic Checking -----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Ted Kremenek and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
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"
17#include "clang/AST/Decl.h"
18#include "clang/AST/Expr.h"
Ted Kremenek1c1700f2007-08-20 16:18:38 +000019#include "clang/AST/ExprCXX.h"
Chris Lattner2e64c072007-08-10 20:18:51 +000020#include "clang/Lex/Preprocessor.h"
21#include "clang/Lex/LiteralSupport.h"
22#include "clang/Basic/SourceManager.h"
23#include "clang/Basic/Diagnostic.h"
24#include "clang/Basic/LangOptions.h"
25#include "clang/Basic/TargetInfo.h"
26#include "llvm/ADT/SmallString.h"
27#include "llvm/ADT/StringExtras.h"
28using namespace clang;
29
30/// CheckFunctionCall - Check a direct function call for various correctness
31/// and safety properties not strictly enforced by the C type system.
Anders Carlssone7e7aa22007-08-17 05:31:46 +000032bool
Ted Kremenek081ed872007-08-14 17:39:48 +000033Sema::CheckFunctionCall(Expr *Fn,
34 SourceLocation LParenLoc, SourceLocation RParenLoc,
35 FunctionDecl *FDecl,
Chris Lattner2e64c072007-08-10 20:18:51 +000036 Expr** Args, unsigned NumArgsInCall) {
37
38 // Get the IdentifierInfo* for the called function.
39 IdentifierInfo *FnInfo = FDecl->getIdentifier();
40
Anders Carlssone7e7aa22007-08-17 05:31:46 +000041 if (FnInfo->getBuiltinID() ==
42 Builtin::BI__builtin___CFStringMakeConstantString) {
43 assert(NumArgsInCall == 1 &&
44 "Wrong number of arguments to builtin CFStringMakeConstantString");
45 return CheckBuiltinCFStringArgument(Args[0]);
46 }
47
Chris Lattner2e64c072007-08-10 20:18:51 +000048 // Search the KnownFunctionIDs for the identifier.
49 unsigned i = 0, e = id_num_known_functions;
Ted Kremenek081ed872007-08-14 17:39:48 +000050 for (; i != e; ++i) { if (KnownFunctionIDs[i] == FnInfo) break; }
Anders Carlsson3e9b43b2007-08-17 15:44:17 +000051 if (i == e) return false;
Chris Lattner2e64c072007-08-10 20:18:51 +000052
53 // Printf checking.
54 if (i <= id_vprintf) {
Ted Kremenek081ed872007-08-14 17:39:48 +000055 // Retrieve the index of the format string parameter and determine
56 // if the function is passed a va_arg argument.
Chris Lattner2e64c072007-08-10 20:18:51 +000057 unsigned format_idx = 0;
Ted Kremenek081ed872007-08-14 17:39:48 +000058 bool HasVAListArg = false;
59
Chris Lattner2e64c072007-08-10 20:18:51 +000060 switch (i) {
61 default: assert(false && "No format string argument index.");
62 case id_printf: format_idx = 0; break;
63 case id_fprintf: format_idx = 1; break;
64 case id_sprintf: format_idx = 1; break;
65 case id_snprintf: format_idx = 2; break;
Ted Kremenek081ed872007-08-14 17:39:48 +000066 case id_asprintf: format_idx = 1; HasVAListArg = true; break;
67 case id_vsnprintf: format_idx = 2; HasVAListArg = true; break;
68 case id_vasprintf: format_idx = 1; HasVAListArg = true; break;
69 case id_vfprintf: format_idx = 1; HasVAListArg = true; break;
70 case id_vsprintf: format_idx = 1; HasVAListArg = true; break;
71 case id_vprintf: format_idx = 0; HasVAListArg = true; break;
72 }
73
74 CheckPrintfArguments(Fn, LParenLoc, RParenLoc, HasVAListArg,
Ted Kremenek45925ab2007-08-17 16:46:58 +000075 FDecl, format_idx, Args, NumArgsInCall);
Chris Lattner2e64c072007-08-10 20:18:51 +000076 }
Anders Carlssone7e7aa22007-08-17 05:31:46 +000077
Anders Carlsson3e9b43b2007-08-17 15:44:17 +000078 return false;
Anders Carlssone7e7aa22007-08-17 05:31:46 +000079}
80
81/// CheckBuiltinCFStringArgument - Checks that the argument to the builtin
82/// CFString constructor is correct
Chris Lattnerda050402007-08-25 05:30:33 +000083bool Sema::CheckBuiltinCFStringArgument(Expr* Arg) {
84 while (1) {
85 if (ParenExpr *PE = dyn_cast<ParenExpr>(Arg))
86 Arg = PE->getSubExpr();
87 else if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Arg))
88 Arg = ICE->getSubExpr();
89 else
90 break;
91 }
Anders Carlssone7e7aa22007-08-17 05:31:46 +000092
93 StringLiteral *Literal = dyn_cast<StringLiteral>(Arg);
94
95 if (!Literal || Literal->isWide()) {
96 Diag(Arg->getLocStart(),
97 diag::err_cfstring_literal_not_string_constant,
98 Arg->getSourceRange());
Anders Carlsson3e9b43b2007-08-17 15:44:17 +000099 return true;
Anders Carlssone7e7aa22007-08-17 05:31:46 +0000100 }
101
102 const char *Data = Literal->getStrData();
103 unsigned Length = Literal->getByteLength();
104
105 for (unsigned i = 0; i < Length; ++i) {
106 if (!isascii(Data[i])) {
107 Diag(PP.AdvanceToTokenCharacter(Arg->getLocStart(), i + 1),
108 diag::warn_cfstring_literal_contains_non_ascii_character,
109 Arg->getSourceRange());
110 break;
111 }
112
113 if (!Data[i]) {
114 Diag(PP.AdvanceToTokenCharacter(Arg->getLocStart(), i + 1),
115 diag::warn_cfstring_literal_contains_nul_character,
116 Arg->getSourceRange());
117 break;
118 }
119 }
120
Anders Carlsson3e9b43b2007-08-17 15:44:17 +0000121 return false;
Chris Lattner2e64c072007-08-10 20:18:51 +0000122}
123
124/// CheckPrintfArguments - Check calls to printf (and similar functions) for
Ted Kremenek081ed872007-08-14 17:39:48 +0000125/// correct use of format strings.
126///
127/// HasVAListArg - A predicate indicating whether the printf-like
128/// function is passed an explicit va_arg argument (e.g., vprintf)
129///
130/// format_idx - The index into Args for the format string.
131///
132/// Improper format strings to functions in the printf family can be
133/// the source of bizarre bugs and very serious security holes. A
134/// good source of information is available in the following paper
135/// (which includes additional references):
Chris Lattner2e64c072007-08-10 20:18:51 +0000136///
137/// FormatGuard: Automatic Protection From printf Format String
138/// Vulnerabilities, Proceedings of the 10th USENIX Security Symposium, 2001.
Ted Kremenek081ed872007-08-14 17:39:48 +0000139///
140/// Functionality implemented:
141///
142/// We can statically check the following properties for string
143/// literal format strings for non v.*printf functions (where the
144/// arguments are passed directly):
145//
146/// (1) Are the number of format conversions equal to the number of
147/// data arguments?
148///
149/// (2) Does each format conversion correctly match the type of the
150/// corresponding data argument? (TODO)
151///
152/// Moreover, for all printf functions we can:
153///
154/// (3) Check for a missing format string (when not caught by type checking).
155///
156/// (4) Check for no-operation flags; e.g. using "#" with format
157/// conversion 'c' (TODO)
158///
159/// (5) Check the use of '%n', a major source of security holes.
160///
161/// (6) Check for malformed format conversions that don't specify anything.
162///
163/// (7) Check for empty format strings. e.g: printf("");
164///
165/// (8) Check that the format string is a wide literal.
166///
167/// All of these checks can be done by parsing the format string.
168///
169/// For now, we ONLY do (1), (3), (5), (6), (7), and (8).
Chris Lattner2e64c072007-08-10 20:18:51 +0000170void
Ted Kremenek081ed872007-08-14 17:39:48 +0000171Sema::CheckPrintfArguments(Expr *Fn,
172 SourceLocation LParenLoc, SourceLocation RParenLoc,
173 bool HasVAListArg, FunctionDecl *FDecl,
Ted Kremenek30596542007-08-10 21:21:05 +0000174 unsigned format_idx, Expr** Args,
175 unsigned NumArgsInCall) {
Ted Kremenek081ed872007-08-14 17:39:48 +0000176 // CHECK: printf-like function is called with no format string.
177 if (format_idx >= NumArgsInCall) {
178 Diag(RParenLoc, diag::warn_printf_missing_format_string,
179 Fn->getSourceRange());
180 return;
181 }
182
Chris Lattner2e64c072007-08-10 20:18:51 +0000183 // CHECK: format string is not a string literal.
184 //
Ted Kremenek081ed872007-08-14 17:39:48 +0000185 // Dynamically generated format strings are difficult to
186 // automatically vet at compile time. Requiring that format strings
187 // are string literals: (1) permits the checking of format strings by
188 // the compiler and thereby (2) can practically remove the source of
189 // many format string exploits.
Chris Lattner2e64c072007-08-10 20:18:51 +0000190 StringLiteral *FExpr = dyn_cast<StringLiteral>(Args[format_idx]);
191
Ted Kremenek081ed872007-08-14 17:39:48 +0000192 if (FExpr == NULL) {
193 Diag(Args[format_idx]->getLocStart(),
194 diag::warn_printf_not_string_constant, Fn->getSourceRange());
195 return;
196 }
197
198 // CHECK: is the format string a wide literal?
199 if (FExpr->isWide()) {
200 Diag(Args[format_idx]->getLocStart(),
201 diag::warn_printf_format_string_is_wide_literal,
202 Fn->getSourceRange());
203 return;
204 }
205
206 // Str - The format string. NOTE: this is NOT null-terminated!
207 const char * const Str = FExpr->getStrData();
208
209 // CHECK: empty format string?
210 const unsigned StrLen = FExpr->getByteLength();
211
212 if (StrLen == 0) {
213 Diag(Args[format_idx]->getLocStart(),
214 diag::warn_printf_empty_format_string, Fn->getSourceRange());
215 return;
216 }
217
218 // We process the format string using a binary state machine. The
219 // current state is stored in CurrentState.
220 enum {
221 state_OrdChr,
222 state_Conversion
223 } CurrentState = state_OrdChr;
224
225 // numConversions - The number of conversions seen so far. This is
226 // incremented as we traverse the format string.
227 unsigned numConversions = 0;
228
229 // numDataArgs - The number of data arguments after the format
230 // string. This can only be determined for non vprintf-like
231 // functions. For those functions, this value is 1 (the sole
232 // va_arg argument).
233 unsigned numDataArgs = NumArgsInCall-(format_idx+1);
234
235 // Inspect the format string.
236 unsigned StrIdx = 0;
237
238 // LastConversionIdx - Index within the format string where we last saw
239 // a '%' character that starts a new format conversion.
240 unsigned LastConversionIdx = 0;
241
242 for ( ; StrIdx < StrLen ; ++StrIdx ) {
243
244 // Is the number of detected conversion conversions greater than
245 // the number of matching data arguments? If so, stop.
246 if (!HasVAListArg && numConversions > numDataArgs) break;
247
248 // Handle "\0"
249 if(Str[StrIdx] == '\0' ) {
250 // The string returned by getStrData() is not null-terminated,
251 // so the presence of a null character is likely an error.
252
253 SourceLocation Loc =
254 PP.AdvanceToTokenCharacter(Args[format_idx]->getLocStart(),StrIdx+1);
255
256 Diag(Loc, diag::warn_printf_format_string_contains_null_char,
257 Fn->getSourceRange());
258
259 return;
260 }
261
262 // Ordinary characters (not processing a format conversion).
263 if (CurrentState == state_OrdChr) {
264 if (Str[StrIdx] == '%') {
265 CurrentState = state_Conversion;
266 LastConversionIdx = StrIdx;
267 }
268 continue;
269 }
270
271 // Seen '%'. Now processing a format conversion.
272 switch (Str[StrIdx]) {
273 // Characters which can terminate a format conversion
274 // (e.g. "%d"). Characters that specify length modifiers or
275 // other flags are handled by the default case below.
276 //
277 // TODO: additional checks will go into the following cases.
278 case 'i':
279 case 'd':
280 case 'o':
281 case 'u':
282 case 'x':
283 case 'X':
284 case 'D':
285 case 'O':
286 case 'U':
287 case 'e':
288 case 'E':
289 case 'f':
290 case 'F':
291 case 'g':
292 case 'G':
293 case 'a':
294 case 'A':
295 case 'c':
296 case 'C':
297 case 'S':
298 case 's':
299 case 'P':
300 ++numConversions;
301 CurrentState = state_OrdChr;
302 break;
303
304 // CHECK: Are we using "%n"? Issue a warning.
305 case 'n': {
306 ++numConversions;
307 CurrentState = state_OrdChr;
308 SourceLocation Loc =
309 PP.AdvanceToTokenCharacter(Args[format_idx]->getLocStart(),
310 LastConversionIdx+1);
311
312 Diag(Loc, diag::warn_printf_write_back, Fn->getSourceRange());
313 break;
314 }
315
316 // Handle "%%"
317 case '%':
318 // Sanity check: Was the first "%" character the previous one?
319 // If not, we will assume that we have a malformed format
320 // conversion, and that the current "%" character is the start
321 // of a new conversion.
322 if (StrIdx - LastConversionIdx == 1)
323 CurrentState = state_OrdChr;
324 else {
325 // Issue a warning: invalid format conversion.
326 SourceLocation Loc =
327 PP.AdvanceToTokenCharacter(Args[format_idx]->getLocStart(),
328 LastConversionIdx+1);
329
330 Diag(Loc, diag::warn_printf_invalid_conversion,
331 std::string(Str+LastConversionIdx, Str+StrIdx),
332 Fn->getSourceRange());
333
334 // This conversion is broken. Advance to the next format
335 // conversion.
336 LastConversionIdx = StrIdx;
337 ++numConversions;
338 }
339
340 break;
341
342 default:
343 // This case catches all other characters: flags, widths, etc.
344 // We should eventually process those as well.
345 break;
346 }
347 }
348
349 if (CurrentState == state_Conversion) {
350 // Issue a warning: invalid format conversion.
351 SourceLocation Loc =
352 PP.AdvanceToTokenCharacter(Args[format_idx]->getLocStart(),
353 LastConversionIdx+1);
354
355 Diag(Loc, diag::warn_printf_invalid_conversion,
Ted Kremenek45925ab2007-08-17 16:46:58 +0000356 std::string(Str+LastConversionIdx, Str+StrIdx),
Ted Kremenek081ed872007-08-14 17:39:48 +0000357 Fn->getSourceRange());
358 return;
359 }
360
361 if (!HasVAListArg) {
362 // CHECK: Does the number of format conversions exceed the number
363 // of data arguments?
364 if (numConversions > numDataArgs) {
365 SourceLocation Loc =
366 PP.AdvanceToTokenCharacter(Args[format_idx]->getLocStart(),
367 LastConversionIdx);
368
369 Diag(Loc, diag::warn_printf_insufficient_data_args,
370 Fn->getSourceRange());
371 }
372 // CHECK: Does the number of data arguments exceed the number of
373 // format conversions in the format string?
374 else if (numConversions < numDataArgs)
375 Diag(Args[format_idx+numConversions+1]->getLocStart(),
376 diag::warn_printf_too_many_data_args, Fn->getSourceRange());
377 }
378}
Ted Kremenek45925ab2007-08-17 16:46:58 +0000379
380//===--- CHECK: Return Address of Stack Variable --------------------------===//
381
382static DeclRefExpr* EvalVal(Expr *E);
383static DeclRefExpr* EvalAddr(Expr* E);
384
385/// CheckReturnStackAddr - Check if a return statement returns the address
386/// of a stack variable.
387void
388Sema::CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
389 SourceLocation ReturnLoc) {
390
391 // Perform checking for returned stack addresses.
392 if (lhsType->isPointerType()) {
393 if (DeclRefExpr *DR = EvalAddr(RetValExp))
394 Diag(DR->getLocStart(), diag::warn_ret_stack_addr,
395 DR->getDecl()->getIdentifier()->getName(),
396 RetValExp->getSourceRange());
397 }
398 // Perform checking for stack values returned by reference.
399 else if (lhsType->isReferenceType()) {
400 if (DeclRefExpr *DR = EvalVal(RetValExp))
401 Diag(DR->getLocStart(), diag::warn_ret_stack_ref,
402 DR->getDecl()->getIdentifier()->getName(),
403 RetValExp->getSourceRange());
404 }
405}
406
407/// EvalAddr - EvalAddr and EvalVal are mutually recursive functions that
408/// check if the expression in a return statement evaluates to an address
409/// to a location on the stack. The recursion is used to traverse the
410/// AST of the return expression, with recursion backtracking when we
411/// encounter a subexpression that (1) clearly does not lead to the address
412/// of a stack variable or (2) is something we cannot determine leads to
413/// the address of a stack variable based on such local checking.
414///
415/// EvalAddr processes expressions that are pointers, and EvalVal handles
416/// expressions that are rvalues or variable references.
417/// At the base case of the recursion is a check for a DeclRefExpr* in
418/// the refers to a stack variable.
419///
420/// This implementation handles:
421///
422/// * pointer-to-pointer casts
423/// * implicit conversions from array references to pointers
424/// * taking the address of fields
425/// * arbitrary interplay between "&" and "*" operators
426/// * pointer arithmetic from an address of a stack variable
427/// * taking the address of an array element where the array is on the stack
428static DeclRefExpr* EvalAddr(Expr *E) {
429
430 // We should only be called for evaluating pointer expressions.
431 assert (E->getType()->isPointerType() && "EvalAddr only works on pointers");
432
433 // Our "symbolic interpreter" is just a dispatch off the currently
434 // viewed AST node. We then recursively traverse the AST by calling
435 // EvalAddr and EvalVal appropriately.
436 switch (E->getStmtClass()) {
437
438 case Stmt::ParenExprClass:
439 // Ignore parentheses.
440 return EvalAddr(cast<ParenExpr>(E)->getSubExpr());
441
442 case Stmt::UnaryOperatorClass: {
443 // The only unary operator that make sense to handle here
444 // is AddrOf. All others don't make sense as pointers.
445 UnaryOperator *U = cast<UnaryOperator>(E);
446
447 if (U->getOpcode() == UnaryOperator::AddrOf)
448 return EvalVal(U->getSubExpr());
449 else
450 return NULL;
451 }
452
453 case Stmt::BinaryOperatorClass: {
454 // Handle pointer arithmetic. All other binary operators are not valid
455 // in this context.
456 BinaryOperator *B = cast<BinaryOperator>(E);
457 BinaryOperator::Opcode op = B->getOpcode();
458
459 if (op != BinaryOperator::Add && op != BinaryOperator::Sub)
460 return NULL;
461
462 Expr *Base = B->getLHS();
463
464 // Determine which argument is the real pointer base. It could be
465 // the RHS argument instead of the LHS.
466 if (!Base->getType()->isPointerType()) Base = B->getRHS();
467
468 assert (Base->getType()->isPointerType());
469 return EvalAddr(Base);
470 }
471
472 // For conditional operators we need to see if either the LHS or RHS are
473 // valid DeclRefExpr*s. If one of them is valid, we return it.
474 case Stmt::ConditionalOperatorClass: {
475 ConditionalOperator *C = cast<ConditionalOperator>(E);
476
477 if (DeclRefExpr* LHS = EvalAddr(C->getLHS()))
478 return LHS;
479 else
480 return EvalAddr(C->getRHS());
481 }
482
483 // For implicit casts, we need to handle conversions from arrays to
484 // pointer values, and implicit pointer-to-pointer conversions.
485 case Stmt::ImplicitCastExprClass: {
486 ImplicitCastExpr *IE = cast<ImplicitCastExpr>(E);
487 Expr* SubExpr = IE->getSubExpr();
488
489 if (SubExpr->getType()->isPointerType())
490 return EvalAddr(SubExpr);
491 else
492 return EvalVal(SubExpr);
493 }
494
495 // For casts, we handle pointer-to-pointer conversions (which
496 // is essentially a no-op from our mini-interpreter's standpoint).
497 // For other casts we abort.
498 case Stmt::CastExprClass: {
499 CastExpr *C = cast<CastExpr>(E);
500 Expr *SubExpr = C->getSubExpr();
501
502 if (SubExpr->getType()->isPointerType())
503 return EvalAddr(SubExpr);
504 else
505 return NULL;
506 }
507
Ted Kremenek1c1700f2007-08-20 16:18:38 +0000508 // C++ casts. For dynamic casts, static casts, and const casts, we
509 // are always converting from a pointer-to-pointer, so we just blow
510 // through the cast. In the case the dynamic cast doesn't fail
511 // (and return NULL), we take the conservative route and report cases
512 // where we return the address of a stack variable. For Reinterpre
513 case Stmt::CXXCastExprClass: {
514 CXXCastExpr *C = cast<CXXCastExpr>(E);
515
516 if (C->getOpcode() == CXXCastExpr::ReinterpretCast) {
517 Expr *S = C->getSubExpr();
518 if (S->getType()->isPointerType())
519 return EvalAddr(S);
520 else
521 return NULL;
522 }
523 else
524 return EvalAddr(C->getSubExpr());
525 }
Ted Kremenek45925ab2007-08-17 16:46:58 +0000526
527 // Everything else: we simply don't reason about them.
528 default:
529 return NULL;
530 }
531}
532
533
534/// EvalVal - This function is complements EvalAddr in the mutual recursion.
535/// See the comments for EvalAddr for more details.
536static DeclRefExpr* EvalVal(Expr *E) {
537
538 // We should only be called for evaluating non-pointer expressions.
539 assert (!E->getType()->isPointerType() && "EvalVal doesn't work on pointers");
540
541 // Our "symbolic interpreter" is just a dispatch off the currently
542 // viewed AST node. We then recursively traverse the AST by calling
543 // EvalAddr and EvalVal appropriately.
544 switch (E->getStmtClass()) {
545
546 case Stmt::DeclRefExprClass: {
547 // DeclRefExpr: the base case. When we hit a DeclRefExpr we are looking
548 // at code that refers to a variable's name. We check if it has local
549 // storage within the function, and if so, return the expression.
550 DeclRefExpr *DR = cast<DeclRefExpr>(E);
551
552 if (VarDecl *V = dyn_cast<VarDecl>(DR->getDecl()))
553 if(V->hasLocalStorage()) return DR;
554
555 return NULL;
556 }
557
558 case Stmt::ParenExprClass:
559 // Ignore parentheses.
560 return EvalVal(cast<ParenExpr>(E)->getSubExpr());
561
562 case Stmt::UnaryOperatorClass: {
563 // The only unary operator that make sense to handle here
564 // is Deref. All others don't resolve to a "name." This includes
565 // handling all sorts of rvalues passed to a unary operator.
566 UnaryOperator *U = cast<UnaryOperator>(E);
567
568 if (U->getOpcode() == UnaryOperator::Deref)
569 return EvalAddr(U->getSubExpr());
570
571 return NULL;
572 }
573
574 case Stmt::ArraySubscriptExprClass: {
575 // Array subscripts are potential references to data on the stack. We
576 // retrieve the DeclRefExpr* for the array variable if it indeed
577 // has local storage.
Ted Kremenek1c1700f2007-08-20 16:18:38 +0000578 return EvalAddr(cast<ArraySubscriptExpr>(E)->getBase());
Ted Kremenek45925ab2007-08-17 16:46:58 +0000579 }
580
581 case Stmt::ConditionalOperatorClass: {
582 // For conditional operators we need to see if either the LHS or RHS are
583 // non-NULL DeclRefExpr's. If one is non-NULL, we return it.
584 ConditionalOperator *C = cast<ConditionalOperator>(E);
585
586 if (DeclRefExpr *LHS = EvalVal(C->getLHS()))
587 return LHS;
588 else
589 return EvalVal(C->getRHS());
590 }
591
592 // Accesses to members are potential references to data on the stack.
593 case Stmt::MemberExprClass: {
594 MemberExpr *M = cast<MemberExpr>(E);
595
596 // Check for indirect access. We only want direct field accesses.
597 if (!M->isArrow())
598 return EvalVal(M->getBase());
599 else
600 return NULL;
601 }
602
603 // Everything else: we simply don't reason about them.
604 default:
605 return NULL;
606 }
607}