Use a real union for IdentifyingPassPtr.

This avoids a nasty const correctness issue (AnalysisIDs are const, Pass* isn't).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179213 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2013-04-10 20:50:44 +00:00
parent bccd635fba
commit 8f5836510a

View File

@ -50,24 +50,26 @@ class PassConfigImpl;
///
/// AnalysisID is sadly char*, so PointerIntPair won't work.
class IdentifyingPassPtr {
void *P;
union {
AnalysisID ID;
Pass *P;
};
bool IsInstance;
public:
IdentifyingPassPtr(): P(0), IsInstance(false) {}
IdentifyingPassPtr(AnalysisID IDPtr): P((void*)IDPtr), IsInstance(false) {}
IdentifyingPassPtr(Pass *InstancePtr)
: P((void*)InstancePtr), IsInstance(true) {}
IdentifyingPassPtr() : P(0), IsInstance(false) {}
IdentifyingPassPtr(AnalysisID IDPtr) : ID(IDPtr), IsInstance(false) {}
IdentifyingPassPtr(Pass *InstancePtr) : P(InstancePtr), IsInstance(true) {}
bool isValid() const { return P; }
bool isInstance() const { return IsInstance; }
AnalysisID getID() const {
assert(!IsInstance && "Not a Pass ID");
return (AnalysisID)P;
return ID;
}
Pass *getInstance() const {
assert(IsInstance && "Not a Pass Instance");
return (Pass *)P;
return P;
}
};