summaryrefslogtreecommitdiffstats
path: root/clang/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-08-20 16:18:38 +0000
committerTed Kremenek <kremenek@apple.com>2007-08-20 16:18:38 +0000
commitc81614d5d147efc770ffb34f81650f3ac1cd2edf (patch)
tree538176a05f970d172e147c69cd76a7a143d49629 /clang/Sema/SemaChecking.cpp
parent9c3d20d82372a5392c2fe344f75ac5c29f3c9393 (diff)
downloadbcm5719-llvm-c81614d5d147efc770ffb34f81650f3ac1cd2edf.tar.gz
bcm5719-llvm-c81614d5d147efc770ffb34f81650f3ac1cd2edf.zip
Modified ArraySubscriptExpr to have accessors getLHS and getRHS in addition
to getBase and getIdx. getBase and getIdx now return a "normalized" view of the expression (e.g., always "A[4]" instead of possibly "4[A]"). getLHS and getRHS return the expressions with syntactic fidelity to the original source code. Also modified client code of ArraySubscriptExpr, including the AST dumper and pretty printer, the return-stack value checker, and the LLVM code generator. llvm-svn: 41180
Diffstat (limited to 'clang/Sema/SemaChecking.cpp')
-rw-r--r--clang/Sema/SemaChecking.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/clang/Sema/SemaChecking.cpp b/clang/Sema/SemaChecking.cpp
index d699e1bcf81..a1deb3d256d 100644
--- a/clang/Sema/SemaChecking.cpp
+++ b/clang/Sema/SemaChecking.cpp
@@ -16,6 +16,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/LiteralSupport.h"
#include "clang/Basic/SourceManager.h"
@@ -499,9 +500,24 @@ static DeclRefExpr* EvalAddr(Expr *E) {
return NULL;
}
- // TODO: C++ casts.
- case Stmt::CXXCastExprClass:
- return NULL;
+ // C++ casts. For dynamic casts, static casts, and const casts, we
+ // are always converting from a pointer-to-pointer, so we just blow
+ // through the cast. In the case the dynamic cast doesn't fail
+ // (and return NULL), we take the conservative route and report cases
+ // where we return the address of a stack variable. For Reinterpre
+ case Stmt::CXXCastExprClass: {
+ CXXCastExpr *C = cast<CXXCastExpr>(E);
+
+ if (C->getOpcode() == CXXCastExpr::ReinterpretCast) {
+ Expr *S = C->getSubExpr();
+ if (S->getType()->isPointerType())
+ return EvalAddr(S);
+ else
+ return NULL;
+ }
+ else
+ return EvalAddr(C->getSubExpr());
+ }
// Everything else: we simply don't reason about them.
default:
@@ -554,18 +570,7 @@ static DeclRefExpr* EvalVal(Expr *E) {
// Array subscripts are potential references to data on the stack. We
// retrieve the DeclRefExpr* for the array variable if it indeed
// has local storage.
- ArraySubscriptExpr *A = cast<ArraySubscriptExpr>(E);
-
- // The array access could be written A[4] or 4[A] (both are equivalent).
- // In the second case, the "base" is the offset and the "Idx" is
- // the base. We test for this case by seeing if the Base expression
- // has a pointer type.
- Expr* Base = A->getBase();
-
- if (Base->getType()->isPointerType())
- return EvalAddr(Base);
- else
- return EvalAddr(A->getIdx());
+ return EvalAddr(cast<ArraySubscriptExpr>(E)->getBase());
}
case Stmt::ConditionalOperatorClass: {
OpenPOWER on IntegriCloud