[PATCH] D148206: [clang] Do not crash after suggesting typo correction to constexpr if condition
Mariya Podchishchaeva via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 13 10:07:46 PDT 2023
Fznamznon updated this revision to Diff 513290.
Fznamznon added a comment.
Use std::optional
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D148206/new/
https://reviews.llvm.org/D148206
Files:
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/test/SemaCXX/invalid-if-constexpr.cpp
Index: clang/test/SemaCXX/invalid-if-constexpr.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/invalid-if-constexpr.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s
+
+namespace GH61885 {
+void similar() { // expected-note {{'similar' declared here}}
+ if constexpr (similer<>) {} // expected-error {{use of undeclared identifier 'similer'; did you mean 'similar'?}}
+}
+void a() { if constexpr (__adl_swap<>) {}} // expected-error{{use of undeclared identifier '__adl_swap'; did you mean '__sync_swap'?}} \
+ // expected-note {{'__sync_swap' declared here}}
+
+int AA() { return true;} // expected-note {{'AA' declared here}}
+
+void b() { if constexpr (AAA<>) {}} // expected-error {{use of undeclared identifier 'AAA'; did you mean 'AA'?}}
+}
+
Index: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -12843,20 +12843,22 @@
Decl *ConditionVar;
FullExprArg Condition;
bool Invalid;
- bool HasKnownValue;
- bool KnownValue;
+ std::optional<bool> KnownValue;
friend class Sema;
ConditionResult(Sema &S, Decl *ConditionVar, FullExprArg Condition,
bool IsConstexpr)
- : ConditionVar(ConditionVar), Condition(Condition), Invalid(false),
- HasKnownValue(IsConstexpr && Condition.get() &&
- !Condition.get()->isValueDependent()),
- KnownValue(HasKnownValue &&
- !!Condition.get()->EvaluateKnownConstInt(S.Context)) {}
+ : ConditionVar(ConditionVar), Condition(Condition), Invalid(false) {
+ if (IsConstexpr && Condition.get()) {
+ if (std::optional<llvm::APSInt> Val =
+ Condition.get()->getIntegerConstantExpr(S.Context)) {
+ KnownValue = !!(*Val);
+ }
+ }
+ }
explicit ConditionResult(bool Invalid)
: ConditionVar(nullptr), Condition(nullptr), Invalid(Invalid),
- HasKnownValue(false), KnownValue(false) {}
+ KnownValue(std::nullopt) {}
public:
ConditionResult() : ConditionResult(false) {}
@@ -12866,8 +12868,6 @@
Condition.get());
}
std::optional<bool> getKnownValue() const {
- if (!HasKnownValue)
- return std::nullopt;
return KnownValue;
}
};
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -301,6 +301,8 @@
expressions/statements with invalid source locations in non-assert builds.
Assert builds may still see assertions triggered from this.
(`#62105 <https://github.com/llvm/llvm-project/issues/62105>`_)
+- Fix crash after suggesting typo correction to constexpr if condition.
+ (`#61885 <https://github.com/llvm/llvm-project/issues/61885>`_)
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148206.513290.patch
Type: text/x-patch
Size: 3082 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230413/5b1903eb/attachment.bin>
More information about the cfe-commits
mailing list