tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This fixes a long standing diagnostic difference between the two interpreters.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154758

Files:
  clang/lib/AST/Interp/Interp.cpp
  clang/test/AST/Interp/constexpr-nqueens.cpp
  clang/test/AST/Interp/cxx20.cpp
  clang/test/AST/Interp/literals.cpp
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===================================================================
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -429,7 +429,7 @@
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant expression}} \
                                  // ref-note {{initializer of 'D' is not a constant expression}} \
                                  // expected-error {{not an integral constant expression}} \
-                                 // expected-note {{read of object outside its lifetime}}
+                                 // expected-note {{read of uninitialized object}}
 #endif
 
   struct AnotherBase {
@@ -492,7 +492,7 @@
   constexpr A a{10}; // expected-error {{must be initialized by a constant expression}}
   static_assert(a.m == 10, "");
   static_assert(a.f == 10, ""); // expected-error {{not an integral constant expression}} \
-                                // expected-note {{read of object outside its lifetime}}
+                                // expected-note {{read of uninitialized object}}
 
   class Foo {
   public:
Index: clang/test/AST/Interp/literals.cpp
===================================================================
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -515,10 +515,10 @@
     T a;
     if constexpr (Inc)
       ++a; // ref-note 2{{increment of uninitialized}} \
-           // expected-note 2{{increment of object outside its lifetime}}
+           // expected-note 2{{increment of uninitialized}}
     else
       --a; // ref-note 2{{decrement of uninitialized}} \
-           // expected-note 2{{decrement of object outside its lifetime}}
+           // expected-note 2{{decrement of uninitialized}}
     return 1;
   }
   static_assert(uninit<int, true>(), ""); // ref-error {{not an integral constant expression}} \
Index: clang/test/AST/Interp/cxx20.cpp
===================================================================
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -59,8 +59,7 @@
 constexpr int unInitLocal() {
   int a;
   return a; // ref-note {{read of uninitialized object}} \
-            // expected-note {{read of object outside its lifetime}}
-            // FIXME: ^^^ Wrong diagnostic.
+            // expected-note {{read of uninitialized object}}
 }
 static_assert(unInitLocal() == 0, ""); // ref-error {{not an integral constant expression}} \
                                        // ref-note {{in call to 'unInitLocal()'}} \
@@ -76,7 +75,7 @@
 
 constexpr int initializedLocal2() {
   int a[2];
-  return *a; // expected-note {{read of object outside its lifetime}} \
+  return *a; // expected-note {{read of uninitialized object is not allowed in a constant expression}} \
              // ref-note {{read of uninitialized object is not allowed in a constant expression}}
 }
 static_assert(initializedLocal2() == 20); // expected-error {{not an integral constant expression}} \
@@ -89,7 +88,7 @@
 constexpr int initializedLocal3() {
   Int i;
   return i.a; // ref-note {{read of uninitialized object is not allowed in a constant expression}} \
-              // expected-note {{read of object outside its lifetime}}
+              // expected-note {{read of uninitialized object}}
 }
 static_assert(initializedLocal3() == 20); // expected-error {{not an integral constant expression}} \
                                           // expected-note {{in call to}} \
@@ -315,7 +314,7 @@
 
   static_assert(Final{1, 2, 3}.c == 3, ""); // OK
   static_assert(Final{1, 2, 3}.a == 0, ""); // expected-error {{not an integral constant expression}} \
-                                            // expected-note {{read of object outside its lifetime}} \
+                                            // expected-note {{read of uninitialized object}}
                                             // ref-error {{not an integral constant expression}} \
                                             // ref-note {{read of uninitialized object}}
 
@@ -337,7 +336,7 @@
   static_assert(Final2{1, 2, 3}.c == 3, ""); // OK
   static_assert(Final2{1, 2, 3}.b == 2, ""); // OK
   static_assert(Final2{1, 2, 3}.a == 0, ""); // expected-error {{not an integral constant expression}} \
-                                             // expected-note {{read of object outside its lifetime}} \
+                                             // expected-note {{read of uninitialized object}}
                                              // ref-error {{not an integral constant expression}} \
                                              // ref-note {{read of uninitialized object}}
 
@@ -356,7 +355,7 @@
   static_assert(Final3{1, 2, 3}.c == 3, ""); // OK
   static_assert(Final3{1, 2, 3}.b == 2, ""); // OK
   static_assert(Final3{1, 2, 3}.a == 0, ""); // expected-error {{not an integral constant expression}} \
-                                             // expected-note {{read of object outside its lifetime}} \
+                                             // expected-note {{read of uninitialized object}}
                                              // ref-error {{not an integral constant expression}} \
                                              // ref-note {{read of uninitialized object}}
 };
Index: clang/test/AST/Interp/constexpr-nqueens.cpp
===================================================================
--- clang/test/AST/Interp/constexpr-nqueens.cpp
+++ clang/test/AST/Interp/constexpr-nqueens.cpp
@@ -18,7 +18,7 @@
     Failed(Failed) {}
   constexpr Board addQueen(int Row, int Col) const {
     return Board(State | ((uint64_t)Row << (Col * 4))); // ref-note {{read of uninitialized object}} \
-                                                        // expected-note {{read of object outside its lifetime}}
+                                                        // expected-note {{read of uninitialized object}}
   }
   constexpr int getQueenRow(int Col) const {
     return (State >> (Col * 4)) & 0xf;
Index: clang/lib/AST/Interp/Interp.cpp
===================================================================
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -261,7 +261,7 @@
 
   if (!S.checkingPotentialConstantExpression()) {
     const SourceInfo &Loc = S.Current->getSource(OpPC);
-    S.FFDiag(Loc, diag::note_constexpr_access_uninit) << AK << false;
+    S.FFDiag(Loc, diag::note_constexpr_access_uninit) << AK << /*uninitialized=*/true;
   }
   return false;
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to