llvm.org GIT mirror llvm / a76b756
[demangler] Fix a bug in r328464 found by oss-fuzz. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328507 91177308-0d34-0410-b5e6-96231b3b80d8 Erik Pilkington 1 year, 7 months ago
1 changed file(s) with 27 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
10871087 size_t Index;
10881088 Node *Ref = nullptr;
10891089
1090 // If we're currently printing this node. It is possible (though invalid) for
1091 // a forward template reference to refer to itself via a substitution. This
1092 // creates a cyclic AST, which will stack overflow printing. To fix this, bail
1093 // out if more than one print* function is active.
1094 mutable bool Printing = false;
1095
10901096 ForwardTemplateReference(size_t Index_)
10911097 : Node(KForwardTemplateReference, Cache::Unknown, Cache::Unknown,
10921098 Cache::Unknown),
10931099 Index(Index_) {}
10941100
10951101 bool hasRHSComponentSlow(OutputStream &S) const override {
1102 if (Printing)
1103 return false;
1104 SwapAndRestore SavePrinting(Printing, true);
10961105 return Ref->hasRHSComponent(S);
10971106 }
10981107 bool hasArraySlow(OutputStream &S) const override {
1108 if (Printing)
1109 return false;
1110 SwapAndRestore SavePrinting(Printing, true);
10991111 return Ref->hasArray(S);
11001112 }
11011113 bool hasFunctionSlow(OutputStream &S) const override {
1114 if (Printing)
1115 return false;
1116 SwapAndRestore SavePrinting(Printing, true);
11021117 return Ref->hasFunction(S);
11031118 }
11041119
1105 void printLeft(OutputStream &S) const override { Ref->printLeft(S); }
1106 void printRight(OutputStream &S) const override { Ref->printRight(S); }
1120 void printLeft(OutputStream &S) const override {
1121 if (Printing)
1122 return;
1123 SwapAndRestore SavePrinting(Printing, true);
1124 Ref->printLeft(S);
1125 }
1126 void printRight(OutputStream &S) const override {
1127 if (Printing)
1128 return;
1129 SwapAndRestore SavePrinting(Printing, true);
1130 Ref->printRight(S);
1131 }
11071132 };
11081133
11091134 class NameWithTemplateArgs final : public Node {