mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 21:21:48 +03:00
Fix Issue 23873 - [ICE] segfault on imported static if ; else auto x (#15168)
This commit is contained in:
parent
6d0a9a5607
commit
c2f8f32de5
4 changed files with 36 additions and 4 deletions
|
@ -26,6 +26,7 @@ import dmd.location;
|
|||
import dmd.mtype;
|
||||
import dmd.visitor;
|
||||
|
||||
import core.stdc.stdio;
|
||||
/***********************************************************
|
||||
*/
|
||||
extern (C++) final class Import : Dsymbol
|
||||
|
@ -232,7 +233,20 @@ extern (C++) final class Import : Dsymbol
|
|||
* most likely because of parsing errors.
|
||||
* Therefore we cannot trust the resulting AST.
|
||||
*/
|
||||
if (load(sc)) return;
|
||||
if (load(sc))
|
||||
{
|
||||
// https://issues.dlang.org/show_bug.cgi?id=23873
|
||||
// For imports that are not at module or function level,
|
||||
// e.g. aggregate level, the import symbol is added to the
|
||||
// symbol table and later semantic is performed on it.
|
||||
// This leads to semantic analysis on an malformed AST
|
||||
// which causes all kinds of segfaults.
|
||||
// The fix is to note that the module has errors and avoid
|
||||
// semantic analysis on it.
|
||||
if(mod)
|
||||
mod.errors = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mod) return; // Failed
|
||||
|
||||
|
|
|
@ -1366,9 +1366,9 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
|
|||
{
|
||||
static if (LOG)
|
||||
{
|
||||
printf("Import::semantic('%s') %s\n", toPrettyChars(), id.toChars());
|
||||
printf("Import::semantic('%s') %s\n", imp.toPrettyChars(), imp.id.toChars());
|
||||
scope(exit)
|
||||
printf("-Import::semantic('%s'), pkg = %p\n", toChars(), pkg);
|
||||
printf("-Import::semantic('%s'), pkg = %p\n", imp.toChars(), imp.pkg);
|
||||
}
|
||||
if (imp.semanticRun > PASS.initial)
|
||||
return;
|
||||
|
@ -1434,7 +1434,9 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
|
|||
imp.addPackageAccess(scopesym);
|
||||
}
|
||||
|
||||
imp.mod.dsymbolSemantic(null);
|
||||
// if a module has errors it means that parsing has failed.
|
||||
if (!imp.mod.errors)
|
||||
imp.mod.dsymbolSemantic(null);
|
||||
|
||||
if (imp.mod.needmoduleinfo)
|
||||
{
|
||||
|
|
2
compiler/test/fail_compilation/imports/import23873.d
Normal file
2
compiler/test/fail_compilation/imports/import23873.d
Normal file
|
@ -0,0 +1,2 @@
|
|||
static if ;
|
||||
else auto x
|
14
compiler/test/fail_compilation/test23873.d
Normal file
14
compiler/test/fail_compilation/test23873.d
Normal file
|
@ -0,0 +1,14 @@
|
|||
// https://issues.dlang.org/show_bug.cgi?id=23873
|
||||
|
||||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/imports/import23873.d(1): Error: (expression) expected following `static if`
|
||||
fail_compilation/imports/import23873.d(1): Error: declaration expected following attribute, not `;`
|
||||
fail_compilation/imports/import23873.d(3): Error: no identifier for declarator `x`
|
||||
---
|
||||
*/
|
||||
struct Foo
|
||||
{
|
||||
import imports.import23873;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue