[cfe-commits] r52501 - in /cfe/trunk: lib/Analysis/GRExprEngine.cpp test/Analysis/complex.c
Ted Kremenek
kremenek at apple.com
Thu Jun 19 10:55:39 PDT 2008
Author: kremenek
Date: Thu Jun 19 12:55:38 2008
New Revision: 52501
URL: http://llvm.org/viewvc/llvm-project?rev=52501&view=rev
Log:
Introduce initial transfer function support for __imag__ and __real__. We don't
have complex RValues yet, so this logic is only fully implemented when __imag__
and __real__ are used on non-complex types.
Added:
cfe/trunk/test/Analysis/complex.c
Modified:
cfe/trunk/lib/Analysis/GRExprEngine.cpp
Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=52501&r1=52500&r2=52501&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Thu Jun 19 12:55:38 2008
@@ -1596,7 +1596,7 @@
default:
break;
-
+
case UnaryOperator::Deref: {
Expr* Ex = U->getSubExpr()->IgnoreParens();
@@ -1616,10 +1616,57 @@
return;
}
-
+ case UnaryOperator::Real: {
+
+ Expr* Ex = U->getSubExpr()->IgnoreParens();
+ NodeSet Tmp;
+ Visit(Ex, Pred, Tmp);
+
+ for (NodeSet::iterator I=Tmp.begin(), E=Tmp.end(); I!=E; ++I) {
+
+ // FIXME: We don't have complex RValues yet.
+ if (Ex->getType()->isAnyComplexType()) {
+ // Just report "Unknown."
+ Dst.Add(*I);
+ continue;
+ }
+
+ // For all other types, UnaryOperator::Real is an identity operation.
+ assert (U->getType() == Ex->getType());
+ ValueState* St = GetState(*I);
+ MakeNode(Dst, U, *I, SetRVal(St, U, GetRVal(St, Ex)));
+ }
+
+ return;
+ }
+
+ case UnaryOperator::Imag: {
+
+ Expr* Ex = U->getSubExpr()->IgnoreParens();
+ NodeSet Tmp;
+ Visit(Ex, Pred, Tmp);
+
+ for (NodeSet::iterator I=Tmp.begin(), E=Tmp.end(); I!=E; ++I) {
+ // FIXME: We don't have complex RValues yet.
+ if (Ex->getType()->isAnyComplexType()) {
+ // Just report "Unknown."
+ Dst.Add(*I);
+ continue;
+ }
+
+ // For all other types, UnaryOperator::Float returns 0.
+ assert (Ex->getType()->isIntegerType());
+ ValueState* St = GetState(*I);
+ RVal X = NonLVal::MakeVal(BasicVals, 0, Ex->getType());
+ MakeNode(Dst, U, *I, SetRVal(St, U, X));
+ }
+
+ return;
+ }
+
+ // FIXME: Just report "Unknown" for OffsetOf.
case UnaryOperator::OffsetOf:
- // FIXME: Just report "Unknown" known for OffsetOf.
Dst.Add(Pred);
return;
Added: cfe/trunk/test/Analysis/complex.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/complex.c?rev=52501&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/complex.c (added)
+++ cfe/trunk/test/Analysis/complex.c Thu Jun 19 12:55:38 2008
@@ -0,0 +1,17 @@
+// RUN: clang -checker-simple -verify %s
+
+#include <stdlib.h>
+
+int f1(int * p) {
+
+ // This branch should be infeasible
+ // because __imag__ p is 0.
+ if (!p && __imag__ (intptr_t) p)
+ *p = 1; // no-warning
+
+ // If p != 0 then this branch is feasible; otherwise it is not.
+ if (__real__ (intptr_t) p)
+ *p = 1; // no-warning
+
+ *p = 2; // expected-warning{{Dereference of null pointer}}
+}
More information about the cfe-commits
mailing list