From 3805136b3f616859f78dd81976d4380f41fcae3e Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 5 Aug 2010 13:56:30 +0000 Subject: [PATCH] Bug 321856: Stack overflow for recursive function type. --- .../cdt/core/parser/tests/ast2/AST2Tests.java | 9 ++++++ .../core/dom/parser/c/CExternalFunction.java | 13 +++++--- .../internal/core/dom/parser/c/CFunction.java | 32 ++++++++++--------- .../core/pdom/AbstractIndexerTask.java | 2 +- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 1a38c8b556a..58cccc3559f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -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"); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java index e27efb2f5b8..4d67e2625f5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java index 4a4f452de27..1c1a1ba89e3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java @@ -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 ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java index 65c3068efce..b11638817d8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java @@ -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; } }