yronglin updated this revision to Diff 533735. yronglin marked an inline comment as done. yronglin added a comment.
Add ReleaseNotes Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D153296/new/ https://reviews.llvm.org/D153296 Files: clang/docs/ReleaseNotes.rst clang/lib/AST/ExprConstant.cpp clang/test/SemaCXX/switch.cpp Index: clang/test/SemaCXX/switch.cpp =================================================================== --- clang/test/SemaCXX/switch.cpp +++ clang/test/SemaCXX/switch.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s void test() { bool x = true; @@ -146,3 +147,17 @@ } } // namespace EmptyEnum + +#if __cplusplus >= 201703L +constexpr int foo(unsigned char c) { + switch (unknown_value) { // expected-error {{use of undeclared identifier}} + case 0: + return 7; + default: + break; + } + return 0; +} + +static_assert(foo('d')); // expected-error {{static assertion expression is not an integral constant expression}} +#endif Index: clang/lib/AST/ExprConstant.cpp =================================================================== --- clang/lib/AST/ExprConstant.cpp +++ clang/lib/AST/ExprConstant.cpp @@ -4889,6 +4889,9 @@ static bool EvaluateDependentExpr(const Expr *E, EvalInfo &Info) { assert(E->isValueDependent()); + // Stop evaluate if expression contains errors. + if (E->containsErrors()) + return false; if (Info.noteSideEffect()) return true; assert(E->containsErrors() && "valid value-dependent expression should never " Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -520,6 +520,9 @@ type by the default argument promotions, and thus this is UB. Clang's behavior now matches GCC's behavior in C++. (`#38717 <https://github.com/llvm/llvm-project/issues/38717>_`). +- Stop evaluate constant expression if the condition expression which in + switch statement contains errors. + (`#63453 <https://github.com/llvm/llvm-project/issues/63453>_`) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Index: clang/test/SemaCXX/switch.cpp =================================================================== --- clang/test/SemaCXX/switch.cpp +++ clang/test/SemaCXX/switch.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s void test() { bool x = true; @@ -146,3 +147,17 @@ } } // namespace EmptyEnum + +#if __cplusplus >= 201703L +constexpr int foo(unsigned char c) { + switch (unknown_value) { // expected-error {{use of undeclared identifier}} + case 0: + return 7; + default: + break; + } + return 0; +} + +static_assert(foo('d')); // expected-error {{static assertion expression is not an integral constant expression}} +#endif Index: clang/lib/AST/ExprConstant.cpp =================================================================== --- clang/lib/AST/ExprConstant.cpp +++ clang/lib/AST/ExprConstant.cpp @@ -4889,6 +4889,9 @@ static bool EvaluateDependentExpr(const Expr *E, EvalInfo &Info) { assert(E->isValueDependent()); + // Stop evaluate if expression contains errors. + if (E->containsErrors()) + return false; if (Info.noteSideEffect()) return true; assert(E->containsErrors() && "valid value-dependent expression should never " Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -520,6 +520,9 @@ type by the default argument promotions, and thus this is UB. Clang's behavior now matches GCC's behavior in C++. (`#38717 <https://github.com/llvm/llvm-project/issues/38717>_`). +- Stop evaluate constant expression if the condition expression which in + switch statement contains errors. + (`#63453 <https://github.com/llvm/llvm-project/issues/63453>_`) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits