Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMarkus Schorn2010-08-05 13:56:46 +0000
committerMarkus Schorn2010-08-05 13:56:46 +0000
commit8d7cd211b5d70c65d5719564160ed668c7b4d289 (patch)
tree923b719d292c0a315d8a44e891ac40089e0f74a5 /core
parentb76671b75e39073e3b3ffe7eb248e06d4c0aa279 (diff)
downloadorg.eclipse.cdt-8d7cd211b5d70c65d5719564160ed668c7b4d289.tar.gz
org.eclipse.cdt-8d7cd211b5d70c65d5719564160ed668c7b4d289.tar.xz
org.eclipse.cdt-8d7cd211b5d70c65d5719564160ed668c7b4d289.zip
Bug 321856: Stack overflow for recursive function type.
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java32
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java2
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 458c5365b8c..2e6cd73fe95 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
@@ -7120,6 +7120,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 964b40a7687..e9323f952c1 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
@@ -880,7 +880,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (exception != null) {
Throwable masked= getMaskedException(exception);
if (masked != exception) {
- e= exception;
+ e= masked;
exception= null;
}
}

Back to the top