Skip to content

Commit

Permalink
4197+5453 ICE with CTFE forward reference
Browse files Browse the repository at this point in the history
Fixes two ice-on-invalid-code bugs:
4197 ICE(glue.c): error in forward-referenced in/out contract
5453 ICE(statement.c): invalid switch statement forward referenced by CTFE

When CTFE finds that it needs to run semantic on a function, it should ungag
errors, unless the function is part of a speculative template.
  • Loading branch information
Don Clugston committed Sep 13, 2011
1 parent a75196a commit 2fe75e8
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/interpret.c
Expand Up @@ -25,6 +25,10 @@
#include "id.h"
#include "utf.h"

#include "template.h"
TemplateInstance *isSpeculativeFunction(FuncDeclaration *fd);


#define LOG 0
#define LOGASSIGN 0

Expand Down Expand Up @@ -150,9 +154,23 @@ Expression *FuncDeclaration::interpret(InterState *istate, Expressions *argument

if (semanticRun < PASSsemantic3 && scope)
{
/* Forward reference - we need to run semantic3 on this function.
* If errors are gagged, and it's not part of a speculative
* template instance, we need to temporarily ungag errors.
*/
int olderrors = global.errors;
int oldgag = global.gag;
TemplateInstance *spec = isSpeculativeFunction(this);
if (global.gag && !spec)
global.gag = 0;
semantic3(scope);
if (olderrors != global.errors) // if errors compiling this function
global.gag = oldgag; // regag errors

// If it is a speculatively-instantiated template, and errors occur,
// we need to mark the template as having errors.
if (spec && global.errors != olderrors)
spec->errors = global.errors - olderrors;
if (olderrors != global.errors) // if errors compiling this function
return NULL;
}
if (semanticRun < PASSsemantic3done)
Expand Down

0 comments on commit 2fe75e8

Please sign in to comment.