Skip to content

Commit

Permalink
Fix bugzilla 24764 - ICE when -vcg-ast prints imported invariant (#16917
Browse files Browse the repository at this point in the history
)

Co-authored-by: Dennis Korpel <dennis@sarc.nl>
  • Loading branch information
dkorpel and Dennis Korpel authored Oct 3, 2024
1 parent f420f98 commit e0259d9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dmd/hdrgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -1858,9 +1858,9 @@ void toCBuffer(Dsymbol s, ref OutBuffer buf, ref HdrGenState hgs)
if (stcToBuffer(buf, d.storage_class))
buf.writeByte(' ');
buf.writestring("invariant");
if(auto es = d.fbody.isExpStatement())
auto es = d.fbody.isExpStatement();
if (es && es.exp && es.exp.op == EXP.assert_)
{
assert(es.exp && es.exp.op == EXP.assert_);
buf.writestring(" (");
(cast(AssertExp)es.exp).e1.expressionToBuffer(buf, hgs);
buf.writestring(");");
Expand Down
22 changes: 21 additions & 1 deletion compiler/test/compilable/extra-files/vcg-ast.d.cg
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ void main()
values();
return 0;
}
import imports.vcg_ast_import;
template imported()
{
import imported = imports.vcg_ast_import;
}
alias myImport = vcg_ast_import;
R!int
{
struct _R
Expand All @@ -126,6 +132,21 @@ mixin _d_cmain!();
}
}
}
imported!()
{
import object;
struct O
{
invariant
{
}
invariant
{
__invariant0();
}
}

}
RTInfo!(C)
{
enum immutable(void)* RTInfo = null;
Expand All @@ -150,4 +171,3 @@ RTInfo!(_R)
enum immutable(void)* RTInfo = null;

}

4 changes: 4 additions & 0 deletions compiler/test/compilable/imports/vcg_ast_import.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct O
{
invariant() {}
}
12 changes: 12 additions & 0 deletions compiler/test/compilable/vcg-ast.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
REQUIRED_ARGS: -vcg-ast -o-
PERMUTE_ARGS:
OUTPUT_FILES: compilable/vcg-ast.d.cg
EXTRA_FILES: imports/vcg_ast_import.d
TEST_OUTPUT_FILE: extra-files/vcg-ast.d.cg
*/

Expand Down Expand Up @@ -63,3 +64,14 @@ void main()
{
values!wchar_t;
}

// https://issues.dlang.org/show_bug.cgi?id=24764

import imports.vcg_ast_import;

template imported()
{
import imported = imports.vcg_ast_import;
}

alias myImport = imported!();

0 comments on commit e0259d9

Please sign in to comment.