[PATCH] D154861: [clang][AST] Propagate the contains-errors bit to DeclRefExpr from VarDecl's initializer.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 11 00:13:16 PDT 2023
hokein updated this revision to Diff 538929.
hokein marked 2 inline comments as done.
hokein added a comment.
address comments and add release note.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154861/new/
https://reviews.llvm.org/D154861
Files:
clang/docs/ReleaseNotes.rst
clang/lib/AST/ComputeDependence.cpp
clang/test/AST/ast-dump-recovery.c
clang/test/SemaCXX/cxx11-crashes.cpp
Index: clang/test/SemaCXX/cxx11-crashes.cpp
===================================================================
--- clang/test/SemaCXX/cxx11-crashes.cpp
+++ clang/test/SemaCXX/cxx11-crashes.cpp
@@ -65,7 +65,7 @@
struct S {}; // expected-note 3{{candidate}}
void f() {
S s(1, 2, 3); // expected-error {{no matching}}
- for (auto x : s) { // expected-error {{invalid range expression of}}
+ for (auto x : s) {
// We used to attempt to evaluate the initializer of this variable,
// and crash because it has an undeduced type.
const int &n(x);
Index: clang/test/AST/ast-dump-recovery.c
===================================================================
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -126,3 +126,25 @@
// CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>'
sizeof array / sizeof foo(undef);
}
+
+// No crash on DeclRefExpr that refers to ValueDecl with invalid initializers.
+void test7() {
+ int b[] = {""()};
+
+ // CHECK: CStyleCastExpr {{.*}} 'unsigned int' contains-errors
+ // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'int[]' contains-errors
+ (unsigned) b; // GH50236
+
+ // CHECK: BinaryOperator {{.*}} '<dependent type>' contains-errors '+'
+ // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int[]' contains-errors
+ // CHECK-NEXT: `-IntegerLiteral {{.*}}
+ b + 1; // GH50243
+
+ // CHECK: CallExpr {{.*}} '<dependent type>' contains-errors
+ // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int ()' Function
+ // CHECK-NEXT: `-DeclRefExpr {{.*}} 'int[]' contains-errors
+ return c(b); // GH48636
+}
+int test8_GH50320_b[] = {""()};
+// CHECK: ArraySubscriptExpr {{.*}} 'int' contains-errors lvalue
+int test8 = test_8GH50320_b[0];
Index: clang/lib/AST/ComputeDependence.cpp
===================================================================
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -489,7 +489,7 @@
// more bullets here that we handle by treating the declaration as having a
// dependent type if they involve a placeholder type that can't be deduced.]
if (Type->isDependentType())
- return Deps | ExprDependence::TypeValueInstantiation;
+ Deps |= ExprDependence::TypeValueInstantiation;
else if (Type->isInstantiationDependentType())
Deps |= ExprDependence::Instantiation;
@@ -525,13 +525,13 @@
// - it names a potentially-constant variable that is initialized with an
// expression that is value-dependent
if (const auto *Var = dyn_cast<VarDecl>(Decl)) {
- if (Var->mightBeUsableInConstantExpressions(Ctx)) {
- if (const Expr *Init = Var->getAnyInitializer()) {
- if (Init->isValueDependent())
- Deps |= ExprDependence::ValueInstantiation;
- if (Init->containsErrors())
- Deps |= ExprDependence::Error;
- }
+ if (const Expr *Init = Var->getAnyInitializer()) {
+ if (Init->containsErrors())
+ Deps |= ExprDependence::Error;
+
+ if (Var->mightBeUsableInConstantExpressions(Ctx) &&
+ Init->isValueDependent())
+ Deps |= ExprDependence::ValueInstantiation;
}
// - it names a static data member that is a dependent member of the
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -573,6 +573,12 @@
- Stop evaluating a constant expression if the condition expression which in
switch statement contains errors.
(`#63453 <https://github.com/llvm/llvm-project/issues/63453>_`)
+- Fix the contains-errors bit not being set for DeclRefExpr that refers to a
+ VarDecl with invalid initializer. This fixes:
+ (`#50236 <https://github.com/llvm/llvm-project/issues/50236>`_),
+ (`#50243 <https://github.com/llvm/llvm-project/issues/50243>`_),
+ (`#48636 <https://github.com/llvm/llvm-project/issues/48636>`_),
+ (`#50320 <https://github.com/llvm/llvm-project/issues/50320>`_).
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154861.538929.patch
Type: text/x-patch
Size: 4038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230711/ac60a2bb/attachment.bin>
More information about the cfe-commits
mailing list