#include <sstream>
#endif
+// SaveAndRestore - A utility class that uses RIIA to save and restore
+// the value of a variable.
+template<typename T>
+struct VISIBILITY_HIDDEN SaveAndRestore {
+ SaveAndRestore(T& x) : X(x), old_value(x) {}
+ ~SaveAndRestore() { X = old_value; }
+ T get() { return old_value; }
+
+ T& X;
+ T old_value;
+};
+
using namespace clang;
using llvm::dyn_cast;
using llvm::cast;
}
continue;
- }
+ }
+
+ // Check for the "noreturn" attribute.
+
+ SaveAndRestore<bool> OldSink(Builder->BuildSinks);
+
+ if (isa<lval::FuncVal>(L))
+ if (cast<lval::FuncVal>(L).getDecl()->getAttr<NoReturnAttr>()) {
+ for (NodeSet::iterator I=Dst.begin(), E=Dst.end(); I != E; ++I ) {
+
+ NodeTy* N = *I;
+
+ if (!N->isSink())
+ N->markAsSink();
+ }
+
+ Builder->BuildSinks = true;
+ }
+
+ // Evaluate the call.
+
bool invalidateArgs = false;
if (isa<LVal>(V))
St = SetRVal(St, cast<LVal>(V), UnknownVal());
- }
+ }
+
+ Nodify(Dst, CE, *DI, St);
}
else {
if (Dst.size() == size)
Nodify(Dst, CE, *DI, St);
}
-
- // Check for the "noreturn" attribute.
-
- if (isa<lval::FuncVal>(L))
- if (cast<lval::FuncVal>(L).getDecl()->getAttr<NoReturnAttr>()) {
-
- NodeTy* N = Builder->generateNode(CE, St, *DI);
-
- if (N) {
- N->markAsSink();
- NoReturnCalls.insert(N);
- }
-
- continue;
- }
-
- Nodify(Dst, CE, *DI, St);
}
}
GRStmtNodeBuilderImpl& NB;
public:
- GRStmtNodeBuilder(GRStmtNodeBuilderImpl& nb) : NB(nb) {}
+ GRStmtNodeBuilder(GRStmtNodeBuilderImpl& nb) : NB(nb), BuildSinks(false) {}
NodeTy* getLastNode() const {
return static_cast<NodeTy*>(NB.getLastNode());
}
NodeTy* N = generateNode(S, St, Pred);
- Dst.Add(N);
+
+ if (N && BuildSinks)
+ N->markAsSink();
+ else
+ Dst.Add(N);
+
return N;
}
+ bool BuildSinks;
};
class GRBranchNodeBuilderImpl {