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);
|
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 {
|
public void testDeepBinaryExpression_294969() throws Exception {
|
||||||
sValidateCopy= false;
|
sValidateCopy= false;
|
||||||
StringBuilder buf= new StringBuilder("void f() {0");
|
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.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
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.IFunctionType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
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.core.dom.ast.c.ICExternalBinding;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Models functions used without declarations.
|
* Models functions used without declarations.
|
||||||
|
@ -38,9 +39,13 @@ public class CExternalFunction extends CFunction implements ICExternalBinding {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IFunctionType getType() {
|
public IFunctionType getType() {
|
||||||
IFunctionType t = super.getType();
|
if (type == null) {
|
||||||
if (t == null) {
|
// Bug 321856: Prevent recursions
|
||||||
type = new CFunctionType(VOID_TYPE, IType.EMPTY_TYPE_ARRAY);
|
type = new CPPFunctionType(VOID_TYPE, IType.EMPTY_TYPE_ARRAY);
|
||||||
|
IFunctionType computedType = createType();
|
||||||
|
if (computedType != null) {
|
||||||
|
type = computedType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,23 +196,25 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
public IFunctionType getType() {
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getType()
|
|
||||||
*/
|
|
||||||
public IFunctionType getType() {
|
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
IASTDeclarator declarator = getPhysicalNode();
|
type = createType();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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 ){
|
public IBinding resolveParameter( IASTName paramName ){
|
||||||
|
|
|
@ -883,7 +883,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
if (exception != null) {
|
if (exception != null) {
|
||||||
Throwable masked= getMaskedException(exception);
|
Throwable masked= getMaskedException(exception);
|
||||||
if (masked != exception) {
|
if (masked != exception) {
|
||||||
e= exception;
|
e= masked;
|
||||||
exception= null;
|
exception= null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue