Skip to content

Commit 40eb47a

Browse files
authored
Fix the line info for return statements (#28327)
Fixes the line info for return statements when they are normalized. This fixes an issue where the debug info for `return` would be generated as being at the beginning of the function, not the end. Future work should investigate and ensure proper debug info for multiple returns. - [x] paratest [Reviewed by @dlongnecke-cray]
2 parents f99fabe + 0039863 commit 40eb47a

File tree

7 files changed

+11
-10
lines changed

7 files changed

+11
-10
lines changed

compiler/codegen/cg-expr.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ GenRet SymExpr::codegen() {
192192
if (id == breakOnCodegenID)
193193
debuggerBreakHere();
194194

195-
if (outfile) {
196-
if (getStmtExpr() && getStmtExpr() == this) codegenStmt(this);
197-
}
195+
if (getStmtExpr() == this)
196+
codegenStmt(this);
197+
198198

199199
if (auto fn = toFnSymbol(var)) {
200200
if (shouldGenerateAsIfCallingDirectly(this, fn)) {
@@ -4393,7 +4393,8 @@ GenRet CallExpr::codegen() {
43934393
// Note (for debugging), function name is in parentSymbol->cname.
43944394
if (id == breakOnCodegenID) debuggerBreakHere();
43954395

4396-
if (getStmtExpr() == this) codegenStmt(this);
4396+
if (getStmtExpr() == this)
4397+
codegenStmt(this);
43974398

43984399
INT_ASSERT(fn || primitive != nullptr || this->isIndirectCall());
43994400
bool canGenerate = (fn && !fn->hasFlag(FLAG_NO_CODEGEN)) ||

compiler/codegen/cg-stmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void codegenStmt(Expr* stmt) {
6262
// Adjust the current line number, but leave the scope alone.
6363
llvm::MDNode* scope;
6464

65-
if(auto fn = toFnSymbol(stmt->parentSymbol); stmt->inTree()) {
65+
if (auto fn = toFnSymbol(stmt->parentSymbol); stmt->inTree()) {
6666
scope = debugInfo->getFunction(fn);
6767
} else {
6868
scope = info->irBuilder->getCurrentDebugLocation().getScope();

compiler/passes/normalize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ static void normalizeReturns(FnSymbol* fn) {
19281928
if (fn->hasFlag(FLAG_NO_FN_BODY)) return;
19291929
if (shouldSkipNormalizing(fn)) return;
19301930

1931-
SET_LINENO(fn);
1931+
SET_LINENO((fn->body->body.tail ? (BaseAST*)fn->body->body.tail : (BaseAST*)fn));
19321932

19331933
fixupExportedArrayReturns(fn);
19341934
fixupGenericReturnTypes(fn);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
lifetime-checking.chpl:11: In function 'test':
2-
lifetime-checking.chpl:11: error: Illegal return of dead value
2+
lifetime-checking.chpl:16: error: Illegal return of dead value
33
lifetime-checking.chpl:16: note: 'a' is dead due to deinitialization here
44
lifetime-checking.chpl:16: error: Scoped variable c cannot be returned
55
lifetime-checking.chpl:12: note: consider scope of a
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
array-in-scalar-ret-by-ref.chpl:4: In method 'getArrayElt':
22
array-in-scalar-ret-by-ref.chpl:5: error: Initializing a reference with another type
3-
array-in-scalar-ret-by-ref.chpl:4: note: Reference has type int(64)
3+
array-in-scalar-ret-by-ref.chpl:5: note: Reference has type int(64)
44
array-in-scalar-ret-by-ref.chpl:5: note: Initializing with type [domain(1,int(64),one)] int(64)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
errors-type-mismatch-fn-1.chpl:6: In method 'this':
22
errors-type-mismatch-fn-1.chpl:7: error: Initializing a reference with another type
3-
errors-type-mismatch-fn-1.chpl:6: note: Reference has type real(64)
3+
errors-type-mismatch-fn-1.chpl:7: note: Reference has type real(64)
44
errors-type-mismatch-fn-1.chpl:7: note: Initializing with type int(64)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
errors-type-mismatch-fn-2.chpl:4: In method 'this':
22
errors-type-mismatch-fn-2.chpl:5: error: Initializing a reference with another type
3-
errors-type-mismatch-fn-2.chpl:4: note: Reference has type real(64)
3+
errors-type-mismatch-fn-2.chpl:5: note: Reference has type real(64)
44
errors-type-mismatch-fn-2.chpl:5: note: Initializing with type int(64)

0 commit comments

Comments
 (0)