diff --git a/clang/include/clang/Analysis/ProgramPoint.h b/clang/include/clang/Analysis/ProgramPoint.h index a046268cfd7e..5fc1fb651b09 100644 --- a/clang/include/clang/Analysis/ProgramPoint.h +++ b/clang/include/clang/Analysis/ProgramPoint.h @@ -31,14 +31,18 @@ protected: uintptr_t Data; ProgramPoint(const void* Ptr, Kind k) { + setRawData(Ptr, k); + } + + ProgramPoint() : Data(0) {} + + void setRawData(const void* Ptr, Kind k) { assert ((reinterpret_cast(const_cast(Ptr)) & 0x7) == 0 && "Address must have at least an 8-byte alignment."); Data = reinterpret_cast(const_cast(Ptr)) | k; } - ProgramPoint() : Data(0) {} - public: unsigned getKind() const { return Data & 0x7; } void* getRawPtr() const { return reinterpret_cast(Data & ~0x7); } @@ -114,10 +118,8 @@ public: /// This ctor forces the BlockEdge to be constructed using an explicitly /// allocated pair object that is stored in the CFG. This is usually /// used to construct edges representing jumps using computed gotos. - BlockEdge(CFG& cfg, const CFGBlock* B1, const CFGBlock* B2, bool) { - Data = reinterpret_cast(cfg.getBlockEdgeImpl(B1, B2)) - | BlockEdgeAuxKind; - } + BlockEdge(CFG& cfg, const CFGBlock* B1, const CFGBlock* B2, bool) + : ProgramPoint(cfg.getBlockEdgeImpl(B1, B2), BlockEdgeAuxKind) {} CFGBlock* getSrc() const; diff --git a/clang/lib/Analysis/ProgramPoint.cpp b/clang/lib/Analysis/ProgramPoint.cpp index c089e4869880..d95680ff3892 100644 --- a/clang/lib/Analysis/ProgramPoint.cpp +++ b/clang/lib/Analysis/ProgramPoint.cpp @@ -19,15 +19,14 @@ using namespace clang; BlockEdge::BlockEdge(CFG& cfg, const CFGBlock* B1, const CFGBlock* B2) { if (B1->succ_size() == 1) { assert (*(B1->succ_begin()) == B2); - Data = reinterpret_cast(B1) | BlockEdgeSrcKind; + setRawData(B1, BlockEdgeSrcKind); } else if (B2->pred_size() == 1) { assert (*(B2->pred_begin()) == B1); - Data = reinterpret_cast(B2) | BlockEdgeDstKind; + setRawData(B2, BlockEdgeDstKind); } else - Data = reinterpret_cast(cfg.getBlockEdgeImpl(B1,B2)) - | BlockEdgeAuxKind; + setRawData(cfg.getBlockEdgeImpl(B1,B2), BlockEdgeAuxKind); } CFGBlock* BlockEdge::getSrc() const {