Fix bypassing nothrow in debug statements (#20720)

* Fix bypassing nothrow in debug statements

* Fix debug walking null statements
This commit is contained in:
Dennis 2025-01-17 01:50:17 +01:00 committed by GitHub
parent b237d0329c
commit ac9e8a5a70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 19 deletions

View file

@ -1363,11 +1363,6 @@ private Expression resolveUFCSProperties(Scope* sc, Expression e1, Expression e2
auto arguments = new Expressions(1);
(*arguments)[0] = eleft;
e = new CallExp(loc, e, arguments);
// https://issues.dlang.org/show_bug.cgi?id=24017
if (sc.flags & SCOPE.debug_)
e.isCallExp().inDebugStatement = true;
e = e.expressionSemantic(sc);
return e;
}

View file

@ -134,7 +134,16 @@ private Expression checkAssignmentAsCondition(Expression e, Scope* sc)
return e;
}
// Performs semantic analysis in Statement AST nodes
/**
* Performs semantic analysis in Statement AST nodes
*
* Params:
* s = statement to perform semantic analysis on
* sc = scope in which statement resides
*
* Returns: statement `s` after semantic analysis.
* Can be `null`, for example with `pragma(msg, "")`
*/
Statement statementSemantic(Statement s, Scope* sc)
{
import dmd.compiler;
@ -3461,6 +3470,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
sc = sc.push();
sc.flags |= SCOPE.debug_;
ds.statement = ds.statement.statementSemantic(sc);
debugThrowWalker(ds.statement);
sc.pop();
}
result = ds.statement;
@ -4736,7 +4746,6 @@ private Statements* flatten(Statement statement, Scope* sc)
if (dc)
{
s = new DebugStatement(cs.loc, cs.ifbody);
debugThrowWalker(cs.ifbody);
}
else
s = cs.ifbody;
@ -4908,7 +4917,8 @@ Params:
*/
private void debugThrowWalker(Statement s)
{
if (!s)
return;
extern(C++) final class DebugWalker : SemanticTimeTransitiveVisitor
{
alias visit = SemanticTimeTransitiveVisitor.visit;

View file

@ -85,3 +85,17 @@ void test6() nothrow
() {throw new Exception("");}();
}
}
void writeln() {}
void writeln(string) {}
void test7() nothrow
{
debug writeln("Hello"); // https://issues.dlang.org/show_bug.cgi?id=24017
debug "Hello".writeln;
debug writeln = "Hello"; // https://github.com/dlang/dmd/issues/20719
debug writeln;
// https://github.com/dlang/dmd/pull/20720#issuecomment-2596892489
debug pragma(msg, ""); // Came up as segfault, pragma statement became null after semantic
}

View file

@ -1,11 +0,0 @@
// https://issues.dlang.org/show_bug.cgi?id=24017
// REQUIRED_ARGS: -debug
void writeln(string) {}
void main() nothrow
{
debug writeln("Hello");
debug "Hello".writeln;
}