[clang] 49f0607 - [clang][bytecode] Fix union copy/move operator active check (#132238)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 20 11:08:58 PDT 2025
Author: Timm Baeder
Date: 2025-03-20T19:08:55+01:00
New Revision: 49f06075a6d298bd13564c9bffcf51281bed4962
URL: https://github.com/llvm/llvm-project/commit/49f06075a6d298bd13564c9bffcf51281bed4962
DIFF: https://github.com/llvm/llvm-project/commit/49f06075a6d298bd13564c9bffcf51281bed4962.diff
LOG: [clang][bytecode] Fix union copy/move operator active check (#132238)
Don't call CheckActive for copy/move operators. They will activate the
union member.
Added:
Modified:
clang/lib/AST/ByteCode/Function.cpp
clang/lib/AST/ByteCode/Function.h
clang/lib/AST/ByteCode/Interp.cpp
clang/test/AST/ByteCode/unions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Function.cpp b/clang/lib/AST/ByteCode/Function.cpp
index fa803070c821d..764aa4a851cf4 100644
--- a/clang/lib/AST/ByteCode/Function.cpp
+++ b/clang/lib/AST/ByteCode/Function.cpp
@@ -35,10 +35,12 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
Kind = FunctionKind::Dtor;
} else if (const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
Virtual = MD->isVirtual();
- if (IsLambdaStaticInvoker) // MD->isLambdaStaticInvoker())
+ if (IsLambdaStaticInvoker)
Kind = FunctionKind::LambdaStaticInvoker;
else if (clang::isLambdaCallOperator(F))
Kind = FunctionKind::LambdaCallOperator;
+ else if (MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())
+ Kind = FunctionKind::CopyOrMoveOperator;
}
}
}
diff --git a/clang/lib/AST/ByteCode/Function.h b/clang/lib/AST/ByteCode/Function.h
index cdf98f9e67dde..c114cfe5ba29a 100644
--- a/clang/lib/AST/ByteCode/Function.h
+++ b/clang/lib/AST/ByteCode/Function.h
@@ -91,6 +91,7 @@ class Function final {
Dtor,
LambdaStaticInvoker,
LambdaCallOperator,
+ CopyOrMoveOperator,
};
using ParamDescriptor = std::pair<PrimType, Descriptor *>;
@@ -159,6 +160,10 @@ class Function final {
bool isConstructor() const { return Kind == FunctionKind::Ctor; }
/// Checks if the function is a destructor.
bool isDestructor() const { return Kind == FunctionKind::Dtor; }
+ /// Checks if the function is copy or move operator.
+ bool isCopyOrMoveOperator() const {
+ return Kind == FunctionKind::CopyOrMoveOperator;
+ }
/// Returns whether this function is a lambda static invoker,
/// which we generate custom byte code for.
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index b4ea825ce472c..a3a2a7c82a47f 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1449,6 +1449,7 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func,
if (!CheckInvoke(S, OpPC, ThisPtr))
return cleanup();
if (!Func->isConstructor() && !Func->isDestructor() &&
+ !Func->isCopyOrMoveOperator() &&
!CheckActive(S, OpPC, ThisPtr, AK_MemberCall))
return false;
}
diff --git a/clang/test/AST/ByteCode/unions.cpp b/clang/test/AST/ByteCode/unions.cpp
index 70524fd36bcc2..66b8389606b85 100644
--- a/clang/test/AST/ByteCode/unions.cpp
+++ b/clang/test/AST/ByteCode/unions.cpp
@@ -570,4 +570,33 @@ namespace ActiveDestroy {
static_assert(foo2());
}
+namespace MoveOrAssignOp {
+ struct min_pointer {
+ int *ptr_;
+ constexpr min_pointer(int *p) : ptr_(p) {}
+ min_pointer() = default;
+ };
+
+ class F {
+ struct __long {
+ min_pointer __data_;
+ };
+ union __rep {
+ int __s;
+ __long __l;
+ } __rep_;
+
+ public:
+ constexpr F() {
+ __rep_ = __rep();
+ __rep_.__l.__data_ = nullptr;
+ }
+ };
+
+ constexpr bool foo() {
+ F f{};
+ return true;
+ }
+ static_assert(foo());
+}
#endif
More information about the cfe-commits
mailing list