Author: Timm Bäder Date: 2023-07-09T16:27:49+02:00 New Revision: c54ff51be9c1192214eb56fc5c8dea2b73557406
URL: https://github.com/llvm/llvm-project/commit/c54ff51be9c1192214eb56fc5c8dea2b73557406 DIFF: https://github.com/llvm/llvm-project/commit/c54ff51be9c1192214eb56fc5c8dea2b73557406.diff LOG: [clang][Interp] Emit correct diagnostic for uninitialized reads Differential Revision: https://reviews.llvm.org/D154758 Added: Modified: 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 Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp index cf9e5b8ea6bd29..4917f43f9512ec 100644 --- a/clang/lib/AST/Interp/Interp.cpp +++ b/clang/lib/AST/Interp/Interp.cpp @@ -239,7 +239,8 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr, 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; } diff --git a/clang/test/AST/Interp/constexpr-nqueens.cpp b/clang/test/AST/Interp/constexpr-nqueens.cpp index 8b8b608fc8c57c..971f99a032b665 100644 --- a/clang/test/AST/Interp/constexpr-nqueens.cpp +++ b/clang/test/AST/Interp/constexpr-nqueens.cpp @@ -18,7 +18,7 @@ struct Board { 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; diff --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp index 87c32e42d053e5..a7d7705c1cefa6 100644 --- a/clang/test/AST/Interp/cxx20.cpp +++ b/clang/test/AST/Interp/cxx20.cpp @@ -59,8 +59,7 @@ static_assert(pointerAssign2() == 12, ""); 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 @@ static_assert(initializedLocal() == 20); 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 @@ struct Int { int a; }; 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 @@ namespace BaseInit { 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 @@ namespace BaseInit { 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 @@ namespace BaseInit { 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}} }; diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index 3c81c6ff04e6ff..882742b2314b4c 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -467,10 +467,10 @@ namespace IncDec { 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}} \ diff --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp index 8d976551cdf59b..5fd423eff025be 100644 --- a/clang/test/AST/Interp/records.cpp +++ b/clang/test/AST/Interp/records.cpp @@ -404,7 +404,7 @@ namespace DeriveFailures { 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 { @@ -467,7 +467,7 @@ namespace DeclRefs { 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: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits