Skip to content

Commit

Permalink
Fix segfault due to failing Expr classification
Browse files Browse the repository at this point in the history
Closes #1124.

Test: transpile `_Static_assert(1, "segfault");`
  • Loading branch information
thedataking committed Oct 22, 2024
1 parent 516b30e commit 3ba5917
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions c2rust-ast-exporter/src/AstExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,12 @@ class TranslateASTVisitor final
#if CLANG_VERSION_MAJOR < 13
bool isRValue = ast->isRValue();
#else
assert(Context && "Expected Context to be non-NULL");
bool isRValue = ast->Classify(*Context).isRValue();
// prvalues are equivalent to rvalues in C++03.
//
// NOTE: We used to call ast->Classify(*Context).isRValue() but that may
// result in a segfault on LLVM 18 and 19 for certain string literals.
// See https://github.com/immunant/c2rust/issues/1124
bool isRValue = ast->getValueKind() == VK_PRValue;
#endif
encode_entry_raw(ast, tag, ast->getSourceRange(), ty, isRValue, isVaList,
encodeMacroExpansions, childIds, extra);
Expand Down

0 comments on commit 3ba5917

Please sign in to comment.