[cfe-commits] r119960 - in /cfe/trunk: lib/Analysis/CFG.cpp test/Analysis/misc-ps-region-store.cpp

Zhanyong Wan wan at google.com
Mon Nov 22 00:45:56 PST 2010


Author: wan
Date: Mon Nov 22 02:45:56 2010
New Revision: 119960

URL: http://llvm.org/viewvc/llvm-project?rev=119960&view=rev
Log:
Fix PR8419.  Reviewed by kremenek and xuzhongxing.

Modified:
    cfe/trunk/lib/Analysis/CFG.cpp
    cfe/trunk/test/Analysis/misc-ps-region-store.cpp

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=119960&r1=119959&r2=119960&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Mon Nov 22 02:45:56 2010
@@ -296,6 +296,7 @@
   CFGBlock *VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E, AddStmtChoice asc);
   CFGBlock *VisitStmtExpr(StmtExpr *S, AddStmtChoice asc);
   CFGBlock *VisitSwitchStmt(SwitchStmt *S);
+  CFGBlock *VisitUnaryOperator(UnaryOperator *U, AddStmtChoice asc);
   CFGBlock *VisitWhileStmt(WhileStmt *W);
 
   CFGBlock *Visit(Stmt *S, AddStmtChoice asc = AddStmtChoice::NotAlwaysAdd);
@@ -886,6 +887,9 @@
     case Stmt::SwitchStmtClass:
       return VisitSwitchStmt(cast<SwitchStmt>(S));
 
+    case Stmt::UnaryOperatorClass:
+      return VisitUnaryOperator(cast<UnaryOperator>(S), asc);
+
     case Stmt::WhileStmtClass:
       return VisitWhileStmt(cast<WhileStmt>(S));
   }
@@ -922,6 +926,19 @@
   return Block;
 }
 
+CFGBlock *CFGBuilder::VisitUnaryOperator(UnaryOperator *U,
+					 AddStmtChoice asc) {
+  if (asc.alwaysAdd()) {
+    autoCreateBlock();
+    AppendStmt(Block, U, asc);
+  }
+
+  bool asLVal = U->isIncrementDecrementOp();
+  return Visit(U->getSubExpr(),
+	       asLVal ? AddStmtChoice::AsLValueNotAlwaysAdd :
+	                AddStmtChoice::NotAlwaysAdd);
+}
+
 CFGBlock *CFGBuilder::VisitBinaryOperator(BinaryOperator *B,
                                           AddStmtChoice asc) {
   if (B->isLogicalOp()) { // && or ||

Modified: cfe/trunk/test/Analysis/misc-ps-region-store.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps-region-store.cpp?rev=119960&r1=119959&r2=119960&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps-region-store.cpp (original)
+++ cfe/trunk/test/Analysis/misc-ps-region-store.cpp Mon Nov 22 02:45:56 2010
@@ -159,6 +159,25 @@
   for (; ; x++) { }
 }
 
+// PR8419 -- this used to crash.
+
+class String8419 {
+ public:
+  char& get(int n);
+  char& operator[](int n);
+};
+
+char& get8419();
+
+void Test8419() {
+  String8419 s;
+  ++(s.get(0));
+  get8419()--;  // used to crash
+  --s[0];       // used to crash
+  s[0] &= 1;    // used to crash
+  s[0]++;       // used to crash
+}
+
 // PR8426 -- this used to crash.
 
 void Use(void* to);





More information about the cfe-commits mailing list