Files
TheRock/compiler/amd-llvm/clang/test/CodeGenCXX/reference-temporary-subobject.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

53 lines
2.3 KiB
C++

// Tests that lifetime-extended temporaries whose backing storage is a
// subobject (member or base) are always emitted as `internal global`, never
// 'internal constant', regardless of the cv-qualification on the reference.
//
// In C++98, skipRValueSubobjectAdjustments is used for rvalue subobject
// adjustments. The MaterializeTemporaryExpr ends up with the type of the
// reference (e.g. `const int`), not the type of the backing store (e.g. `S`).
// hasSameUnqualifiedType detects this mismatch and correctly falls back to
// Init->getType(), preventing the backing store from being marked constant.
//
// RUN: %clang_cc1 -std=c++98 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
// RUN: %clang_cc1 -std=c++11 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
// RUN: %clang_cc1 -std=c++98 -triple x86_64-linux-gnu -emit-llvm -o - %s -fexperimental-new-constant-interpreter | FileCheck %s
// RUN: %clang_cc1 -std=c++11 -triple x86_64-linux-gnu -emit-llvm -o - %s -fexperimental-new-constant-interpreter | FileCheck %s
// `const int &` bound to a member of an S temporary.
// The backing store is the whole S object, which can't be stored const.
struct MemberS { int x, y; };
const int &member_ref = MemberS().x;
// CHECK: @_ZGR10member_ref_ = internal global %struct.MemberS
// Binding a `const int &` to a mutable member.
// The backing store is the whole object (with a mutable member), so it
// must remain writable.
struct MutableS {
mutable int m;
MutableS() : m(1) {}
};
const int &mutable_member_ref = MutableS().m;
void write_mutable() { const_cast<int &>(mutable_member_ref) = 5; }
// CHECK: @_ZGR18mutable_member_ref_ = internal global %struct.MutableS
// `const Base &` bound to a Derived temporary.
// Non-constexpr constructors mean no constant initializer is possible, and
// the backing store is the full Derived object.
struct Base { int b; Base() : b(11) {} };
struct Derived : Base { int d; Derived() : Base(), d(22) {} };
const Base &base_ref = Derived();
// CHECK: @_ZGR8base_ref_ = internal global %struct.Derived
// Same as above but using a plain member instead of a base class.
struct Pair { int a, c; Pair() : a(33), c(44) {} };
const int &pair_member_ref = Pair().a;
// CHECK: @_ZGR15pair_member_ref_ = internal global %struct.Pair