Skip to content

Commit

Permalink
Fix #18281 - ICE on attempt to compare deref of two functions ptr (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored Jan 23, 2025
1 parent ac9e8a5 commit 72a9347
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
17 changes: 17 additions & 0 deletions compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -13496,6 +13496,11 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
error(exp.loc, "compare not defined for complex operands");
return setError();
}
else if (t1.isTypeFunction() || t2.isTypeFunction())
{
error(exp.loc, "comparison is not defined for function types");
return setError();
}
else if (t1.ty == Taarray || t2.ty == Taarray)
{
error(exp.loc, "`%s` is not defined for associative arrays", EXPtoString(exp.op).ptr);
Expand Down Expand Up @@ -13816,6 +13821,12 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
return;
}

if (t1.isTypeFunction() || t2.isTypeFunction())
{
error(exp.loc, "operator `==` is not defined for function types");
return setError();
}

if (auto tv = t1.isTypeVector())
exp.type = tv.toBooleanVector();

Expand Down Expand Up @@ -13877,6 +13888,12 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
if (exp.e2.op == EXP.call)
exp.e2 = (cast(CallExp)exp.e2).addDtorHook(sc);

if (exp.e1.type.isTypeFunction() || exp.e2.type.isTypeFunction())
{
error(exp.loc, "operator `is` is not defined for function types");
return setError();
}

if (exp.e1.type.toBasetype().ty == Tsarray ||
exp.e2.type.toBasetype().ty == Tsarray)
deprecation(exp.loc, "identity comparison of static arrays "
Expand Down
16 changes: 12 additions & 4 deletions compiler/test/fail_compilation/fail22151.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail22151.d(14): Error: function `test` is not an lvalue and cannot be modified
fail_compilation/fail22151.d(15): Error: function `test2` is not an lvalue and cannot be modified
fail_compilation/fail22151.d(18): Error: function pointed to by `fp` is not an lvalue and cannot be modified
fail_compilation/fail22151.d(21): Error: function pointed to by `ff` is not an lvalue and cannot be modified
fail_compilation/fail22151.d(17): Error: function `test` is not an lvalue and cannot be modified
fail_compilation/fail22151.d(18): Error: function `test2` is not an lvalue and cannot be modified
fail_compilation/fail22151.d(21): Error: function pointed to by `fp` is not an lvalue and cannot be modified
fail_compilation/fail22151.d(24): Error: function pointed to by `ff` is not an lvalue and cannot be modified
fail_compilation/fail22151.d(27): Error: operator `==` is not defined for function types
fail_compilation/fail22151.d(28): Error: operator `is` is not defined for function types
fail_compilation/fail22151.d(29): Error: comparison is not defined for function types
---
*/

Expand All @@ -19,6 +22,11 @@ void test()

auto ff = &test2;
*ff = *&test2;

// https://github.com/dlang/dmd/issues/18281
const c = *fp == *fp;
const d = *fp is *fp;
const e = *fp < *fp;
}

void test2();

0 comments on commit 72a9347

Please sign in to comment.