Skip to content

Commit 5299903

Browse files
authored
Properly handle unknown files in InsertLineNumbers (#28021)
Fixes an issue with CHPL_UNWIND!=none when compiling a program with extern blocks like `test/extern/ferguson/externblock/extern_block_primer.chpl`. This was caused by trying to write file information for all the functions in a program (only when `CHPL_UNWIND!=none`), including the ones in the extern block (which have no file information). This was causing an internal error. The solution implemented in this PR is not specific to extern blocks, this just adds a better default than an internal error. Future work could add file information for extern blocks. - [x] paratest [Reviewed by @DanilaFe]
2 parents f9430e6 + b8f97e3 commit 5299903

File tree

4 files changed

+53
-15
lines changed

4 files changed

+53
-15
lines changed

compiler/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ target_include_directories(chpl PRIVATE
9999
${SRC_DIR}/../build/compiler/${CHPL_COMPILER_SUBDIR} # for enabling CONFIGURED_PREFIX in configured_prefix.h
100100
${SRC_DIR}/../runtime/include/encoding # support for sharing unicode support between compiler and runtime
101101
${SRC_DIR}/../third-party/utf8-decoder # support for sharing unicode support between compiler and runtime
102+
${SRC_DIR}/../runtime/include/fileinfo # support for sharing line/file support between compiler and runtime
102103
)
103104

104105
# all the compiler subdirectories with sources do these same things

compiler/passes/insertLineNumbers.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include <unordered_set>
3939
#include <vector>
4040

41+
#include "chpl-linefile-defs.h"
42+
4143
namespace {
4244
// As a means of abbreviation.
4345
using Pass = InsertLineNumbers;
@@ -72,8 +74,7 @@ int Pass::addFilenameTableEntry(const std::string& name) {
7274

7375
int Pass::getFilenameTableIndex(const std::string& name) {
7476
if (auto optIdx = gFilenameTable.index(name)) return *optIdx;
75-
INT_FATAL("Entry not in table!");
76-
return -1;
77+
return CHPL_FILE_IDX_UNKNOWN;
7778
}
7879

7980
const std::vector<std::string>& Pass::getFilenameTable() {
@@ -147,6 +148,7 @@ Pass::LineAndFile Pass::makeASTLine(CallExpr* call) {
147148

148149
if (call->isResolved() &&
149150
call->resolvedFunction()->hasFlag(FLAG_COMMAND_LINE_SETTING)) {
151+
// TODO: can this just use CHPL_FILE_IDX_COMMAND_LINE_ARG?
150152
// Make up pretend line numbers for errors with command line
151153
// configuration variables.
152154
Symbol* line = new_IntSymbol(0);

runtime/include/chpl-linefile-support.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,12 @@
2323

2424
#include "chpltypes.h"
2525

26+
#include "fileinfo/chpl-linefile-defs.h"
27+
2628
#ifdef __cplusplus
2729
extern "C" {
2830
#endif
2931

30-
#define CHPL_FILE_IDX_INTERNAL 1 // <internal>
31-
32-
#define CHPL_FILE_IDX_COMMAND_LINE -1 // (command-line)
33-
#define CHPL_FILE_IDX_COMMAND_LINE_ARG -2 // <command-line arg>
34-
#define CHPL_FILE_IDX_FORK_LARGE -3 // "fork large"
35-
#define CHPL_FILE_IDX_MAIN_PROGRAM -4 // "main program"
36-
#define CHPL_FILE_IDX_UNKNOWN -5 // "<unknown>"
37-
#define CHPL_FILE_IDX_IDLE_TASK -6 // "|idle|"
38-
#define CHPL_FILE_IDX_COMM_TASK -7 // "<comm thread>"
39-
#define CHPL_FILE_IDX_MAIN_TASK -8 // "<main task>"
40-
#define CHPL_FILE_IDX_ON_BODY_TASK -9 // "on-body task"
41-
#define CHPL_FILE_IDX_SAVED_FILENAME -10 // variable, see below
42-
4332
// chpl_saveFilename stores the passed in char*, subsequent calls to
4433
// chpl_lookupFilename(CHPL_FILE_IDX_SAVED_FILENAME) will return that stored
4534
// pointer. CHPL_FILE_IDX_SAVED_FILENAME may only be used while the original
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2020-2025 Hewlett Packard Enterprise Development LP
3+
* Copyright 2004-2019 Cray Inc.
4+
* Other additional copyright holders may be indicated within.
5+
*
6+
* The entirety of this work is licensed under the Apache License,
7+
* Version 2.0 (the "License"); you may not use this file except
8+
* in compliance with the License.
9+
*
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
#ifndef _chpl_linefile_defs_h_
22+
#define _chpl_linefile_defs_h_
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
enum chpl_file_idx_t {
29+
CHPL_FILE_IDX_INTERNAL = 1, // <internal>
30+
CHPL_FILE_IDX_COMMAND_LINE = -1, // (command-line)
31+
CHPL_FILE_IDX_COMMAND_LINE_ARG = -2, // <command-line arg>
32+
CHPL_FILE_IDX_FORK_LARGE = -3, // "fork large"
33+
CHPL_FILE_IDX_MAIN_PROGRAM = -4, // "main program"
34+
CHPL_FILE_IDX_UNKNOWN = -5, // "<unknown>"
35+
CHPL_FILE_IDX_IDLE_TASK = -6, // "|idle|"
36+
CHPL_FILE_IDX_COMM_TASK = -7, // "<comm thread>"
37+
CHPL_FILE_IDX_MAIN_TASK = -8, // "<main task>"
38+
CHPL_FILE_IDX_ON_BODY_TASK = -9, // "on-body task"
39+
CHPL_FILE_IDX_SAVED_FILENAME = -10, // variable, see chpl-linefile-support.h
40+
};
41+
42+
#ifdef __cplusplus
43+
}
44+
#endif
45+
46+
#endif // _chpl_linefile_defs_h_

0 commit comments

Comments
 (0)