Skip to content

[clang][bytecode] Fix non-defaulted union copy/move ctors#199394

Merged
tbaederr merged 1 commit into
llvm:mainfrom
tbaederr:union-copy-ctor
May 27, 2026
Merged

[clang][bytecode] Fix non-defaulted union copy/move ctors#199394
tbaederr merged 1 commit into
llvm:mainfrom
tbaederr:union-copy-ctor

Conversation

@tbaederr
Copy link
Copy Markdown
Contributor

They are like regular record ctors.

@llvmorg-github-actions llvmorg-github-actions Bot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels May 24, 2026
@llvmorg-github-actions
Copy link
Copy Markdown

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

They are like regular record ctors.


Full diff: https://github.com/llvm/llvm-project/pull/199394.diff

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Compiler.cpp (+2-2)
  • (modified) clang/test/AST/ByteCode/unions.cpp (+12)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 4d13cd7139f83..1e58d91861ad5 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6856,8 +6856,8 @@ bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) {
     return false;
   bool IsUnion = R->isUnion();
 
-  // Union copy and move ctors are special.
-  if (IsUnion && Ctor->isCopyOrMoveConstructor()) {
+  // Default union copy and move ctors are special.
+  if (IsUnion && Ctor->isCopyOrMoveConstructor() && Ctor->isDefaulted()) {
     LocOverrideScope<Emitter> LOS(this, SourceInfo{});
 
     // No special case for NumFields == 0 here, so the Memcpy op
diff --git a/clang/test/AST/ByteCode/unions.cpp b/clang/test/AST/ByteCode/unions.cpp
index 399c4c891be00..17d868325f1a7 100644
--- a/clang/test/AST/ByteCode/unions.cpp
+++ b/clang/test/AST/ByteCode/unions.cpp
@@ -386,6 +386,18 @@ namespace CopyCtor {
   static_assert(y.a == 42, "");
   static_assert(y.b == 42, ""); // both-error {{constant expression}} \
                                 // both-note {{'b' of union with active member 'a'}}
+
+  /// Non-defaulted copy ctor.
+  union U2 {
+    int a;
+    constexpr U() : a(100) {}
+    constexpr U(const U &u) {
+      a = 20;
+    };
+  };
+  constexpr U u2;
+  constexpr U u22(u2);
+  static_assert(u22.a == 20);
 }
 
 namespace UnionInBase {

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 24, 2026

🐧 Linux x64 Test Results

  • 118034 tests passed
  • 4767 tests skipped

✅ The build succeeded and all tests passed.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 24, 2026

🪟 Windows x64 Test Results

  • 55646 tests passed
  • 2601 tests skipped

✅ The build succeeded and all tests passed.

@tbaederr tbaederr merged commit 22ba468 into llvm:main May 27, 2026
10 checks passed

// Union copy and move ctors are special.
if (IsUnion && Ctor->isCopyOrMoveConstructor()) {
// Default union copy and move ctors are special.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Default union copy and move ctors are special.
// Defaulted union copy and move ctors are special.

@llvm-ci
Copy link
Copy Markdown

llvm-ci commented May 27, 2026

LLVM Buildbot has detected a new failure on builder intel-sycl-gpu running on intel-sycl-gpu-01 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/225/builds/8896

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: 1200 seconds without output running [b'ninja', b'check-all'], attempting to kill
******************** TEST 'libomptarget :: spirv64-intel :: offloading/strided_update/strided_update_struct_partial_to.c' FAILED ********************
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 1
/home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./bin/clang -fopenmp    -I /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/llvm-project/offload/test -I /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/runtimes/runtimes-bins/openmp/runtime/src -L /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./lib/x86_64-unknown-linux-gnu -L /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./lib/x86_64-unknown-linux-gnu -L /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./lib -L /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/runtimes/runtimes-bins/openmp/runtime/src  -Wl,-rpath,/home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./lib/x86_64-unknown-linux-gnu -Wl,-rpath,/home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./lib/x86_64-unknown-linux-gnu -Wl,-rpath,/home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./lib  -fopenmp-targets=spirv64-intel /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/llvm-project/offload/test/offloading/strided_update/strided_update_struct_partial_to.c -o /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/runtimes/runtimes-bins/offload/test/spirv64-intel/offloading/strided_update/Output/strided_update_struct_partial_to.c.tmp && /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/runtimes/runtimes-bins/offload/test/spirv64-intel/offloading/strided_update/Output/strided_update_struct_partial_to.c.tmp | /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./bin/FileCheck /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/llvm-project/offload/test/offloading/strided_update/strided_update_struct_partial_to.c
# executed command: /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./bin/clang -fopenmp -I /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/llvm-project/offload/test -I /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/runtimes/runtimes-bins/openmp/runtime/src -L /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./lib/x86_64-unknown-linux-gnu -L /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./lib/x86_64-unknown-linux-gnu -L /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./lib -L /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./lib/x86_64-unknown-linux-gnu -Wl,-rpath,/home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./lib/x86_64-unknown-linux-gnu -Wl,-rpath,/home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./lib -fopenmp-targets=spirv64-intel /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/llvm-project/offload/test/offloading/strided_update/strided_update_struct_partial_to.c -o /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/runtimes/runtimes-bins/offload/test/spirv64-intel/offloading/strided_update/Output/strided_update_struct_partial_to.c.tmp
# executed command: /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/runtimes/runtimes-bins/offload/test/spirv64-intel/offloading/strided_update/Output/strided_update_struct_partial_to.c.tmp
# .---command stderr------------
# | PluginInterface error: Failure to run target region 0x60da4263f670 in device 0: "unknown or internal error" zeCommandListAppendLaunchKernel failed with error 1879048195, ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY
# | omptarget error: Executing target region abort target.
# | omptarget error: Consult https://openmp.llvm.org/design/Runtimes.html for debugging options.
# | omptarget error: Source location information not present. Compile with -g or -gline-tables-only.
# | omptarget fatal error 1: failure of target construct while offloading is mandatory
# `-----------------------------
# error: command failed with exit status: -6
# executed command: /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./bin/FileCheck /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/llvm-project/offload/test/offloading/strided_update/strided_update_struct_partial_to.c
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/build/./bin/FileCheck /home/test-user/llvm-buildbot-worker/intel-sycl-gpu/llvm-project/offload/test/offloading/strided_update/strided_update_struct_partial_to.c
# `-----------------------------
# error: command failed with exit status: 2

--

********************


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants