[PATCH] D58998: Add declarations of explicit specializations and make primary template deleted
Thomas Köppe via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 5 14:29:55 PST 2019
tkoeppe created this revision.
tkoeppe added reviewers: chandlerc, bkramer.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Currently, code that uses the specialization in question will accidentally and erroneously specialize the primary template. This only "works" by accident; the program is ill-formed NDR.
We also define the primary template as deleted, so as to avoid future accidental misuse.
(Found with -Wundefined-func-template.)
Repository:
rL LLVM
https://reviews.llvm.org/D58998
Files:
lib/Target/Hexagon/RDFGraph.h
lib/Target/Hexagon/RDFLiveness.h
Index: lib/Target/Hexagon/RDFLiveness.h
===================================================================
--- lib/Target/Hexagon/RDFLiveness.h
+++ lib/Target/Hexagon/RDFLiveness.h
@@ -142,6 +142,10 @@
unsigned Nest, unsigned MaxNest);
};
+ // Explicit specialization in RDFLiveness.cpp; primary template in RDFGraph.h.
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<Liveness::RefMap> &P);
+
} // end namespace rdf
} // end namespace llvm
Index: lib/Target/Hexagon/RDFGraph.h
===================================================================
--- lib/Target/Hexagon/RDFGraph.h
+++ lib/Target/Hexagon/RDFGraph.h
@@ -924,10 +924,6 @@
return MM;
}
- template <typename T> struct Print;
- template <typename T>
- raw_ostream &operator<< (raw_ostream &OS, const Print<T> &P);
-
template <typename T>
struct Print {
Print(const T &x, const DataFlowGraph &g) : Obj(x), G(g) {}
@@ -942,6 +938,44 @@
: Print<NodeAddr<T>>(x, g) {}
};
+ template <typename T>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<T> &P) = delete;
+
+ // Explicit specializations in RDFGraph.cpp. There is an additional explicit
+ // specialization in RDFLiveness.cpp; it is declared in RDFLiveness.h.
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<RegisterRef> &P);
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<NodeId> &P);
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<NodeAddr<DefNode*>> &P);
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<NodeAddr<UseNode*>> &P);
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<NodeAddr<PhiUseNode*>> &P);
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<NodeAddr<RefNode*>> &P);
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<NodeList> &P);
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<NodeSet> &P);
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<NodeAddr<PhiNode*>> &P);
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<NodeAddr<StmtNode*>> &P);
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<NodeAddr<InstrNode*>> &P);
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<NodeAddr<BlockNode*>> &P);
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<NodeAddr<FuncNode*>> &P);
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<RegisterSet> &P);
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<RegisterAggr> &P);
+ template<>
+ raw_ostream &operator<< (raw_ostream &OS, const Print<DataFlowGraph::DefStack> &P);
+
} // end namespace rdf
} // end namespace llvm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58998.189400.patch
Type: text/x-patch
Size: 2810 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190305/78a2d7a0/attachment.bin>
More information about the llvm-commits
mailing list