Skip to content

charmxi: do not crash on serial blocks when run without -orig-file - #4027

Merged
lvkale merged 1 commit into
reviewed-with-reconversefrom
charmxi-origfile-null
Oct 11, 2026
Merged

lvkale merged 1 commit into
reviewed-with-reconversefrom
charmxi-origfile-null

Conversation

@lvkale

@lvkale lvkale commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Cause

processAst in src/xlat-i/xi-main.C set cur_file = origFile = origFile_;. origFile_ is NULL unless charmxi is given -orig-file. charmc always passes that flag, but direct callers of charmxi usually do not. SerialConstruct::generateCode (src/xlat-i/sdag/constructs/Serial.C) writes cur_file into a #line directive through XStr::append(const char*), which calls strlen on the NULL pointer. As a result, any non-empty serial block made charmxi segfault. The other users of cur_file print it in diagnostics: the SDAG-constructor error in SdagEntry.C and the error reporters in xi-util.C. They also crashed instead of reporting the error.

Fix

When no -orig-file is given, cur_file falls back to the input file name, or to STDIN when charmxi reads standard input. readFile already uses the same fallback while parsing. origFile itself is unchanged.

Reproducer

mainmodule t {
  mainchare Main {
    entry Main(CkArgMsg*);
    entry void run() {
      serial { int x = 1; (void)x; }
    };
  };
};
invocation before after
charmxi t.ci exit 139 (SIGSEGV) exit 0, t.def.h has #line 5 "t.ci"
charmxi < t.ci exit 139 exit 0
charmxi -orig-file t.ci t.ci exit 0 exit 0, #line 5 "t.ci"

Regression test

tests/charm++/charmxi_parsing gains SerialNoOrigFile.ci and a test-charmxi-direct target, which is part of make test. The target runs bin/charmxi directly on that file without -orig-file and checks that the generated .def.h has a #line directive naming the .ci file. With the unfixed charmxi the target fails with a segmentation fault.

🤖 Generated with Claude Code

processAst left cur_file NULL when charmxi was invoked without
-orig-file (charmc always passes it; direct callers usually do not),
and the serial construct wrote that pointer into a #line directive,
so any non-empty serial block crashed the translator. Fall back to
the input file name, as the preprocessing path already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lvkale
lvkale force-pushed the charmxi-origfile-null branch from abe1f86 to 76787b6 Compare October 10, 2026 23:59
@lvkale
lvkale merged commit 4cc35a5 into reviewed-with-reconverse Oct 11, 2026
5 checks passed
@lvkale
lvkale deleted the charmxi-origfile-null branch October 11, 2026 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants