Skip to content

[Clang][ExprConstant] fix constant expression did not evaluate to integer #97146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,8 @@ Bug Fixes to C++ Support
- Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205).
- Fixed a bug where the first operand of binary ``operator&`` would be transformed as if it was the operand
of the address of operator. (#GH97483).
- Fixed an assertion failure about a constant expression which is a known integer but is not
evaluated to an integer. (#GH96670).

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
9 changes: 6 additions & 3 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15859,9 +15859,12 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,

if (const auto *CE = dyn_cast<ConstantExpr>(Exp)) {
if (CE->hasAPValueResult()) {
Result.Val = CE->getAPValueResult();
IsConst = true;
return true;
APValue APV = CE->getAPValueResult();
if (!APV.isLValue()) {
Result.Val = std::move(APV);
IsConst = true;
return true;
}
}

// The SubExpr is usually just an IntegerLiteral.
Expand Down
10 changes: 10 additions & 0 deletions clang/test/SemaCXX/eval-crashes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,13 @@ struct array {
array() : data(*new int[1][2]) {}
};
}

namespace GH96670 {
inline constexpr long ullNil = -1;

template<typename T = long, const T &Nil = ullNil>
struct Test {};

inline constexpr long lNil = -1;
Test<long, lNil> c;
}
Loading