Do not generate context for assert(0) (#15625)

This commit is contained in:
Nicholas Wilson 2023-09-28 12:40:20 +08:00 committed by GitHub
parent 8a65dd7cbc
commit a6285c26c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View file

@ -6427,7 +6427,9 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
const generateMsg = !exp.msg &&
sc.needsCodegen() && // let ctfe interpreter handle the error message
global.params.checkAction == CHECKACTION.context &&
global.params.useAssert == CHECKENABLE.on;
global.params.useAssert == CHECKENABLE.on &&
!((exp.e1.isIntegerExp() && (exp.e1.toInteger() == 0)) ||
exp.e1.isNullExp());
Expression temporariesPrefix;
if (generateMsg)

View file

@ -0,0 +1,10 @@
module checkaction_context_assert_0;
/*
REQUIRED_ARGS: -vcg-ast -o- -checkaction=context
OUTPUT_FILES: compilable/checkaction-context-assert-0.d.cg
TEST_OUTPUT_FILE: extra-files/checkaction-context-assert-0.d.cg
*/
void a() { assert(0); }
void b() { assert(false); }
void c() { assert(null); }

View file

@ -0,0 +1,15 @@
=== compilable/checkaction-context-assert-0.d.cg
module checkaction_context_assert_0;
import object;
void a()
{
assert(0);
}
void b()
{
assert(false);
}
void c()
{
assert(null);
}