[clang] 3c67c22 - [clang][Interp] Test non-active union access
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Wed May 22 08:31:50 PDT 2024
Author: Timm Bäder
Date: 2024-05-22T17:31:34+02:00
New Revision: 3c67c227f2e16accd3cdb3aeb4c845edabd2f6c4
URL: https://github.com/llvm/llvm-project/commit/3c67c227f2e16accd3cdb3aeb4c845edabd2f6c4
DIFF: https://github.com/llvm/llvm-project/commit/3c67c227f2e16accd3cdb3aeb4c845edabd2f6c4.diff
LOG: [clang][Interp] Test non-active union access
Added:
Modified:
clang/lib/AST/Interp/Interp.cpp
clang/test/AST/Interp/unions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 1ed2ff30bdd05..cac678352e2ce 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -457,10 +457,10 @@ bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
return false;
if (!CheckRange(S, OpPC, Ptr, AK_Read))
return false;
- if (!CheckInitialized(S, OpPC, Ptr, AK_Read))
- return false;
if (!CheckActive(S, OpPC, Ptr, AK_Read))
return false;
+ if (!CheckInitialized(S, OpPC, Ptr, AK_Read))
+ return false;
if (!CheckTemporary(S, OpPC, Ptr, AK_Read))
return false;
if (!CheckMutable(S, OpPC, Ptr))
diff --git a/clang/test/AST/Interp/unions.cpp b/clang/test/AST/Interp/unions.cpp
index 08ca39c3cb089..004e500de064f 100644
--- a/clang/test/AST/Interp/unions.cpp
+++ b/clang/test/AST/Interp/unions.cpp
@@ -1,8 +1,6 @@
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=expected,both %s
// RUN: %clang_cc1 -verify=ref,both %s
-// both-no-diagnostics
-
union U {
int a;
int b;
@@ -10,5 +8,5 @@ union U {
constexpr U a = {12};
static_assert(a.a == 12, "");
-
-
+static_assert(a.b == 0, ""); // both-error {{not an integral constant expression}} \
+ // both-note {{read of member 'b' of union with active member 'a'}}
More information about the cfe-commits
mailing list