mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
[IR/Analysis] Defend against getting slightly wrong template arguments
passed into CRTP base classes. This can sometimes happen and not cause an immediate failure when the derived class is, itself, a template. You can end up essentially calling methods on the wrong derived type but a type where many things will appear to "work". To fail fast and with a clear error message we can use a static_assert, but we have to stash that static_assert inside a method body or nested type that won't need to be completed while building the base class. I've tried to pick a reasonably small number of places that seemed like reliably places for this to be instantiated. llvm-svn: 294272
This commit is contained in:
parent
c69a2c11a3
commit
cefe125ec4
@ -196,7 +196,10 @@ class PtrUseVisitor : protected InstVisitor<DerivedT>,
|
||||
typedef InstVisitor<DerivedT> Base;
|
||||
|
||||
public:
|
||||
PtrUseVisitor(const DataLayout &DL) : PtrUseVisitorBase(DL) {}
|
||||
PtrUseVisitor(const DataLayout &DL) : PtrUseVisitorBase(DL) {
|
||||
static_assert(std::is_base_of<PtrUseVisitor, DerivedT>::value,
|
||||
"Must pass the derived type to this template!");
|
||||
}
|
||||
|
||||
/// \brief Recursively visit the uses of the given pointer.
|
||||
/// \returns An info struct about the pointer. See \c PtrInfo for details.
|
||||
|
@ -116,6 +116,9 @@ public:
|
||||
// visit - Finally, code to visit an instruction...
|
||||
//
|
||||
RetTy visit(Instruction &I) {
|
||||
static_assert(std::is_base_of<InstVisitor, SubClass>::value,
|
||||
"Must pass the derived type to this template!");
|
||||
|
||||
switch (I.getOpcode()) {
|
||||
default: llvm_unreachable("Unknown instruction type encountered!");
|
||||
// Build the switch statement using the Instruction.def file...
|
||||
|
Loading…
Reference in New Issue
Block a user