summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Demangle/ItaniumDemangle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Demangle/ItaniumDemangle.cpp')
-rw-r--r--llvm/lib/Demangle/ItaniumDemangle.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/llvm/lib/Demangle/ItaniumDemangle.cpp b/llvm/lib/Demangle/ItaniumDemangle.cpp
index c80b1c9ef2b..3f610a41422 100644
--- a/llvm/lib/Demangle/ItaniumDemangle.cpp
+++ b/llvm/lib/Demangle/ItaniumDemangle.cpp
@@ -1088,23 +1088,48 @@ struct ForwardTemplateReference : Node {
size_t Index;
Node *Ref = nullptr;
+ // If we're currently printing this node. It is possible (though invalid) for
+ // a forward template reference to refer to itself via a substitution. This
+ // creates a cyclic AST, which will stack overflow printing. To fix this, bail
+ // out if more than one print* function is active.
+ mutable bool Printing = false;
+
ForwardTemplateReference(size_t Index_)
: Node(KForwardTemplateReference, Cache::Unknown, Cache::Unknown,
Cache::Unknown),
Index(Index_) {}
bool hasRHSComponentSlow(OutputStream &S) const override {
+ if (Printing)
+ return false;
+ SwapAndRestore<bool> SavePrinting(Printing, true);
return Ref->hasRHSComponent(S);
}
bool hasArraySlow(OutputStream &S) const override {
+ if (Printing)
+ return false;
+ SwapAndRestore<bool> SavePrinting(Printing, true);
return Ref->hasArray(S);
}
bool hasFunctionSlow(OutputStream &S) const override {
+ if (Printing)
+ return false;
+ SwapAndRestore<bool> SavePrinting(Printing, true);
return Ref->hasFunction(S);
}
- void printLeft(OutputStream &S) const override { Ref->printLeft(S); }
- void printRight(OutputStream &S) const override { Ref->printRight(S); }
+ void printLeft(OutputStream &S) const override {
+ if (Printing)
+ return;
+ SwapAndRestore<bool> SavePrinting(Printing, true);
+ Ref->printLeft(S);
+ }
+ void printRight(OutputStream &S) const override {
+ if (Printing)
+ return;
+ SwapAndRestore<bool> SavePrinting(Printing, true);
+ Ref->printRight(S);
+ }
};
class NameWithTemplateArgs final : public Node {
OpenPOWER on IntegriCloud