This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Allow evaluating expressions in C++20 mode
AcceptedPublic

Authored by Michael137 on Feb 1 2023, 3:47 AM.

Details

Reviewers
aprantl
labath
Summary

This patch allows users to evaluate expressions using
expr -l c++20. Currently DWARF keeps the CU's at
DW_AT_language at DW_LANG_C_plus_plus_14 even
when compiling with -std=c++20. So even in "C++20
programs" expression evaluation will by default be
performed in C++11 mode for now.

Enabling C++14 has been previously attempted at
https://reviews.llvm.org/D80308

There are some remaining issues around evaluating C++20
expressions. Mainly, lack of support for C++20 AST nodes in
clang::ASTImporter. But these can be addressed in follow-up
patches.

Diff Detail

Event Timeline

Michael137 created this revision.Feb 1 2023, 3:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2023, 3:47 AM
Michael137 requested review of this revision.Feb 1 2023, 3:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2023, 3:47 AM
Michael137 updated this revision to Diff 493899.Feb 1 2023, 3:51 AM
  • Remove redundant change
aprantl added inline comments.Feb 1 2023, 1:11 PM
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
522

Why no case C++17?

525

Why does this not set C++14? Because it's effectively equivalent?

aprantl added inline comments.Mar 28 2023, 9:33 AM
lldb/source/Target/Language.cpp
271

Can you check if we already have a similar function in Dwarf.h in LLVM?

Michael137 added inline comments.Apr 3 2023, 4:05 AM
lldb/source/Target/Language.cpp
271

we do in fact :)

dwarf::isCplusPlus

The only remaining quirk is that we one of the language constants (DW_LANG_Mips_Assembler) doesn't match the DWARF constants. Which isn't really a problem for this particular function

Michael137 added inline comments.Apr 3 2023, 4:12 AM
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
525

I think it's because we haven't done the work to make c++14 in the expression evaluator work, but the default clang language is c++14. So we downgrade it silently to c++11 here.

We should really fix that, but I think this broke some tests in the past when we tried enabling it (see 8cb75745412e4bc9592d2409cc6cfa4a2940d9e7, https://reviews.llvm.org/D80308)

Michael137 marked an inline comment as not done.Apr 14 2023, 7:20 AM
Michael137 added inline comments.
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
525

But looking at the specific test failures from back then there doesn't seem like a good reason for why we can't re-enable that patch now. And also add a C++17 version.

Let me try that

Michael137 added inline comments.Apr 14 2023, 7:29 AM
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
522

Fair point, can add one

aprantl accepted this revision.Apr 14 2023, 8:49 AM
This revision is now accepted and ready to land.Apr 14 2023, 8:49 AM
  • Add FIXME
JDevlieghere added inline comments.Apr 14 2023, 9:17 AM
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
518

s/evaluatino/evaluation/