mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 321856: Stack overflow for recursive function type.
This commit is contained in:
parent
24639ea848
commit
3805136b3f
4 changed files with 36 additions and 20 deletions
|
@ -7127,6 +7127,15 @@ public class AST2Tests extends AST2BaseTest {
|
|||
parseAndCheckBindings(code, ParserLanguage.C, false, true);
|
||||
}
|
||||
|
||||
// typeof(b(1)) b(int);
|
||||
public void testRecursiveFunctionType_321856() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(code, false);
|
||||
IFunction f= bh.assertNonProblem("b(1)", 1);
|
||||
f= bh.assertNonProblem("b(int)", 1);
|
||||
f.getType();
|
||||
}
|
||||
|
||||
public void testDeepBinaryExpression_294969() throws Exception {
|
||||
sValidateCopy= false;
|
||||
StringBuilder buf= new StringBuilder("void f() {0");
|
||||
|
|
|
@ -13,12 +13,13 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType;
|
||||
|
||||
/**
|
||||
* Models functions used without declarations.
|
||||
|
@ -38,9 +39,13 @@ public class CExternalFunction extends CFunction implements ICExternalBinding {
|
|||
|
||||
@Override
|
||||
public IFunctionType getType() {
|
||||
IFunctionType t = super.getType();
|
||||
if (t == null) {
|
||||
type = new CFunctionType(VOID_TYPE, IType.EMPTY_TYPE_ARRAY);
|
||||
if (type == null) {
|
||||
// Bug 321856: Prevent recursions
|
||||
type = new CPPFunctionType(VOID_TYPE, IType.EMPTY_TYPE_ARRAY);
|
||||
IFunctionType computedType = createType();
|
||||
if (computedType != null) {
|
||||
type = computedType;
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
|
|
@ -196,23 +196,25 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
|
|||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getType()
|
||||
*/
|
||||
public IFunctionType getType() {
|
||||
public IFunctionType getType() {
|
||||
if (type == null) {
|
||||
IASTDeclarator declarator = getPhysicalNode();
|
||||
if (declarator == null && (bits & FULLY_RESOLVED) == 0) {
|
||||
resolveAllDeclarations();
|
||||
declarator = getPhysicalNode();
|
||||
}
|
||||
if (declarator != null) {
|
||||
IType tempType = CVisitor.unwrapTypedefs(CVisitor.createType(declarator));
|
||||
if (tempType instanceof IFunctionType)
|
||||
type = (IFunctionType) tempType;
|
||||
}
|
||||
type = createType();
|
||||
}
|
||||
return type;
|
||||
return type;
|
||||
}
|
||||
|
||||
protected IFunctionType createType() {
|
||||
IASTDeclarator declarator = getPhysicalNode();
|
||||
if (declarator == null && (bits & FULLY_RESOLVED) == 0) {
|
||||
resolveAllDeclarations();
|
||||
declarator = getPhysicalNode();
|
||||
}
|
||||
if (declarator != null) {
|
||||
IType tempType = CVisitor.unwrapTypedefs(CVisitor.createType(declarator));
|
||||
if (tempType instanceof IFunctionType)
|
||||
return (IFunctionType) tempType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public IBinding resolveParameter( IASTName paramName ){
|
||||
|
|
|
@ -883,7 +883,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
if (exception != null) {
|
||||
Throwable masked= getMaskedException(exception);
|
||||
if (masked != exception) {
|
||||
e= exception;
|
||||
e= masked;
|
||||
exception= null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue