Author: Andy Kaylor Date: 2025-09-05T13:19:43-07:00 New Revision: e1021bb9bdcbd75c0fa6164628b6f791d696214b
URL: https://github.com/llvm/llvm-project/commit/e1021bb9bdcbd75c0fa6164628b6f791d696214b DIFF: https://github.com/llvm/llvm-project/commit/e1021bb9bdcbd75c0fa6164628b6f791d696214b.diff LOG: [CIR] Implement CXX field default initialization (#157140) This adds the code needed to handle default initialization for fields of various types. Added: clang/test/CIR/CodeGen/cxx-default-init.cpp Modified: clang/lib/CIR/CodeGen/CIRGenClass.cpp clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp clang/lib/CIR/CodeGen/CIRGenFunction.h Removed: ################################################################################ diff --git a/clang/lib/CIR/CodeGen/CIRGenClass.cpp b/clang/lib/CIR/CodeGen/CIRGenClass.cpp index ecfcd9f820a22..0a8dc2b62fe21 100644 --- a/clang/lib/CIR/CodeGen/CIRGenClass.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenClass.cpp @@ -517,17 +517,23 @@ void CIRGenFunction::emitInitializerForField(FieldDecl *field, LValue lhs, QualType fieldType = field->getType(); switch (getEvaluationKind(fieldType)) { case cir::TEK_Scalar: - if (lhs.isSimple()) + if (lhs.isSimple()) { emitExprAsInit(init, field, lhs, false); - else - cgm.errorNYI(field->getSourceRange(), - "emitInitializerForField: non-simple scalar"); + } else { + RValue rhs = RValue::get(emitScalarExpr(init)); + emitStoreThroughLValue(rhs, lhs); + } break; case cir::TEK_Complex: - cgm.errorNYI(field->getSourceRange(), "emitInitializerForField: complex"); + emitComplexExprIntoLValue(init, lhs, /*isInit=*/true); break; case cir::TEK_Aggregate: { - cgm.errorNYI(field->getSourceRange(), "emitInitializerForField: aggregate"); + assert(!cir::MissingFeatures::aggValueSlotGC()); + assert(!cir::MissingFeatures::sanitizers()); + AggValueSlot slot = AggValueSlot::forLValue( + lhs, AggValueSlot::IsDestructed, AggValueSlot::IsNotAliased, + getOverlapForFieldInit(field), AggValueSlot::IsNotZeroed); + emitAggExpr(init, slot); break; } } diff --git a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp index 2e7fb9843b135..dc34d2b3baa8d 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp @@ -91,7 +91,10 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> { void visitCXXParenListOrInitListExpr(Expr *e, ArrayRef<Expr *> args, FieldDecl *initializedFieldInUnion, Expr *arrayFiller); - + void VisitCXXDefaultInitExpr(CXXDefaultInitExpr *die) { + CIRGenFunction::CXXDefaultInitExprScope Scope(cgf, die); + Visit(die->getExpr()); + } void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *e) { assert(!cir::MissingFeatures::aggValueSlotDestructedFlag()); Visit(e->getSubExpr()); @@ -232,10 +235,6 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> { cgf.cgm.errorNYI(dae->getSourceRange(), "AggExprEmitter: VisitCXXDefaultArgExpr"); } - void VisitCXXDefaultInitExpr(CXXDefaultInitExpr *die) { - cgf.cgm.errorNYI(die->getSourceRange(), - "AggExprEmitter: VisitCXXDefaultInitExpr"); - } void VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *e) { cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCXXInheritedCtorInitExpr"); @@ -794,6 +793,26 @@ void CIRGenFunction::emitAggregateCopy(LValue dest, LValue src, QualType ty, assert(!cir::MissingFeatures::opTBAA()); } +// TODO(cir): This could be shared with classic codegen. +AggValueSlot::Overlap_t +CIRGenFunction::getOverlapForFieldInit(const FieldDecl *fd) { + if (!fd->hasAttr<NoUniqueAddressAttr>() || !fd->getType()->isRecordType()) + return AggValueSlot::DoesNotOverlap; + + // If the field lies entirely within the enclosing class's nvsize, its tail + // padding cannot overlap any already-initialized object. (The only subobjects + // with greater addresses that might already be initialized are vbases.) + const RecordDecl *classRD = fd->getParent(); + const ASTRecordLayout &layout = getContext().getASTRecordLayout(classRD); + if (layout.getFieldOffset(fd->getFieldIndex()) + + getContext().getTypeSize(fd->getType()) <= + (uint64_t)getContext().toBits(layout.getNonVirtualSize())) + return AggValueSlot::DoesNotOverlap; + + // The tail padding may contain values we need to preserve. + return AggValueSlot::MayOverlap; +} + LValue CIRGenFunction::emitAggExprToLValue(const Expr *e) { assert(hasAggregateEvaluationKind(e->getType()) && "Invalid argument!"); Address temp = createMemTemp(e->getType(), getLoc(e->getSourceRange())); diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp index c90bd2126c754..d678ea0212aa5 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp @@ -201,9 +201,8 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> { return {}; } mlir::Value VisitCXXDefaultInitExpr(CXXDefaultInitExpr *die) { - cgf.cgm.errorNYI(die->getExprLoc(), - "ComplexExprEmitter VisitCXXDefaultInitExpr"); - return {}; + CIRGenFunction::CXXDefaultInitExprScope scope(cgf, die); + return Visit(die->getExpr()); } mlir::Value VisitExprWithCleanups(ExprWithCleanups *e) { cgf.cgm.errorNYI(e->getExprLoc(), diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index 0e000cc494063..754ef79392916 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -661,6 +661,11 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> { mlir::Value VisitUnaryImag(const UnaryOperator *e); + mlir::Value VisitCXXDefaultInitExpr(CXXDefaultInitExpr *die) { + CIRGenFunction::CXXDefaultInitExprScope scope(cgf, die); + return Visit(die->getExpr()); + } + mlir::Value VisitCXXThisExpr(CXXThisExpr *te) { return cgf.loadCXXThis(); } mlir::Value VisitExprWithCleanups(ExprWithCleanups *e); diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h b/clang/lib/CIR/CodeGen/CIRGenFunction.h index 7a885c109794c..de9e3541ed840 100644 --- a/clang/lib/CIR/CodeGen/CIRGenFunction.h +++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h @@ -25,7 +25,9 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/BaseSubobject.h" #include "clang/AST/CharUnits.h" +#include "clang/AST/CurrentSourceLocExprScope.h" #include "clang/AST/Decl.h" +#include "clang/AST/ExprCXX.h" #include "clang/AST/Stmt.h" #include "clang/AST/Type.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" @@ -599,6 +601,12 @@ class CIRGenFunction : public CIRGenTypeCache { /// true when both vcall CFI and whole-program-vtables are enabled. bool shouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *rd); + /// Source location information about the default argument or member + /// initializer expression we're evaluating, if any. + clang::CurrentSourceLocExprScope curSourceLocExprScope; + using SourceLocExprScopeGuard = + clang::CurrentSourceLocExprScope::SourceLocExprScopeGuard; + /// A scope within which we are constructing the fields of an object which /// might use a CXXDefaultInitExpr. This stashes away a 'this' value to use if /// we need to evaluate the CXXDefaultInitExpr within the evaluation. @@ -617,6 +625,29 @@ class CIRGenFunction : public CIRGenTypeCache { Address oldCXXDefaultInitExprThis; }; + /// The scope of a CXXDefaultInitExpr. Within this scope, the value of 'this' + /// is overridden to be the object under construction. + class CXXDefaultInitExprScope { + public: + CXXDefaultInitExprScope(CIRGenFunction &cgf, const CXXDefaultInitExpr *e) + : cgf{cgf}, oldCXXThisValue(cgf.cxxThisValue), + oldCXXThisAlignment(cgf.cxxThisAlignment), + sourceLocScope(e, cgf.curSourceLocExprScope) { + cgf.cxxThisValue = cgf.cxxDefaultInitExprThis.getPointer(); + cgf.cxxThisAlignment = cgf.cxxDefaultInitExprThis.getAlignment(); + } + ~CXXDefaultInitExprScope() { + cgf.cxxThisValue = oldCXXThisValue; + cgf.cxxThisAlignment = oldCXXThisAlignment; + } + + public: + CIRGenFunction &cgf; + mlir::Value oldCXXThisValue; + clang::CharUnits oldCXXThisAlignment; + SourceLocExprScopeGuard sourceLocScope; + }; + LValue makeNaturalAlignPointeeAddrLValue(mlir::Value v, clang::QualType t); LValue makeNaturalAlignAddrLValue(mlir::Value val, QualType ty); @@ -658,6 +689,8 @@ class CIRGenFunction : public CIRGenTypeCache { const clang::CXXRecordDecl *rd); void initializeVTablePointer(mlir::Location loc, const VPtr &vptr); + AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *fd); + /// Return the address of a local variable. Address getAddrOfLocalVar(const clang::VarDecl *vd) { auto it = localDeclMap.find(vd); diff --git a/clang/test/CIR/CodeGen/cxx-default-init.cpp b/clang/test/CIR/CodeGen/cxx-default-init.cpp new file mode 100644 index 0000000000000..06d3a27f61cc9 --- /dev/null +++ b/clang/test/CIR/CodeGen/cxx-default-init.cpp @@ -0,0 +1,245 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -mconstructor-aliases -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -mconstructor-aliases -fclangir -emit-llvm %s -o %t-cir.ll +// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -mconstructor-aliases -emit-llvm %s -o %t.ll +// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG + +struct Pair { + int a; + int b; +}; + +struct ZeroInit { + int i{}; + Pair p{}; + int arr[4]{}; + float _Complex c{}; + unsigned bf : 8 {}; + ZeroInit() = default; +}; + +// CIR: cir.func{{.*}} @_ZN8ZeroInitC2Ev(%[[THIS_ARG:.*]]: !cir.ptr<!rec_ZeroInit> {{.*}}) +// CIR: %[[ITER:.*]] = cir.alloca {{.*}} ["arrayinit.temp"] +// CIR: %[[THIS:.*]] = cir.load %[[THIS_ALLOCA:.*]] +// CIR: %[[I:.*]] = cir.get_member %[[THIS]][0] {name = "i"} +// CIR: %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i +// CIR: cir.store{{.*}} %[[ZERO]], %[[I]] +// CIR: %[[P:.*]] = cir.get_member %[[THIS]][1] {name = "p"} +// CIR: %[[P_A:.*]] = cir.get_member %[[P]][0] {name = "a"} +// CIR: %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i +// CIR: cir.store{{.*}} %[[ZERO]], %[[P_A]] +// CIR: %[[P_B:.*]] = cir.get_member %[[P]][1] {name = "b"} +// CIR: %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i +// CIR: cir.store{{.*}} %[[ZERO]], %[[P_B]] +// CIR: %[[ARR:.*]] = cir.get_member %[[THIS]][2] {name = "arr"} +// CIR: %[[ARR_BEGIN:.*]] = cir.cast(array_to_ptrdecay, %[[ARR]] : !cir.ptr<!cir.array<!s32i x 4>>), !cir.ptr<!s32i> +// CIR: cir.store{{.*}} %[[ARR_BEGIN]], %[[ITER]] +// CIR: %[[FOUR:.*]] = cir.const #cir.int<4> : !s64i +// CIR: %[[END:.*]] = cir.ptr_stride(%[[ARR_BEGIN]] : !cir.ptr<!s32i>, %[[FOUR]] : !s64i) +// CIR: cir.do { +// CIR: %[[CUR:.*]] = cir.load{{.*}} %[[ITER]] +// CIR: %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i +// CIR: cir.store{{.*}} %[[ZERO]], %[[CUR]] +// CIR: %[[ONE:.*]] = cir.const #cir.int<1> : !s64i +// CIR: %[[NEXT:.*]] = cir.ptr_stride(%[[CUR]] : !cir.ptr<!s32i>, %[[ONE]] : !s64i) +// CIR: cir.store{{.*}} %[[NEXT]], %[[ITER]] +// CIR: cir.yield +// CIR: } while { +// CIR: %[[CUR:.*]] = cir.load{{.*}} %[[ITER]] +// CIR: %[[CMP:.*]] = cir.cmp(ne, %[[CUR]], %[[END]]) +// CIR: cir.condition(%[[CMP]]) +// CIR: } +// CIR: %[[C:.*]] = cir.get_member %[[THIS]][3] {name = "c"} +// CIR: %[[ZERO:.*]] = cir.const #cir.zero : !cir.complex<!cir.float> +// CIR: cir.store{{.*}} %[[ZERO]], %[[C]] +// CIR: %[[BF:.*]] = cir.get_member %[[THIS]][4] {name = "bf"} +// CIR: %[[ZERO:.*]] = cir.const #cir.int<0> : !u32i +// CIR: %[[BF_VAL:.*]] = cir.set_bitfield{{.*}} (#bfi_bf, %[[BF]] : !cir.ptr<!u8i>, %[[ZERO]] : !u32i) + +// LLVM: define{{.*}} void @_ZN8ZeroInitC2Ev(ptr %[[THIS_ARG:.*]]) +// LLVM: %[[THIS_ALLOCA:.*]] = alloca ptr +// LLVM: %[[ITER:.*]] = alloca ptr +// LLVM: %[[THIS:.*]] = load ptr, ptr %[[THIS_ALLOCA]] +// LLVM: %[[I:.*]] = getelementptr %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 0 +// LLVM: store i32 0, ptr %[[I]] +// LLVM: %[[P:.*]] = getelementptr %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 1 +// LLVM: %[[P_A:.*]] = getelementptr %struct.Pair, ptr %[[P]], i32 0, i32 0 +// LLVM: store i32 0, ptr %[[P_A]] +// LLVM: %[[P_B:.*]] = getelementptr %struct.Pair, ptr %[[P]], i32 0, i32 1 +// LLVM: store i32 0, ptr %[[P_B]] +// LLVM: %[[ARR:.*]] = getelementptr %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 2 +// LLVM: %[[ARR_BEGIN:.*]] = getelementptr i32, ptr %[[ARR]], i32 0 +// LLVM: store ptr %[[ARR_BEGIN]], ptr %[[ITER]] +// LLVM: %[[ARR_END:.*]] = getelementptr i32, ptr %[[ARR_BEGIN]], i64 4 +// LLVM: br label %[[LOOP_BODY:.*]] +// LLVM: [[LOOP_COND:.*]]: +// LLVM: %[[CUR:.*]] = load ptr, ptr %[[ITER]] +// LLVM: %[[CMP:.*]] = icmp ne ptr %[[CUR]], %[[ARR_END]] +// LLVM: br i1 %[[CMP]], label %[[LOOP_BODY]], label %[[LOOP_END:.*]] +// LLVM: [[LOOP_BODY]]: +// LLVM: %[[CUR:.*]] = load ptr, ptr %[[ITER]] +// LLVM: store i32 0, ptr %[[CUR]] +// LLVM: %[[NEXT:.*]] = getelementptr i32, ptr %[[CUR]], i64 1 +// LLVM: store ptr %[[NEXT]], ptr %[[ITER]] +// LLVM: br label %[[LOOP_COND]] +// LLVM: [[LOOP_END]]: +// LLVM: %[[C:.*]] = getelementptr %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 3 +// LLVM: store { float, float } zeroinitializer, ptr %[[C]] +// LLVM: %[[BF:.*]] = getelementptr %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 4 +// LLVM: store i8 0, ptr %[[BF]] + +// OGCG: define{{.*}} void @_ZN8ZeroInitC2Ev(ptr {{.*}} %[[THIS_ARG:.*]]) +// OGCG: %[[THIS:.*]] = load ptr, ptr %[[THIS_ALLOCA:.*]] +// OGCG: %[[I:.*]] = getelementptr inbounds nuw %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 0 +// OGCG: store i32 0, ptr %[[I]] +// OGCG: %[[P:.*]] = getelementptr inbounds nuw %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 1 +// OGCG: %[[P_A:.*]] = getelementptr inbounds nuw %struct.Pair, ptr %[[P]], i32 0, i32 0 +// OGCG: store i32 0, ptr %[[P_A]] +// OGCG: %[[P_B:.*]] = getelementptr inbounds nuw %struct.Pair, ptr %[[P]], i32 0, i32 1 +// OGCG: store i32 0, ptr %[[P_B]] +// OGCG: %[[ARR:.*]] = getelementptr inbounds nuw %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 2 +// OGCG: %[[ARR_END:.*]] = getelementptr inbounds i32, ptr %[[ARR]], i64 4 +// OGCG: br label %[[LOOP_BODY:.*]] +// OGCG: [[LOOP_BODY]]: +// OGCG: %[[CUR:.*]] = phi ptr [ %[[ARR]], %entry ], [ %[[NEXT:.*]], %[[LOOP_BODY]] ] +// OGCG: store i32 0, ptr %[[CUR]] +// OGCG: %[[NEXT]] = getelementptr inbounds i32, ptr %[[CUR]], i64 1 +// OGCG: %[[CMP:.*]] = icmp eq ptr %[[NEXT]], %[[ARR_END]] +// OGCG: br i1 %[[CMP]], label %[[LOOP_END:.*]], label %[[LOOP_BODY]] +// OGCG: [[LOOP_END]]: +// OGCG: %[[C:.*]] = getelementptr inbounds nuw %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 3 +// OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[C]], i32 0, i32 0 +// OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[C]], i32 0, i32 1 +// OGCG: store float 0.000000e+00, ptr %[[C_REAL_PTR]] +// OGCG: store float 0.000000e+00, ptr %[[C_IMAG_PTR]] +// OGCG: %[[BF:.*]] = getelementptr inbounds nuw %struct.ZeroInit, ptr %[[THIS]], i32 0, i32 4 +// OGCG: store i8 0, ptr %[[BF]] + +struct ValueInit { + int i{1}; + Pair p{2, 3}; + int arr[4]{4, 5}; + float _Complex c{6.0f, 7.0f}; + unsigned bf : 8 {0xFF}; + ValueInit() = default; +}; + +// CIR: cir.func{{.*}} @_ZN9ValueInitC2Ev(%[[THIS_ARG:.*]]: !cir.ptr<!rec_ValueInit> {{.*}}) +// CIR: %[[ITER:.*]] = cir.alloca {{.*}} ["arrayinit.temp"] +// CIR: %[[THIS:.*]] = cir.load %[[THIS_ALLOCA:.*]] +// CIR: %[[I:.*]] = cir.get_member %[[THIS]][0] {name = "i"} +// CIR: %[[ONE:.*]] = cir.const #cir.int<1> : !s32i +// CIR: cir.store{{.*}} %[[ONE]], %[[I]] +// CIR: %[[P:.*]] = cir.get_member %[[THIS]][1] {name = "p"} +// CIR: %[[P_A:.*]] = cir.get_member %[[P]][0] {name = "a"} +// CIR: %[[TWO:.*]] = cir.const #cir.int<2> : !s32i +// CIR: cir.store{{.*}} %[[TWO]], %[[P_A]] +// CIR: %[[P_B:.*]] = cir.get_member %[[P]][1] {name = "b"} +// CIR: %[[THREE:.*]] = cir.const #cir.int<3> : !s32i +// CIR: cir.store{{.*}} %[[THREE]], %[[P_B]] +// CIR: %[[ARR:.*]] = cir.get_member %[[THIS]][2] {name = "arr"} +// CIR: %[[ARR_BEGIN:.*]] = cir.cast(array_to_ptrdecay, %[[ARR]] : !cir.ptr<!cir.array<!s32i x 4>>), !cir.ptr<!s32i> +// CIR: %[[FOUR:.*]] = cir.const #cir.int<4> : !s32i +// CIR: cir.store{{.*}} %[[FOUR]], %[[ARR_BEGIN]] +// CIR: %[[ONE:.*]] = cir.const #cir.int<1> : !s64i +// CIR: %[[SECOND:.*]] = cir.ptr_stride(%[[ARR_BEGIN]] : !cir.ptr<!s32i>, %[[ONE]] : !s64i) +// CIR: %[[FIVE:.*]] = cir.const #cir.int<5> : !s32i +// CIR: cir.store{{.*}} %[[FIVE]], %[[SECOND]] +// CIR: %[[ONE:.*]] = cir.const #cir.int<1> : !s64i +// CIR: %[[NEXT:.*]] = cir.ptr_stride(%[[SECOND]] : !cir.ptr<!s32i>, %[[ONE]] : !s64i) +// CIR: cir.store{{.*}} %[[NEXT]], %[[ITER]] +// CIR: %[[FOUR:.*]] = cir.const #cir.int<4> : !s64i +// CIR: %[[END:.*]] = cir.ptr_stride(%[[ARR_BEGIN]] : !cir.ptr<!s32i>, %[[FOUR]] : !s64i) +// CIR: cir.do { +// CIR: %[[CUR:.*]] = cir.load{{.*}} %[[ITER]] +// CIR: %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i +// CIR: cir.store{{.*}} %[[ZERO]], %[[CUR]] +// CIR: %[[ONE:.*]] = cir.const #cir.int<1> : !s64i +// CIR: %[[NEXT:.*]] = cir.ptr_stride(%[[CUR]] : !cir.ptr<!s32i>, %[[ONE]] : !s64i) +// CIR: cir.store{{.*}} %[[NEXT]], %[[ITER]] +// CIR: cir.yield +// CIR: } while { +// CIR: %[[CUR:.*]] = cir.load{{.*}} %[[ITER]] +// CIR: %[[CMP:.*]] = cir.cmp(ne, %[[CUR]], %[[END]]) +// CIR: cir.condition(%[[CMP]]) +// CIR: } +// CIR: %[[C:.*]] = cir.get_member %[[THIS]][3] {name = "c"} +// CIR: %[[FOUR_FIVEI:.*]] = cir.const #cir.const_complex<#cir.fp<6.000000e+00> : !cir.float, #cir.fp<7.000000e+00> +// CIR: cir.store{{.*}} %[[FOUR_FIVEI]], %[[C]] +// CIR: %[[BF:.*]] = cir.get_member %[[THIS]][4] {name = "bf"} +// CIR: %[[FF:.*]] = cir.const #cir.int<255> : !s32i +// CIR: %[[FF_CAST:.*]] = cir.cast(integral, %[[FF]] : !s32i), !u32i +// CIR: %[[BF_VAL:.*]] = cir.set_bitfield{{.*}} (#bfi_bf, %[[BF]] : !cir.ptr<!u8i>, %[[FF_CAST]] : !u32i) + +// LLVM: define{{.*}} void @_ZN9ValueInitC2Ev(ptr %[[THIS_ARG:.*]]) +// LLVM: %[[THIS_ALLOCA:.*]] = alloca ptr +// LLVM: %[[ITER:.*]] = alloca ptr +// LLVM: %[[THIS:.*]] = load ptr, ptr %[[THIS_ALLOCA]] +// LLVM: %[[I:.*]] = getelementptr %struct.ValueInit, ptr %[[THIS]], i32 0, i32 0 +// LLVM: store i32 1, ptr %[[I]] +// LLVM: %[[P:.*]] = getelementptr %struct.ValueInit, ptr %[[THIS]], i32 0, i32 1 +// LLVM: %[[P_A:.*]] = getelementptr %struct.Pair, ptr %[[P]], i32 0, i32 0 +// LLVM: store i32 2, ptr %[[P_A]] +// LLVM: %[[P_B:.*]] = getelementptr %struct.Pair, ptr %[[P]], i32 0, i32 1 +// LLVM: store i32 3, ptr %[[P_B]] +// LLVM: %[[ARR:.*]] = getelementptr %struct.ValueInit, ptr %[[THIS]], i32 0, i32 2 +// LLVM: %[[ARR_BEGIN:.*]] = getelementptr i32, ptr %[[ARR]], i32 0 +// LLVM: store i32 4, ptr %[[ARR_BEGIN]] +// LLVM: %[[ARR_1:.*]] = getelementptr i32, ptr %[[ARR_BEGIN]], i64 1 +// LLVM: store i32 5, ptr %[[ARR_1]] +// LLVM: %[[ARR_2:.*]] = getelementptr i32, ptr %[[ARR_1]], i64 1 +// LLVM: store ptr %[[ARR_2]], ptr %[[ITER]] +// LLVM: %[[ARR_END:.*]] = getelementptr i32, ptr %[[ARR_BEGIN]], i64 4 +// LLVM: br label %[[LOOP_BODY:.*]] +// LLVM: [[LOOP_COND:.*]]: +// LLVM: %[[CUR:.*]] = load ptr, ptr %[[ITER]] +// LLVM: %[[CMP:.*]] = icmp ne ptr %[[CUR]], %[[ARR_END]] +// LLVM: br i1 %[[CMP]], label %[[LOOP_BODY]], label %[[LOOP_END:.*]] +// LLVM: [[LOOP_BODY]]: +// LLVM: %[[CUR:.*]] = load ptr, ptr %[[ITER]] +// LLVM: store i32 0, ptr %[[CUR]] +// LLVM: %[[NEXT:.*]] = getelementptr i32, ptr %[[CUR]], i64 1 +// LLVM: store ptr %[[NEXT]], ptr %[[ITER]] +// LLVM: br label %[[LOOP_COND]] +// LLVM: [[LOOP_END]]: +// LLVM: %[[C:.*]] = getelementptr %struct.ValueInit, ptr %[[THIS]], i32 0, i32 3 +// LLVM: store { float, float } { float 6.000000e+00, float 7.000000e+00 }, ptr %[[C]] +// LLVM: %[[BF:.*]] = getelementptr %struct.ValueInit, ptr %[[THIS]], i32 0, i32 4 +// LLVM: store i8 -1, ptr %[[BF]] + +// OGCG: define{{.*}} void @_ZN9ValueInitC2Ev(ptr {{.*}} %[[THIS_ARG:.*]]) +// OGCG: %[[THIS:.*]] = load ptr, ptr %[[THIS_ALLOCA:.*]] +// OGCG: %[[I:.*]] = getelementptr inbounds nuw %struct.ValueInit, ptr %[[THIS]], i32 0, i32 0 +// OGCG: store i32 1, ptr %[[I]] +// OGCG: %[[P:.*]] = getelementptr inbounds nuw %struct.ValueInit, ptr %[[THIS]], i32 0, i32 1 +// OGCG: %[[P_A:.*]] = getelementptr inbounds nuw %struct.Pair, ptr %[[P]], i32 0, i32 0 +// OGCG: store i32 2, ptr %[[P_A]] +// OGCG: %[[P_B:.*]] = getelementptr inbounds nuw %struct.Pair, ptr %[[P]], i32 0, i32 1 +// OGCG: store i32 3, ptr %[[P_B]] +// OGCG: %[[ARR:.*]] = getelementptr inbounds nuw %struct.ValueInit, ptr %[[THIS]], i32 0, i32 2 +// OGCG: store i32 4, ptr %[[ARR]] +// OGCG: %[[ARR_1:.*]] = getelementptr inbounds i32, ptr %[[ARR]], i64 1 +// OGCG: store i32 5, ptr %[[ARR_1]] +// OGCG: %[[ARR_BEGIN:.*]] = getelementptr inbounds i32, ptr %[[ARR]], i64 2 +// OGCG: %[[ARR_END:.*]] = getelementptr inbounds i32, ptr %[[ARR]], i64 4 +// OGCG: br label %[[LOOP_BODY:.*]] +// OGCG: [[LOOP_BODY]]: +// OGCG: %[[CUR:.*]] = phi ptr [ %[[ARR_BEGIN]], %entry ], [ %[[NEXT:.*]], %[[LOOP_BODY]] ] +// OGCG: store i32 0, ptr %[[CUR]] +// OGCG: %[[NEXT]] = getelementptr inbounds i32, ptr %[[CUR]], i64 1 +// OGCG: %[[CMP:.*]] = icmp eq ptr %[[NEXT]], %[[ARR_END]] +// OGCG: br i1 %[[CMP]], label %[[LOOP_END:.*]], label %[[LOOP_BODY]] +// OGCG: [[LOOP_END]]: +// OGCG: %[[C:.*]] = getelementptr inbounds nuw %struct.ValueInit, ptr %[[THIS]], i32 0, i32 3 +// OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[C]], i32 0, i32 0 +// OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[C]], i32 0, i32 1 +// OGCG: store float 6.000000e+00, ptr %[[C_REAL_PTR]] +// OGCG: store float 7.000000e+00, ptr %[[C_IMAG_PTR]] +// OGCG: %[[BF:.*]] = getelementptr inbounds nuw %struct.ValueInit, ptr %[[THIS]], i32 0, i32 4 +// OGCG: store i8 -1, ptr %[[BF]] + +void use_structs() { + ZeroInit zi; + ValueInit vi; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits