clang 23.0.0git
CIRGenExprAggregate.cpp
Go to the documentation of this file.
1//===- CIRGenExprAggregrate.cpp - Emit CIR Code from Aggregate Expressions ===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This contains code to emit Aggregate Expr nodes as CIR code.
10//
11//===----------------------------------------------------------------------===//
12
13#include "CIRGenBuilder.h"
15#include "CIRGenFunction.h"
16#include "CIRGenValue.h"
17#include "mlir/IR/Builders.h"
19
20#include "clang/AST/Expr.h"
23#include "llvm/IR/Value.h"
24#include <cstdint>
25
26using namespace clang;
27using namespace clang::CIRGen;
28
29namespace {
30// FIXME(cir): This should be a common helper between CIRGen
31// and traditional CodeGen
32/// Is the value of the given expression possibly a reference to or
33/// into a __block variable?
34static bool isBlockVarRef(const Expr *e) {
35 // Make sure we look through parens.
36 e = e->IgnoreParens();
37
38 // Check for a direct reference to a __block variable.
39 if (const DeclRefExpr *dre = dyn_cast<DeclRefExpr>(e)) {
40 const VarDecl *var = dyn_cast<VarDecl>(dre->getDecl());
41 return (var && var->hasAttr<BlocksAttr>());
42 }
43
44 // More complicated stuff.
45
46 // Binary operators.
47 if (const BinaryOperator *op = dyn_cast<BinaryOperator>(e)) {
48 // For an assignment or pointer-to-member operation, just care
49 // about the LHS.
50 if (op->isAssignmentOp() || op->isPtrMemOp())
51 return isBlockVarRef(op->getLHS());
52
53 // For a comma, just care about the RHS.
54 if (op->getOpcode() == BO_Comma)
55 return isBlockVarRef(op->getRHS());
56
57 // FIXME: pointer arithmetic?
58 return false;
59
60 // Check both sides of a conditional operator.
61 } else if (const AbstractConditionalOperator *op =
62 dyn_cast<AbstractConditionalOperator>(e)) {
63 return isBlockVarRef(op->getTrueExpr()) ||
64 isBlockVarRef(op->getFalseExpr());
65
66 // OVEs are required to support BinaryConditionalOperators.
67 } else if (const OpaqueValueExpr *op = dyn_cast<OpaqueValueExpr>(e)) {
68 if (const Expr *src = op->getSourceExpr())
69 return isBlockVarRef(src);
70
71 // Casts are necessary to get things like (*(int*)&var) = foo().
72 // We don't really care about the kind of cast here, except
73 // we don't want to look through l2r casts, because it's okay
74 // to get the *value* in a __block variable.
75 } else if (const CastExpr *cast = dyn_cast<CastExpr>(e)) {
76 if (cast->getCastKind() == CK_LValueToRValue)
77 return false;
78 return isBlockVarRef(cast->getSubExpr());
79
80 // Handle unary operators. Again, just aggressively look through
81 // it, ignoring the operation.
82 } else if (const UnaryOperator *uop = dyn_cast<UnaryOperator>(e)) {
83 return isBlockVarRef(uop->getSubExpr());
84
85 // Look into the base of a field access.
86 } else if (const MemberExpr *mem = dyn_cast<MemberExpr>(e)) {
87 return isBlockVarRef(mem->getBase());
88
89 // Look into the base of a subscript.
90 } else if (const ArraySubscriptExpr *sub = dyn_cast<ArraySubscriptExpr>(e)) {
91 return isBlockVarRef(sub->getBase());
92 }
93
94 return false;
95}
96
97class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
98
99 CIRGenFunction &cgf;
100 AggValueSlot dest;
101
102 // Calls `fn` with a valid return value slot, potentially creating a temporary
103 // to do so. If a temporary is created, an appropriate copy into `Dest` will
104 // be emitted, as will lifetime markers.
105 //
106 // The given function should take a ReturnValueSlot, and return an RValue that
107 // points to said slot.
108 void withReturnValueSlot(const Expr *e,
109 llvm::function_ref<RValue(ReturnValueSlot)> fn);
110
111 AggValueSlot ensureSlot(mlir::Location loc, QualType t) {
112 if (!dest.isIgnored())
113 return dest;
114 return cgf.createAggTemp(t, loc, "agg.tmp.ensured");
115 }
116
117 void ensureDest(mlir::Location loc, QualType ty) {
118 if (!dest.isIgnored())
119 return;
120 dest = cgf.createAggTemp(ty, loc, "agg.tmp.ensured");
121 }
122
123public:
124 AggExprEmitter(CIRGenFunction &cgf, AggValueSlot dest)
125 : cgf(cgf), dest(dest) {}
126
127 /// Given an expression with aggregate type that represents a value lvalue,
128 /// this method emits the address of the lvalue, then loads the result into
129 /// DestPtr.
130 void emitAggLoadOfLValue(const Expr *e);
131
132 void emitArrayInit(Address destPtr, cir::ArrayType arrayTy, QualType arrayQTy,
133 Expr *exprToVisit, ArrayRef<Expr *> args,
134 Expr *arrayFiller);
135
136 void emitFinalDestCopy(QualType type, RValue src);
137
138 /// Perform the final copy to DestPtr, if desired.
139 void emitFinalDestCopy(QualType type, const LValue &src,
140 CIRGenFunction::ExprValueKind srcValueKind =
142
143 void emitCopy(QualType type, const AggValueSlot &dest,
144 const AggValueSlot &src);
145
146 void emitInitializationToLValue(Expr *e, LValue lv);
147
148 void emitNullInitializationToLValue(mlir::Location loc, LValue lv);
149
150 void Visit(Expr *e) { StmtVisitor<AggExprEmitter>::Visit(e); }
151
152 void VisitArraySubscriptExpr(ArraySubscriptExpr *e) {
153 emitAggLoadOfLValue(e);
154 }
155
156 void VisitCallExpr(const CallExpr *e);
157 void VisitStmtExpr(const StmtExpr *e) {
158 CIRGenFunction::StmtExprEvaluation eval(cgf);
159 Address retAlloca =
160 cgf.createMemTemp(e->getType(), cgf.getLoc(e->getSourceRange()));
161 (void)cgf.emitCompoundStmt(*e->getSubStmt(), &retAlloca, dest);
162 }
163
164 void VisitBinAssign(const BinaryOperator *e) {
165 // For an assignment to work, the value on the right has
166 // to be compatible with the value on the left.
167 assert(cgf.getContext().hasSameUnqualifiedType(e->getLHS()->getType(),
168 e->getRHS()->getType()) &&
169 "Invalid assignment");
170
171 if (isBlockVarRef(e->getLHS()) &&
172 e->getRHS()->HasSideEffects(cgf.getContext())) {
173 cgf.cgm.errorNYI(e->getSourceRange(),
174 "block var reference with side effects");
175 return;
176 }
177
178 LValue lhs = cgf.emitLValue(e->getLHS());
179
180 // If we have an atomic type, evaluate into the destination and then
181 // do an atomic copy.
183
184 // Codegen the RHS so that it stores directly into the LHS.
186 AggValueSlot lhsSlot = AggValueSlot::forLValue(
189
190 // A non-volatile aggregate destination might have volatile member.
191 if (!lhsSlot.isVolatile() && cgf.hasVolatileMember(e->getLHS()->getType()))
192 lhsSlot.setVolatile(true);
193
194 cgf.emitAggExpr(e->getRHS(), lhsSlot);
195
196 // Copy into the destination if the assignment isn't ignored.
197 emitFinalDestCopy(e->getType(), lhs);
198
199 if (!dest.isIgnored() && !dest.isExternallyDestructed() &&
201 cgf.pushDestroy(QualType::DK_nontrivial_c_struct, dest.getAddress(),
202 e->getType());
203 }
204
205 void VisitDeclRefExpr(DeclRefExpr *e) { emitAggLoadOfLValue(e); }
206
207 void VisitInitListExpr(InitListExpr *e);
208 void VisitCXXConstructExpr(const CXXConstructExpr *e);
209
210 void visitCXXParenListOrInitListExpr(Expr *e, ArrayRef<Expr *> args,
211 FieldDecl *initializedFieldInUnion,
212 Expr *arrayFiller);
213 void VisitCXXDefaultInitExpr(CXXDefaultInitExpr *die) {
214 CIRGenFunction::CXXDefaultInitExprScope Scope(cgf, die);
215 Visit(die->getExpr());
216 }
217 void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *e) {
218 // Ensure that we have a slot, but if we already do, remember
219 // whether it was externally destructed.
220 bool wasExternallyDestructed = dest.isExternallyDestructed();
221 ensureDest(cgf.getLoc(e->getSourceRange()), e->getType());
222
223 // We're going to push a destructor if there isn't already one.
224 dest.setExternallyDestructed();
225
226 Visit(e->getSubExpr());
227
228 // Push that destructor we promised.
229 if (!wasExternallyDestructed)
230 cgf.emitCXXTemporary(e->getTemporary(), e->getType(), dest.getAddress());
231 }
232 void VisitLambdaExpr(LambdaExpr *e);
233 void VisitExprWithCleanups(ExprWithCleanups *e);
234
235 // Stubs -- These should be moved up when they are implemented.
236 void VisitCastExpr(CastExpr *e) {
237 switch (e->getCastKind()) {
238 case CK_LValueToRValueBitCast: {
239 if (dest.isIgnored()) {
240 cgf.emitAnyExpr(e->getSubExpr(), AggValueSlot::ignored(),
241 /*ignoreResult=*/true);
242 break;
243 }
244
245 LValue sourceLV = cgf.emitLValue(e->getSubExpr());
246 Address sourceAddress =
247 sourceLV.getAddress().withElementType(cgf.getBuilder(), cgf.voidTy);
248 Address destAddress =
249 dest.getAddress().withElementType(cgf.getBuilder(), cgf.voidTy);
250
251 mlir::Location loc = cgf.getLoc(e->getExprLoc());
252
253 mlir::Value sizeVal = cgf.getBuilder().getConstInt(
254 loc, cgf.sizeTy,
255 cgf.getContext().getTypeSizeInChars(e->getType()).getQuantity());
256 cgf.getBuilder().createMemCpy(loc, destAddress.getPointer(),
257 sourceAddress.getPointer(), sizeVal);
258
259 break;
260 }
261 case CK_LValueToRValue:
262 // If we're loading from a volatile type, force the destination
263 // into existence.
265 cgf.cgm.errorNYI(e->getSourceRange(),
266 "AggExprEmitter: volatile lvalue-to-rvalue cast");
267 [[fallthrough]];
268 case CK_NoOp:
269 case CK_UserDefinedConversion:
270 case CK_ConstructorConversion:
271 assert(cgf.getContext().hasSameUnqualifiedType(e->getSubExpr()->getType(),
272 e->getType()) &&
273 "Implicit cast types must be compatible");
274 Visit(e->getSubExpr());
275 break;
276 case CK_ToUnion: {
277 if (dest.isIgnored()) {
278 cgf.emitAnyExpr(e->getSubExpr(), AggValueSlot::ignored(),
279 /*ignoreResult=*/true);
280 break;
281 }
282 QualType ty = e->getSubExpr()->getType();
283 Address castPtr = dest.getAddress().withElementType(cgf.getBuilder(),
284 cgf.convertType(ty));
285 emitInitializationToLValue(e->getSubExpr(),
286 cgf.makeAddrLValue(castPtr, ty));
287 break;
288 }
289 default:
290 cgf.cgm.errorNYI(e->getSourceRange(),
291 std::string("AggExprEmitter: VisitCastExpr: ") +
292 e->getCastKindName());
293 break;
294 }
295 }
296 void VisitStmt(Stmt *s) {
297 cgf.cgm.errorNYI(s->getSourceRange(),
298 std::string("AggExprEmitter::VisitStmt: ") +
299 s->getStmtClassName());
300 }
301 void VisitParenExpr(ParenExpr *pe) { Visit(pe->getSubExpr()); }
302 void VisitGenericSelectionExpr(GenericSelectionExpr *ge) {
303 Visit(ge->getResultExpr());
304 }
305 void VisitCoawaitExpr(CoawaitExpr *e) {
306 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCoawaitExpr");
307 }
308 void VisitCoyieldExpr(CoyieldExpr *e) {
309 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCoyieldExpr");
310 }
311 void VisitUnaryCoawait(UnaryOperator *e) {
312 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitUnaryCoawait");
313 }
314 void VisitUnaryExtension(UnaryOperator *e) { Visit(e->getSubExpr()); }
315 void VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *e) {
316 cgf.cgm.errorNYI(e->getSourceRange(),
317 "AggExprEmitter: VisitSubstNonTypeTemplateParmExpr");
318 }
319 void VisitConstantExpr(ConstantExpr *e) {
320 ensureDest(cgf.getLoc(e->getSourceRange()), e->getType());
321
322 if (mlir::Attribute result = ConstantEmitter(cgf).tryEmitConstantExpr(e)) {
323 mlir::Value resultVal = cgf.getBuilder().getConstant(
324 cgf.getLoc(e->getSourceRange()), mlir::cast<mlir::TypedAttr>(result));
325 LValue destLVal = cgf.makeAddrLValue(dest.getAddress(), e->getType());
326 cgf.emitStoreThroughLValue(RValue::get(resultVal), destLVal);
327 return;
328 }
329
330 // It isn't clear that it is possible to get to here, but this branch is
331 // present in classic codegen, so we leave it here too.
332 return Visit(e->getSubExpr());
333 }
334 void VisitMemberExpr(MemberExpr *e) { emitAggLoadOfLValue(e); }
335 void VisitUnaryDeref(UnaryOperator *e) { emitAggLoadOfLValue(e); }
336 void VisitStringLiteral(StringLiteral *e) { emitAggLoadOfLValue(e); }
337 void VisitCompoundLiteralExpr(CompoundLiteralExpr *e);
338
339 void VisitPredefinedExpr(const PredefinedExpr *e) { emitAggLoadOfLValue(e); }
340 void VisitBinaryOperator(const BinaryOperator *e) {
341 cgf.cgm.errorNYI(e->getSourceRange(),
342 "AggExprEmitter: VisitBinaryOperator");
343 }
344 void VisitPointerToDataMemberBinaryOperator(const BinaryOperator *e) {
345 cgf.cgm.errorNYI(e->getSourceRange(),
346 "AggExprEmitter: VisitPointerToDataMemberBinaryOperator");
347 }
348 void VisitBinComma(const BinaryOperator *e) {
349 cgf.emitIgnoredExpr(e->getLHS());
350 Visit(e->getRHS());
351 }
352 void VisitBinCmp(const BinaryOperator *e) {
353 assert(cgf.getContext().hasSameType(e->getLHS()->getType(),
354 e->getRHS()->getType()));
355 const ComparisonCategoryInfo &cmpInfo =
356 cgf.getContext().CompCategories.getInfoForType(e->getType());
357 assert(cmpInfo.Record->isTriviallyCopyable() &&
358 "cannot copy non-trivially copyable aggregate");
359
360 QualType argTy = e->getLHS()->getType();
361
362 if (!argTy->isIntegralOrEnumerationType() && !argTy->isRealFloatingType() &&
363 !argTy->isNullPtrType() && !argTy->isPointerType() &&
364 !argTy->isMemberPointerType() && !argTy->isAnyComplexType())
365 cgf.cgm.errorNYI(e->getBeginLoc(), "aggregate three-way comparison");
366
367 mlir::Location loc = cgf.getLoc(e->getSourceRange());
368 CIRGenBuilderTy &builder = cgf.getBuilder();
369
370 if (e->getType()->isAnyComplexType())
371 cgf.cgm.errorNYI(e->getBeginLoc(), "VisitBinCmp: complex type");
372
373 if (e->getType()->isAggregateType())
374 cgf.cgm.errorNYI(e->getBeginLoc(), "VisitBinCmp: aggregate type");
375
376 mlir::Value lhs = cgf.emitAnyExpr(e->getLHS()).getValue();
377 mlir::Value rhs = cgf.emitAnyExpr(e->getRHS()).getValue();
378
379 mlir::Value resultScalar;
380 if (argTy->isNullPtrType()) {
381 resultScalar =
382 builder.getConstInt(loc, cmpInfo.getEqualOrEquiv()->getIntValue());
383 } else {
384 llvm::APSInt ltRes = cmpInfo.getLess()->getIntValue();
385 llvm::APSInt eqRes = cmpInfo.getEqualOrEquiv()->getIntValue();
386 llvm::APSInt gtRes = cmpInfo.getGreater()->getIntValue();
387 if (!cmpInfo.isPartial()) {
388 cir::CmpOrdering ordering = cmpInfo.isStrong()
389 ? cir::CmpOrdering::Strong
390 : cir::CmpOrdering::Weak;
391 resultScalar = builder.createThreeWayCmpTotalOrdering(
392 loc, lhs, rhs, ltRes, eqRes, gtRes, ordering);
393 } else {
394 // Partial ordering.
395 llvm::APSInt unorderedRes = cmpInfo.getUnordered()->getIntValue();
396 resultScalar = builder.createThreeWayCmpPartialOrdering(
397 loc, lhs, rhs, ltRes, eqRes, gtRes, unorderedRes);
398 }
399 }
400
401 // Create the return value in the destination slot.
402 ensureDest(loc, e->getType());
403 LValue destLVal = cgf.makeAddrLValue(dest.getAddress(), e->getType());
404
405 // Emit the address of the first (and only) field in the comparison category
406 // type, and initialize it from the constant integer value produced above.
407 const FieldDecl *resultField = *cmpInfo.Record->field_begin();
408 LValue fieldLVal = cgf.emitLValueForFieldInitialization(
409 destLVal, resultField, resultField->getName());
410 cgf.emitStoreThroughLValue(RValue::get(resultScalar), fieldLVal);
411
412 // All done! The result is in the dest slot.
413 }
414
415 void VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *e) {
416 cgf.cgm.errorNYI(e->getSourceRange(),
417 "AggExprEmitter: VisitCXXRewrittenBinaryOperator");
418 }
419 void VisitObjCMessageExpr(ObjCMessageExpr *e) {
420 cgf.cgm.errorNYI(e->getSourceRange(),
421 "AggExprEmitter: VisitObjCMessageExpr");
422 }
423 void VisitObjCIVarRefExpr(ObjCIvarRefExpr *e) {
424 cgf.cgm.errorNYI(e->getSourceRange(),
425 "AggExprEmitter: VisitObjCIVarRefExpr");
426 }
427
428 void VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *e) {
429 AggValueSlot dest = ensureSlot(cgf.getLoc(e->getExprLoc()), e->getType());
430 LValue destLV = cgf.makeAddrLValue(dest.getAddress(), e->getType());
431 emitInitializationToLValue(e->getBase(), destLV);
432 VisitInitListExpr(e->getUpdater());
433 }
434 void VisitAbstractConditionalOperator(const AbstractConditionalOperator *e) {
435 mlir::Location loc = cgf.getLoc(e->getSourceRange());
436
437 CIRGenFunction::OpaqueValueMapping binding(cgf, e);
438 CIRGenFunction::ConditionalEvaluation eval(cgf);
439
440 // Save whether the destination's lifetime is externally managed.
441 bool isExternallyDestructed = dest.isExternallyDestructed();
442 bool destructNonTrivialCStruct =
443 !isExternallyDestructed &&
445 isExternallyDestructed |= destructNonTrivialCStruct;
446
447 cgf.emitIfOnBoolExpr(
448 e->getCond(),
449 /*thenBuilder=*/
450 [&](mlir::OpBuilder &b, mlir::Location loc) {
451 eval.beginEvaluation();
452 {
453 CIRGenFunction::LexicalScope lexScope{cgf, loc,
454 b.getInsertionBlock()};
455 cgf.curLexScope->setAsTernary();
456 dest.setExternallyDestructed(isExternallyDestructed);
457 assert(!cir::MissingFeatures::incrementProfileCounter());
458 Visit(e->getTrueExpr());
459 cir::YieldOp::create(b, loc);
460 }
461 eval.endEvaluation();
462 },
463 loc,
464 /*elseBuilder=*/
465 [&](mlir::OpBuilder &b, mlir::Location loc) {
466 eval.beginEvaluation();
467 {
468 CIRGenFunction::LexicalScope lexScope{cgf, loc,
469 b.getInsertionBlock()};
470 cgf.curLexScope->setAsTernary();
471
472 // If the result of an agg expression is unused, then the emission
473 // of the LHS might need to create a destination slot. That's fine
474 // with us, and we can safely emit the RHS into the same slot, but
475 // we shouldn't claim that it's already being destructed.
476 dest.setExternallyDestructed(isExternallyDestructed);
478 Visit(e->getFalseExpr());
479 cir::YieldOp::create(b, loc);
480 }
481 eval.endEvaluation();
482 },
483 loc);
484
485 if (destructNonTrivialCStruct)
486 cgf.cgm.errorNYI(
487 e->getSourceRange(),
488 "Abstract conditional aggregate: destructNonTrivialCStruct");
489 }
490 void VisitChooseExpr(const ChooseExpr *e) { Visit(e->getChosenSubExpr()); }
491 void VisitCXXParenListInitExpr(CXXParenListInitExpr *e) {
492 visitCXXParenListOrInitListExpr(e, e->getInitExprs(),
494 e->getArrayFiller());
495 }
496
497 void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *e) {
499 uint64_t numElements = e->getArraySize().getZExtValue();
500
501 if (!numElements)
502 return;
503
504 const mlir::Location loc = cgf.getLoc(e->getSourceRange());
505
506 if (!e->getType()->isConstantArrayType())
507 cgf.cgm.errorNYI(e->getSourceRange(),
508 "VisitArrayInitLoopExpr: Non-constant array");
509
510 Address dest = ensureSlot(loc, e->getType()).getAddress();
511 cir::ArrayType arrayTy = cast<cir::ArrayType>(dest.getElementType());
512
513 emitArrayInit(dest, arrayTy, e->getType(),
514 const_cast<ArrayInitLoopExpr *>(e), {}, e->getSubExpr());
515 }
516
517 void VisitImplicitValueInitExpr(ImplicitValueInitExpr *e) {
518 QualType ty = e->getType();
519 mlir::Location loc = cgf.getLoc(e->getSourceRange());
520 AggValueSlot slot = ensureSlot(loc, ty);
521 emitNullInitializationToLValue(loc,
522 cgf.makeAddrLValue(slot.getAddress(), ty));
523 }
524 void VisitNoInitExpr(NoInitExpr *e) {
525 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitNoInitExpr");
526 }
527 void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *dae) {
529 Visit(dae->getExpr());
530 }
531 void VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *e) {
532 AggValueSlot slot =
533 ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
535 e->constructsVBase(), slot.getAddress(),
536 e->inheritedFromVBase(), e);
537 }
538
539 /// Emit the initializer for a std::initializer_list initialized with a
540 /// real initializer list.
541 void VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *e) {
542 ASTContext &ctx = cgf.getContext();
543 CIRGenBuilderTy &builder = cgf.getBuilder();
544 mlir::Location loc = cgf.getLoc(e->getExprLoc());
545
546 LValue array = cgf.emitLValue(e->getSubExpr());
547 assert(array.isSimple() && "initializer_list array not a simple lvalue");
548 Address arrayPtr = array.getAddress();
549
552 assert(arrayType && "std::initializer_list constructed from non-array");
553
554 auto *record = e->getType()->castAsRecordDecl();
555 assert(record->getNumFields() == 2 &&
556 "Expected std::initializer_list to only have two fields");
557
558 RecordDecl::field_iterator field = record->field_begin();
559 assert(field != record->field_end() &&
560 ctx.hasSameType(field->getType()->getPointeeType(),
561 arrayType->getElementType()) &&
562 "Expected std::initializer_list first field to be const E *");
563
564 // Start pointer.
565 AggValueSlot dest = ensureSlot(loc, e->getType());
566 LValue destLV = cgf.makeAddrLValue(dest.getAddress(), e->getType());
567 LValue start =
568 cgf.emitLValueForFieldInitialization(destLV, *field, field->getName());
569
570 mlir::Value arrayStart = arrayPtr.emitRawPointer();
571 cgf.emitStoreThroughLValue(RValue::get(arrayStart), start);
572 ++field;
573 assert(field != record->field_end() &&
574 "Expected std::initializer_list to have two fields");
575
576 cir::ConstantOp size = builder.getConstInt(loc, arrayType->getSize());
577 LValue endOrLength =
578 cgf.emitLValueForFieldInitialization(destLV, *field, field->getName());
579 if (ctx.hasSameType(field->getType(), ctx.getSizeType())) {
580 // Length.
581 cgf.emitStoreThroughLValue(RValue::get(size), endOrLength);
582 } else {
583 // End pointer.
584 assert(field->getType()->isPointerType() &&
585 ctx.hasSameType(field->getType()->getPointeeType(),
586 arrayType->getElementType()) &&
587 "Expected std::initializer_list second field to be const E *");
588 mlir::Value arrayEnd = builder.createPtrStride(loc, arrayStart, size);
589 cgf.emitStoreThroughLValue(RValue::get(arrayEnd), endOrLength);
590 }
591 }
592
593 void VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *e) {
594 cgf.cgm.errorNYI(e->getSourceRange(),
595 "AggExprEmitter: VisitCXXScalarValueInitExpr");
596 }
597 void VisitCXXTypeidExpr(CXXTypeidExpr *e) { emitAggLoadOfLValue(e); }
598 void VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *e) {
599 Visit(e->getSubExpr());
600 }
601 void VisitOpaqueValueExpr(OpaqueValueExpr *e) {
602 cgf.cgm.errorNYI(e->getSourceRange(),
603 "AggExprEmitter: VisitOpaqueValueExpr");
604 }
605
606 void VisitPseudoObjectExpr(PseudoObjectExpr *e) {
607 cgf.cgm.errorNYI(e->getSourceRange(),
608 "AggExprEmitter: VisitPseudoObjectExpr");
609 }
610
611 void VisitVAArgExpr(VAArgExpr *e) {
612 // emitVAArg returns an aggregate value (not a pointer) at the CIR level.
613 // ABI-specific pointer handling will be done later in LoweringPrepare.
614 mlir::Value vaArgValue = cgf.emitVAArg(e);
615
616 // Create a temporary alloca to hold the aggregate value.
617 mlir::Location loc = cgf.getLoc(e->getSourceRange());
618 Address tmpAddr = cgf.createMemTemp(e->getType(), loc, "vaarg.tmp");
619
620 // Store the va_arg result into the temporary.
621 cgf.emitAggregateStore(vaArgValue, tmpAddr);
622
623 // Create an LValue from the temporary address.
624 LValue tmpLValue = cgf.makeAddrLValue(tmpAddr, e->getType());
625
626 // Copy the aggregate value from temporary to destination.
627 emitFinalDestCopy(e->getType(), tmpLValue);
628 }
629
630 void VisitCXXThrowExpr(const CXXThrowExpr *e) { cgf.emitCXXThrowExpr(e); }
631 void VisitAtomicExpr(AtomicExpr *e) {
632 RValue result = cgf.emitAtomicExpr(e);
633 emitFinalDestCopy(e->getType(), result);
634 }
635};
636
637} // namespace
638
639static bool isTrivialFiller(Expr *e) {
640 if (!e)
641 return true;
642
644 return true;
645
646 if (auto *ile = dyn_cast<InitListExpr>(e)) {
647 if (ile->getNumInits())
648 return false;
649 return isTrivialFiller(ile->getArrayFiller());
650 }
651
652 if (const auto *cons = dyn_cast_or_null<CXXConstructExpr>(e))
653 return cons->getConstructor()->isDefaultConstructor() &&
654 cons->getConstructor()->isTrivial();
655
656 return false;
657}
658
659/// Given an expression with aggregate type that represents a value lvalue, this
660/// method emits the address of the lvalue, then loads the result into DestPtr.
661void AggExprEmitter::emitAggLoadOfLValue(const Expr *e) {
662 LValue lv = cgf.emitLValue(e);
663
664 // If the type of the l-value is atomic, then do an atomic load.
666
667 emitFinalDestCopy(e->getType(), lv);
668}
669
670void AggExprEmitter::VisitCompoundLiteralExpr(CompoundLiteralExpr *e) {
671 if (dest.isPotentiallyAliased() && e->getType().isPODType(cgf.getContext())) {
672 // For a POD type, just emit a load of the lvalue + a copy, because our
673 // compound literal might alias the destination.
674 emitAggLoadOfLValue(e);
675 return;
676 }
677
678 AggValueSlot slot = ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
679
680 // Block-scope compound literals are destroyed at the end of the enclosing
681 // scope in C.
682 bool destruct =
683 !cgf.getLangOpts().CPlusPlus && !slot.isExternallyDestructed();
684 if (destruct)
686
687 cgf.emitAggExpr(e->getInitializer(), slot);
688
689 if (destruct)
690 if ([[maybe_unused]] QualType::DestructionKind dtorKind =
692 cgf.cgm.errorNYI(e->getSourceRange(), "compound literal with destructor");
693}
694
695void AggExprEmitter::emitArrayInit(Address destPtr, cir::ArrayType arrayTy,
696 QualType arrayQTy, Expr *e,
697 ArrayRef<Expr *> args, Expr *arrayFiller) {
698 CIRGenBuilderTy &builder = cgf.getBuilder();
699 const mlir::Location loc = cgf.getLoc(e->getSourceRange());
700
701 const uint64_t numInitElements = args.size();
702
703 bool setArrayInitLoopExprScope = isa<ArrayInitLoopExpr>(e);
704
705 const QualType elementType =
706 cgf.getContext().getAsArrayType(arrayQTy)->getElementType();
707
708 const QualType elementPtrType = cgf.getContext().getPointerType(elementType);
709
710 const mlir::Type cirElementType = cgf.convertType(elementType);
711 const cir::PointerType cirElementPtrType =
712 builder.getPointerTo(cirElementType);
713
714 auto begin = cir::CastOp::create(builder, loc, cirElementPtrType,
715 cir::CastKind::array_to_ptrdecay,
716 destPtr.getPointer());
717
718 const CharUnits elementSize =
719 cgf.getContext().getTypeSizeInChars(elementType);
720 const CharUnits elementAlign =
721 destPtr.getAlignment().alignmentOfArrayElement(elementSize);
722
723 // Exception safety requires us to destroy all the already-constructed
724 // members if an initializer throws. For that, we'll need an EH cleanup.
725 QualType::DestructionKind dtorKind = elementType.isDestructedType();
726 Address endOfInit = Address::invalid();
728
729 if (dtorKind && cgf.getLangOpts().Exceptions) {
730 endOfInit = cgf.createTempAlloca(cirElementPtrType, cgf.getPointerAlign(),
731 loc, "arrayinit.endOfInit");
732 builder.createStore(loc, begin, endOfInit);
733
734 cgf.pushIrregularPartialArrayCleanup(begin, endOfInit, elementType,
735 elementAlign,
736 cgf.getDestroyer(dtorKind));
737 }
738
739 // The 'current element to initialize'. The invariants on this
740 // variable are complicated. Essentially, after each iteration of
741 // the loop, it points to the last initialized element, except
742 // that it points to the beginning of the array before any
743 // elements have been initialized.
744 mlir::Value element = begin;
745
746 // Don't build the 'one' before the cycle to avoid
747 // emmiting the redundant `cir.const 1` instrs.
748 mlir::Value one;
749
750 // Emit the explicit initializers.
751 for (uint64_t i = 0; i != numInitElements; ++i) {
752 // Advance to the next element.
753 if (i > 0) {
754 one = builder.getConstantInt(loc, cgf.ptrDiffTy, i);
755 element = builder.createPtrStride(loc, begin, one);
756
757 // Tell the cleanup that it needs to destroy up to this element.
758 if (endOfInit.isValid())
759 builder.createStore(loc, element, endOfInit);
760 }
761
762 const Address address = Address(element, cirElementType, elementAlign);
763 const LValue elementLV = cgf.makeAddrLValue(address, elementType);
764 emitInitializationToLValue(args[i], elementLV);
765 }
766
767 const uint64_t numArrayElements = arrayTy.getSize();
768
769 // Check whether there's a non-trivial array-fill expression.
770 const bool hasTrivialFiller = isTrivialFiller(arrayFiller);
771
772 // Any remaining elements need to be zero-initialized, possibly
773 // using the filler expression. We can skip this if the we're
774 // emitting to zeroed memory.
775 if (numInitElements != numArrayElements &&
776 !(dest.isZeroed() && hasTrivialFiller &&
777 cgf.getTypes().isZeroInitializable(elementType))) {
778 // Advance to the start of the rest of the array.
779 if (numInitElements) {
780 one = builder.getConstantInt(loc, cgf.ptrDiffTy, 1);
781 element = cir::PtrStrideOp::create(builder, loc, cirElementPtrType,
782 element, one);
783
784 if (endOfInit.isValid())
785 builder.createStore(loc, element, endOfInit);
786 }
787
788 // Allocate the temporary variable
789 // to store the pointer to first unitialized element
790 const Address tmpAddr = cgf.createTempAlloca(
791 cirElementPtrType, cgf.getPointerAlign(), loc, "arrayinit.temp");
792 LValue tmpLV = cgf.makeAddrLValue(tmpAddr, elementPtrType);
793 cgf.emitStoreThroughLValue(RValue::get(element), tmpLV);
794
795 // Compute the end of array
796 cir::ConstantOp numArrayElementsConst = builder.getConstInt(
797 loc, mlir::cast<cir::IntType>(cgf.ptrDiffTy), numArrayElements);
798 mlir::Value end = cir::PtrStrideOp::create(builder, loc, cirElementPtrType,
799 begin, numArrayElementsConst);
800
801 builder.createDoWhile(
802 loc,
803 /*condBuilder=*/
804 [&](mlir::OpBuilder &b, mlir::Location loc) {
805 cir::LoadOp currentElement = builder.createLoad(loc, tmpAddr);
806 cir::CmpOp cmp = cir::CmpOp::create(builder, loc, cir::CmpOpKind::ne,
807 currentElement, end);
808 builder.createCondition(cmp);
809 },
810 /*bodyBuilder=*/
811 [&](mlir::OpBuilder &b, mlir::Location loc) {
812 cir::LoadOp currentElement = builder.createLoad(loc, tmpAddr);
813
814 // Emit the actual filler expression.
815 LValue elementLV = cgf.makeAddrLValue(
816 Address(currentElement, cirElementType, elementAlign),
817 elementType);
818
819 mlir::Value idx;
820 if (setArrayInitLoopExprScope)
821 idx = cir::PtrDiffOp::create(b, loc, cgf.ptrDiffTy, currentElement,
822 begin);
823
824 CIRGenFunction::ArrayInitLoopExprScope loopExprScope(
825 cgf, setArrayInitLoopExprScope, idx);
826
827 if (arrayFiller)
828 emitInitializationToLValue(arrayFiller, elementLV);
829 else
830 emitNullInitializationToLValue(loc, elementLV);
831
832 // Advance pointer and store them to temporary variable
833 cir::ConstantOp one = builder.getConstInt(
834 loc, mlir::cast<cir::IntType>(cgf.ptrDiffTy), 1);
835 auto nextElement = cir::PtrStrideOp::create(
836 builder, loc, cirElementPtrType, currentElement, one);
837
838 // Tell the EH cleanup that we finished with the last element.
839 if (endOfInit.isValid())
840 builder.createStore(loc, nextElement, endOfInit);
841
842 cgf.emitStoreThroughLValue(RValue::get(nextElement), tmpLV);
843
844 builder.createYield(loc);
845 });
846 }
847}
848
849/// EmitFinalDestCopy - Perform the final copy to DestPtr, if desired.
850void AggExprEmitter::emitFinalDestCopy(QualType type, RValue src) {
851 assert(src.isAggregate() && "value must be aggregate value!");
852 LValue srcLV = cgf.makeAddrLValue(src.getAggregateAddress(), type);
853 emitFinalDestCopy(type, srcLV, CIRGenFunction::EVK_RValue);
854}
855
856/// Perform the final copy to destPtr, if desired.
857void AggExprEmitter::emitFinalDestCopy(
858 QualType type, const LValue &src,
859 CIRGenFunction::ExprValueKind srcValueKind) {
860 // If dest is ignored, then we're evaluating an aggregate expression
861 // in a context that doesn't care about the result. Note that loads
862 // from volatile l-values force the existence of a non-ignored
863 // destination.
864 if (dest.isIgnored())
865 return;
866
867 if (srcValueKind == CIRGenFunction::EVK_RValue) {
868 if (type.isNonTrivialToPrimitiveDestructiveMove() == QualType::PCK_Struct) {
869 cgf.cgm.errorNYI("emitFinalDestCopy: EVK_RValue & PCK_Struct");
870 }
871 } else {
872 if (type.isNonTrivialToPrimitiveCopy() == QualType::PCK_Struct) {
873 cgf.cgm.errorNYI("emitFinalDestCopy: !EVK_RValue & PCK_Struct");
874 }
875 }
876
880
881 AggValueSlot srcAgg = AggValueSlot::forLValue(src, AggValueSlot::IsDestructed,
884 emitCopy(type, dest, srcAgg);
885}
886
887/// Perform a copy from the source into the destination.
888///
889/// \param type - the type of the aggregate being copied; qualifiers are
890/// ignored
891void AggExprEmitter::emitCopy(QualType type, const AggValueSlot &dest,
892 const AggValueSlot &src) {
894
895 // If the result of the assignment is used, copy the LHS there also.
896 // It's volatile if either side is. Use the minimum alignment of
897 // the two sides.
898 LValue destLV = cgf.makeAddrLValue(dest.getAddress(), type);
899 LValue srcLV = cgf.makeAddrLValue(src.getAddress(), type);
901 cgf.emitAggregateCopy(destLV, srcLV, type, dest.mayOverlap(),
902 dest.isVolatile() || src.isVolatile());
903}
904
905void AggExprEmitter::emitInitializationToLValue(Expr *e, LValue lv) {
906 const QualType type = lv.getType();
907
909 const mlir::Location loc = e->getSourceRange().isValid()
910 ? cgf.getLoc(e->getSourceRange())
911 : *cgf.currSrcLoc;
912 return emitNullInitializationToLValue(loc, lv);
913 }
914
915 if (isa<NoInitExpr>(e))
916 return;
917
918 if (type->isReferenceType()) {
919 RValue rv = cgf.emitReferenceBindingToExpr(e);
920 return cgf.emitStoreThroughLValue(rv, lv);
921 }
922
923 switch (cgf.getEvaluationKind(type)) {
924 case cir::TEK_Complex:
925 cgf.emitComplexExprIntoLValue(e, lv, /*isInit*/ true);
926 break;
931 dest.isZeroed()));
932
933 return;
934 case cir::TEK_Scalar:
935 if (lv.isSimple())
936 cgf.emitScalarInit(e, cgf.getLoc(e->getSourceRange()), lv);
937 else
939 return;
940 }
941}
942
943void AggExprEmitter::VisitCXXConstructExpr(const CXXConstructExpr *e) {
944 AggValueSlot slot = ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
945 cgf.emitCXXConstructExpr(e, slot);
946}
947
948void AggExprEmitter::emitNullInitializationToLValue(mlir::Location loc,
949 LValue lv) {
950 const QualType type = lv.getType();
951
952 // If the destination slot is already zeroed out before the aggregate is
953 // copied into it, we don't have to emit any zeros here.
954 if (dest.isZeroed() && cgf.getTypes().isZeroInitializable(type))
955 return;
956
957 if (cgf.hasScalarEvaluationKind(type)) {
958 // For non-aggregates, we can store the appropriate null constant.
959 mlir::Value null = cgf.cgm.emitNullConstant(type, loc);
960 if (lv.isSimple()) {
961 cgf.emitStoreOfScalar(null, lv, /* isInitialization */ true);
962 return;
963 }
964
966 return;
967 }
968
969 // There's a potential optimization opportunity in combining
970 // memsets; that would be easy for arrays, but relatively
971 // difficult for structures with the current code.
972 cgf.emitNullInitialization(loc, lv.getAddress(), lv.getType());
973}
974
975void AggExprEmitter::VisitLambdaExpr(LambdaExpr *e) {
976 CIRGenFunction::SourceLocRAIIObject loc{cgf, cgf.getLoc(e->getSourceRange())};
977 AggValueSlot slot = ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
978 LValue slotLV = cgf.makeAddrLValue(slot.getAddress(), e->getType());
979
980 // We'll need to enter cleanup scopes in case any of the element
981 // initializers throws an exception or contains branch out of the expressions.
982 CIRGenFunction::CleanupDeactivationScope deactivationScope(cgf);
983
984 for (auto [curField, capture, captureInit] : llvm::zip(
985 e->getLambdaClass()->fields(), e->captures(), e->capture_inits())) {
986 // Pick a name for the field.
987 llvm::StringRef fieldName = curField->getName();
988 if (capture.capturesVariable()) {
989 assert(!curField->isBitField() && "lambdas don't have bitfield members!");
990 ValueDecl *v = capture.getCapturedVar();
991 fieldName = v->getName();
992 cgf.cgm.lambdaFieldToName[curField] = fieldName;
993 } else if (capture.capturesThis()) {
994 cgf.cgm.lambdaFieldToName[curField] = "this";
995 } else {
996 cgf.cgm.errorNYI(e->getSourceRange(), "Unhandled capture kind");
997 cgf.cgm.lambdaFieldToName[curField] = "unhandled-capture-kind";
998 }
999
1000 // Emit initialization
1001 LValue lv =
1002 cgf.emitLValueForFieldInitialization(slotLV, curField, fieldName);
1003 if (curField->hasCapturedVLAType())
1004 cgf.cgm.errorNYI(e->getSourceRange(), "lambda captured VLA type");
1005
1006 emitInitializationToLValue(captureInit, lv);
1007
1008 // Push a destructor if necessary.
1009 if (QualType::DestructionKind dtorKind =
1010 curField->getType().isDestructedType()) {
1011 assert(lv.isSimple());
1013 curField->getType(),
1014 cgf.getDestroyer(dtorKind), false);
1015 }
1016 }
1017}
1018
1019void AggExprEmitter::VisitExprWithCleanups(ExprWithCleanups *e) {
1020 CIRGenFunction::FullExprCleanupScope fullExprScope(cgf, e->getSubExpr());
1021 Visit(e->getSubExpr());
1022}
1023
1024void AggExprEmitter::VisitCallExpr(const CallExpr *e) {
1025 if (e->getCallReturnType(cgf.getContext())->isReferenceType()) {
1026 cgf.cgm.errorNYI(e->getSourceRange(), "reference return type");
1027 return;
1028 }
1029
1030 withReturnValueSlot(
1031 e, [&](ReturnValueSlot slot) { return cgf.emitCallExpr(e, slot); });
1032}
1033
1034void AggExprEmitter::withReturnValueSlot(
1035 const Expr *e, llvm::function_ref<RValue(ReturnValueSlot)> fn) {
1036 QualType retTy = e->getType();
1037
1039 bool requiresDestruction =
1041 if (requiresDestruction)
1042 cgf.cgm.errorNYI(
1043 e->getSourceRange(),
1044 "withReturnValueSlot: return value requiring destruction is NYI");
1045
1046 // If it makes no observable difference, save a memcpy + temporary.
1047 //
1048 // We need to always provide our own temporary if destruction is required.
1049 // Otherwise, fn will emit its own, notice that it's "unused", and end its
1050 // lifetime before we have the chance to emit a proper destructor call.
1053
1054 Address retAddr = dest.getAddress();
1056
1059 fn(ReturnValueSlot(retAddr));
1060}
1061
1062void AggExprEmitter::VisitInitListExpr(InitListExpr *e) {
1063 if (e->hadArrayRangeDesignator())
1064 llvm_unreachable("GNU array range designator extension");
1065
1066 if (e->isTransparent())
1067 return Visit(e->getInit(0));
1068
1069 visitCXXParenListOrInitListExpr(
1070 e, e->inits(), e->getInitializedFieldInUnion(), e->getArrayFiller());
1071}
1072
1073void AggExprEmitter::visitCXXParenListOrInitListExpr(
1074 Expr *e, ArrayRef<Expr *> args, FieldDecl *initializedFieldInUnion,
1075 Expr *arrayFiller) {
1076
1077 const mlir::Location loc = cgf.getLoc(e->getSourceRange());
1078 const AggValueSlot dest = ensureSlot(loc, e->getType());
1079
1080 if (e->getType()->isConstantArrayType()) {
1081 cir::ArrayType arrayTy =
1083 emitArrayInit(dest.getAddress(), arrayTy, e->getType(), e, args,
1084 arrayFiller);
1085 return;
1086 } else if (e->getType()->isVariableArrayType()) {
1087 cgf.cgm.errorNYI(e->getSourceRange(),
1088 "visitCXXParenListOrInitListExpr variable array type");
1089 return;
1090 }
1091
1092 if (e->getType()->isArrayType()) {
1093 cgf.cgm.errorNYI(e->getSourceRange(),
1094 "visitCXXParenListOrInitListExpr array type");
1095 return;
1096 }
1097
1098 assert(e->getType()->isRecordType() && "Only support structs/unions here!");
1099
1100 // Do struct initialization; this code just sets each individual member
1101 // to the approprate value. This makes bitfield support automatic;
1102 // the disadvantage is that the generated code is more difficult for
1103 // the optimizer, especially with bitfields.
1104 unsigned numInitElements = args.size();
1105 auto *record = e->getType()->castAsRecordDecl();
1106
1107 // We'll need to enter cleanup scopes in case any of the element
1108 // initializers throws an exception.
1109 CIRGenFunction::CleanupDeactivationScope deactivateCleanups(cgf);
1110
1111 unsigned curInitIndex = 0;
1112
1113 // Emit initialization of base classes.
1114 if (auto *cxxrd = dyn_cast<CXXRecordDecl>(record)) {
1115 assert(numInitElements >= cxxrd->getNumBases() &&
1116 "missing initializer for base class");
1117 for (auto &base : cxxrd->bases()) {
1118 assert(!base.isVirtual() && "should not see vbases here");
1119 CXXRecordDecl *baseRD = base.getType()->getAsCXXRecordDecl();
1121 loc, dest.getAddress(), cxxrd, baseRD,
1122 /*baseIsVirtual=*/false);
1124 AggValueSlot aggSlot = AggValueSlot::forAddr(
1125 address, Qualifiers(), AggValueSlot::IsDestructed,
1127 cgf.getOverlapForBaseInit(cxxrd, baseRD, false));
1128 cgf.emitAggExpr(args[curInitIndex++], aggSlot);
1129
1130 if (QualType::DestructionKind dtorKind =
1131 base.getType().isDestructedType())
1132 cgf.pushDestroyAndDeferDeactivation(dtorKind, address, base.getType());
1133 }
1134 }
1135
1136 // Prepare a 'this' for CXXDefaultInitExprs.
1137 CIRGenFunction::FieldConstructionScope fcScope(cgf, dest.getAddress());
1138
1139 LValue destLV = cgf.makeAddrLValue(dest.getAddress(), e->getType());
1140
1141 if (record->isUnion()) {
1142 // Only initialize one field of a union. The field itself is
1143 // specified by the initializer list.
1144 if (!initializedFieldInUnion) {
1145 // Empty union; we have nothing to do.
1146
1147 // Make sure that it's really an empty and not a failure of
1148 // semantic analysis.
1149 assert(llvm::all_of(record->fields(),
1150 [](const FieldDecl *f) {
1151 return f->isUnnamedBitField() ||
1152 f->isAnonymousStructOrUnion();
1153 }) &&
1154 "Only unnamed bitfields or anonymous class allowed");
1155 return;
1156 }
1157
1158 // FIXME: volatility
1159 FieldDecl *initedField = initializedFieldInUnion;
1160
1161 LValue fieldLV = cgf.emitLValueForFieldInitialization(
1162 destLV, initedField, initedField->getName());
1163
1164 if (numInitElements) {
1165 // Store the initializer into the field
1166 emitInitializationToLValue(args[0], fieldLV);
1167 } else {
1168 // Default-initialize to null.
1169 emitNullInitializationToLValue(loc, fieldLV);
1170 }
1171 return;
1172 }
1173
1174 // Here we iterate over the fields; this makes it simpler to both
1175 // default-initialize fields and skip over unnamed fields.
1176 for (const FieldDecl *field : record->fields()) {
1177 // We're done once we hit the flexible array member.
1178 if (field->getType()->isIncompleteArrayType())
1179 break;
1180
1181 // Always skip anonymous bitfields.
1182 if (field->isUnnamedBitField())
1183 continue;
1184
1185 // We're done if we reach the end of the explicit initializers, we
1186 // have a zeroed object, and the rest of the fields are
1187 // zero-initializable.
1188 if (curInitIndex == numInitElements && dest.isZeroed() &&
1190 break;
1191 LValue lv =
1192 cgf.emitLValueForFieldInitialization(destLV, field, field->getName());
1193 // We never generate write-barriers for initialized fields.
1195
1196 if (curInitIndex < numInitElements) {
1197 // Store the initializer into the field.
1198 CIRGenFunction::SourceLocRAIIObject loc{
1199 cgf, cgf.getLoc(record->getSourceRange())};
1200 emitInitializationToLValue(args[curInitIndex++], lv);
1201 } else {
1202 // We're out of initializers; default-initialize to null
1203 emitNullInitializationToLValue(cgf.getLoc(e->getSourceRange()), lv);
1204 }
1205
1206 // Push a destructor if necessary.
1207 // FIXME: if we have an array of structures, all explicitly
1208 // initialized, we can end up pushing a linear number of cleanups.
1209 if (QualType::DestructionKind dtorKind =
1210 field->getType().isDestructedType()) {
1211 assert(lv.isSimple());
1213 field->getType(),
1214 cgf.getDestroyer(dtorKind), false);
1215 }
1216
1217 // From classic codegen, maybe not useful for CIR:
1218 // If the GEP didn't get used because of a dead zero init or something
1219 // else, clean it up for -O0 builds and general tidiness.
1220 }
1221}
1222
1223// TODO(cir): This could be shared with classic codegen.
1225 const CXXRecordDecl *rd, const CXXRecordDecl *baseRD, bool isVirtual) {
1226 // If the most-derived object is a field declared with [[no_unique_address]],
1227 // the tail padding of any virtual base could be reused for other subobjects
1228 // of that field's class.
1229 if (isVirtual)
1231
1232 // If the base class is laid out entirely within the nvsize of the derived
1233 // class, its tail padding cannot yet be initialized, so we can issue
1234 // stores at the full width of the base class.
1235 const ASTRecordLayout &layout = getContext().getASTRecordLayout(rd);
1236 if (layout.getBaseClassOffset(baseRD) +
1237 getContext().getASTRecordLayout(baseRD).getSize() <=
1238 layout.getNonVirtualSize())
1240
1241 // The tail padding may contain values we need to preserve.
1243}
1244
1246 AggExprEmitter(*this, slot).Visit(const_cast<Expr *>(e));
1247}
1248
1250 AggValueSlot::Overlap_t mayOverlap,
1251 bool isVolatile) {
1252 // TODO(cir): this function needs improvements, commented code for now since
1253 // this will be touched again soon.
1254 assert(!ty->isAnyComplexType() && "Unexpected copy of complex");
1255
1256 Address destPtr = dest.getAddress();
1257 Address srcPtr = src.getAddress();
1258
1259 if (getLangOpts().CPlusPlus) {
1260 if (auto *record = ty->getAsCXXRecordDecl()) {
1261 assert((record->hasTrivialCopyConstructor() ||
1262 record->hasTrivialCopyAssignment() ||
1263 record->hasTrivialMoveConstructor() ||
1264 record->hasTrivialMoveAssignment() ||
1265 record->hasAttr<TrivialABIAttr>() || record->isUnion()) &&
1266 "Trying to aggregate-copy a type without a trivial copy/move "
1267 "constructor or assignment operator");
1268 // Ignore empty classes in C++.
1269 if (record->isEmpty())
1270 return;
1271 }
1272 }
1273
1275
1276 // Aggregate assignment turns into llvm.memcpy. This is almost valid per
1277 // C99 6.5.16.1p3, which states "If the value being stored in an object is
1278 // read from another object that overlaps in anyway the storage of the first
1279 // object, then the overlap shall be exact and the two objects shall have
1280 // qualified or unqualified versions of a compatible type."
1281 //
1282 // memcpy is not defined if the source and destination pointers are exactly
1283 // equal, but other compilers do this optimization, and almost every memcpy
1284 // implementation handles this case safely. If there is a libc that does not
1285 // safely handle this, we can add a target hook.
1286
1287 // Get data size info for this aggregate. Don't copy the tail padding if this
1288 // might be a potentially-overlapping subobject, since the tail padding might
1289 // be occupied by a different object. Otherwise, copying it is fine.
1290 TypeInfoChars typeInfo;
1291 if (mayOverlap)
1292 typeInfo = getContext().getTypeInfoDataSizeInChars(ty);
1293 else
1294 typeInfo = getContext().getTypeInfoInChars(ty);
1295
1297
1298 // Don't do any of the memmove_collectable tests if GC isn't set.
1299 if (cgm.getLangOpts().getGC() != LangOptions::NonGC)
1300 cgm.errorNYI("emitAggregateCopy: GC");
1301
1302 // If the data size (excluding tail padding) differs from the full type size,
1303 // use skip_tail_padding to avoid clobbering tail padding that may be occupied
1304 // by other objects (e.g. fields marked with [[no_unique_address]]).
1305 CharUnits dataSize = typeInfo.Width;
1306 bool skipTailPadding =
1307 mayOverlap && dataSize != getContext().getTypeSizeInChars(ty);
1308 // NOTE(cir): original codegen would normally convert destPtr and srcPtr to
1309 // i8* since memcpy operates on bytes. We don't need that in CIR because
1310 // cir.copy will operate on any CIR pointer that points to a sized type.
1311 builder.createCopy(destPtr.getPointer(), srcPtr.getPointer(), isVolatile,
1312 skipTailPadding);
1313
1315}
1316
1317// TODO(cir): This could be shared with classic codegen.
1320 if (!fd->hasAttr<NoUniqueAddressAttr>() || !fd->getType()->isRecordType())
1322
1323 // If the field lies entirely within the enclosing class's nvsize, its tail
1324 // padding cannot overlap any already-initialized object. (The only subobjects
1325 // with greater addresses that might already be initialized are vbases.)
1326 const RecordDecl *classRD = fd->getParent();
1327 const ASTRecordLayout &layout = getContext().getASTRecordLayout(classRD);
1328 if (layout.getFieldOffset(fd->getFieldIndex()) +
1329 getContext().getTypeSize(fd->getType()) <=
1330 (uint64_t)getContext().toBits(layout.getNonVirtualSize()))
1332
1333 // The tail padding may contain values we need to preserve.
1335}
1336
static bool isBlockVarRef(const Expr *E)
Is the value of the given expression possibly a reference to or into a __block variable?
static bool isTrivialFiller(Expr *e)
cir::ConditionOp createCondition(mlir::Value condition)
Create a loop condition.
cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base, mlir::Value stride)
cir::PointerType getPointerTo(mlir::Type ty)
cir::DoWhileOp createDoWhile(mlir::Location loc, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> condBuilder, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> bodyBuilder)
Create a do-while operation.
cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty, int64_t value)
cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value={})
Create a yield operation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
const ConstantArrayType * getAsConstantArrayType(QualType T) const
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
static bool hasSameType(QualType T1, QualType T2)
Determine whether the given types T1 and T2 are equivalent.
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
CharUnits getNonVirtualSize() const
getNonVirtualSize - Get the non-virtual size (in chars) of an object, which is the size of the object...
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Definition Expr.h:4359
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4537
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
Definition Expr.h:4549
Represents a loop initializing the elements of an array.
Definition Expr.h:5971
llvm::APInt getArraySize() const
Definition Expr.h:5993
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:5986
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:5991
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2727
QualType getElementType() const
Definition TypeBase.h:3798
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6931
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4044
Expr * getLHS() const
Definition Expr.h:4094
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4099
Expr * getRHS() const
Definition Expr.h:4096
mlir::Value getPointer() const
Definition Address.h:98
mlir::Type getElementType() const
Definition Address.h:125
static Address invalid()
Definition Address.h:76
clang::CharUnits getAlignment() const
Definition Address.h:138
bool isValid() const
Definition Address.h:77
mlir::Value emitRawPointer() const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
Definition Address.h:112
An aggregate value slot.
IsZeroed_t isZeroed() const
Overlap_t mayOverlap() const
static AggValueSlot forAddr(Address addr, clang::Qualifiers quals, IsDestructed_t isDestructed, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed)
IsDestructed_t isExternallyDestructed() const
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed)
void setExternallyDestructed(bool destructed=true)
static AggValueSlot ignored()
Returns an aggregate value slot indicating that the aggregate value is being ignored.
IsAliased_t isPotentiallyAliased() const
void setVolatile(bool flag)
cir::CmpThreeWayOp createThreeWayCmpTotalOrdering(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, const llvm::APSInt &ltRes, const llvm::APSInt &eqRes, const llvm::APSInt &gtRes, cir::CmpOrdering ordering)
cir::CmpThreeWayOp createThreeWayCmpPartialOrdering(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, const llvm::APSInt &ltRes, const llvm::APSInt &eqRes, const llvm::APSInt &gtRes, const llvm::APSInt &unorderedRes)
cir::StoreOp createStore(mlir::Location loc, mlir::Value val, Address dst, bool isVolatile=false, mlir::IntegerAttr align={}, cir::SyncScopeKindAttr scope={}, cir::MemOrderAttr order={})
cir::ConstantOp getConstInt(mlir::Location loc, llvm::APSInt intVal)
cir::LoadOp createLoad(mlir::Location loc, Address addr, bool isVolatile=false)
An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
static bool hasScalarEvaluationKind(clang::QualType type)
mlir::Type convertType(clang::QualType t)
static cir::TypeEvaluationKind getEvaluationKind(clang::QualType type)
Return the cir::TypeEvaluationKind of QualType type.
CIRGenTypes & getTypes() const
const clang::LangOptions & getLangOpts() const
cir::AllocaOp createTempAlloca(mlir::Type ty, mlir::Location loc, const Twine &name="tmp", mlir::Value arraySize=nullptr, bool insertIntoFnEntryBlock=false)
This creates an alloca and inserts it into the entry block if ArraySize is nullptr,...
RValue emitCallExpr(const clang::CallExpr *e, ReturnValueSlot returnValue=ReturnValueSlot())
LValue emitLValue(const clang::Expr *e)
Emit code to compute a designator that specifies the location of the expression.
void emitAggregateCopy(LValue dest, LValue src, QualType eltTy, AggValueSlot::Overlap_t mayOverlap, bool isVolatile=false)
Emit an aggregate copy.
void pushIrregularPartialArrayCleanup(mlir::Value arrayBegin, Address arrayEndPointer, QualType elementType, CharUnits elementAlign, Destroyer *destroyer)
Push an EH cleanup to destroy already-constructed elements of the given array.
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
void emitAggregateStore(mlir::Value value, Address dest)
RValue emitAtomicExpr(AtomicExpr *e)
void emitNullInitialization(mlir::Location loc, Address destPtr, QualType ty)
RValue emitReferenceBindingToExpr(const Expr *e)
Emits a reference binding to the passed in expression.
void pushDestroyAndDeferDeactivation(QualType::DestructionKind dtorKind, Address addr, QualType type)
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *fd)
void emitCXXConstructExpr(const clang::CXXConstructExpr *e, AggValueSlot dest)
LValue emitAggExprToLValue(const Expr *e)
void emitStoreOfScalar(mlir::Value value, Address addr, bool isVolatile, clang::QualType ty, LValueBaseInfo baseInfo, bool isInit=false, bool isNontemporal=false)
static bool hasAggregateEvaluationKind(clang::QualType type)
void emitScalarInit(const clang::Expr *init, mlir::Location loc, LValue lvalue, bool capturedByInit=false)
LValue emitLValueForFieldInitialization(LValue base, const clang::FieldDecl *field, llvm::StringRef fieldName)
Like emitLValueForField, excpet that if the Field is a reference, this will return the address of the...
mlir::Value emitScalarExpr(const clang::Expr *e, bool ignoreResultAssign=false)
Emit the computation of the specified expression of scalar type.
Address getAddressOfDirectBaseInCompleteClass(mlir::Location loc, Address value, const CXXRecordDecl *derived, const CXXRecordDecl *base, bool baseIsVirtual)
Convert the given pointer to a complete class to the given direct base.
CIRGenBuilderTy & getBuilder()
AggValueSlot::Overlap_t getOverlapForBaseInit(const CXXRecordDecl *rd, const CXXRecordDecl *baseRD, bool isVirtual)
Determine whether a base class initialization may overlap some other object.
Destroyer * getDestroyer(clang::QualType::DestructionKind kind)
void emitComplexExprIntoLValue(const Expr *e, LValue dest, bool isInit)
void emitCXXThrowExpr(const CXXThrowExpr *e)
LValue makeAddrLValue(Address addr, QualType ty, AlignmentSource source=AlignmentSource::Type)
mlir::Value emitStoreThroughBitfieldLValue(RValue src, LValue dstresult)
std::optional< mlir::Location > currSrcLoc
Use to track source locations across nested visitor traversals.
clang::ASTContext & getContext() const
void emitInheritedCXXConstructorCall(const CXXConstructorDecl *d, bool forVirtualBase, Address thisAddr, bool inheritedFromVBase, const CXXInheritedCtorInitExpr *e)
void emitStoreThroughLValue(RValue src, LValue dst, bool isInit=false)
Store the specified rvalue into the specified lvalue, where both are guaranteed to the have the same ...
Address createMemTemp(QualType t, mlir::Location loc, const Twine &name="tmp", Address *alloca=nullptr, mlir::OpBuilder::InsertPoint ip={})
Create a temporary memory object of the given type, with appropriate alignmen and cast it to the defa...
void emitAggExpr(const clang::Expr *e, AggValueSlot slot)
mlir::Value emitVAArg(VAArgExpr *ve)
Generate code to get an argument from the passed in pointer and update it accordingly.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
mlir::Value emitNullConstant(QualType t, mlir::Location loc)
Return the result of value-initializing the given type, i.e.
llvm::DenseMap< const clang::FieldDecl *, llvm::StringRef > lambdaFieldToName
Keep a map between lambda fields and names, this needs to be per module since lambdas might get gener...
bool isZeroInitializable(clang::QualType ty)
Return whether a type can be zero-initialized (in the C++ sense) with an LLVM zeroinitializer.
Address getAddress() const
This trivial value class is used to represent the result of an expression that is evaluated.
Definition CIRGenValue.h:33
Address getAggregateAddress() const
Return the value of the address of the aggregate.
Definition CIRGenValue.h:69
bool isAggregate() const
Definition CIRGenValue.h:51
static RValue get(mlir::Value v)
Definition CIRGenValue.h:83
CXXTemporary * getTemporary()
Definition ExprCXX.h:1515
const Expr * getSubExpr() const
Definition ExprCXX.h:1519
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1274
Expr * getExpr()
Get the initialization expression that will be used.
Definition ExprCXX.cpp:1112
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1755
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition ExprCXX.h:1796
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition ExprCXX.h:1792
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
Definition ExprCXX.h:1806
Represents a list-initialization with parenthesis.
Definition ExprCXX.h:5141
MutableArrayRef< Expr * > getInitExprs()
Definition ExprCXX.h:5181
FieldDecl * getInitializedFieldInUnion()
Definition ExprCXX.h:5215
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
bool isTriviallyCopyable() const
Determine whether this class is considered trivially copyable per (C++11 [class]p6).
Definition DeclCXX.cpp:611
SourceRange getSourceRange() const LLVM_READONLY
Definition ExprCXX.h:357
An expression "T()" which creates an rvalue of a non-class type T.
Definition ExprCXX.h:2200
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition ExprCXX.h:804
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1212
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition ExprCXX.h:852
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Definition Expr.cpp:1609
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3682
CastKind getCastKind() const
Definition Expr.h:3726
static const char * getCastKindName(CastKind CK)
Definition Expr.cpp:1957
Expr * getSubExpr()
Definition Expr.h:3732
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
Definition CharUnits.h:214
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition Expr.h:4854
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Definition Expr.h:4890
bool isPartial() const
True iff the comparison is not totally ordered.
const ValueInfo * getLess() const
const ValueInfo * getUnordered() const
const CXXRecordDecl * Record
The declaration for the comparison category type from the standard library.
bool isStrong() const
True iff the comparison is "strong".
const ValueInfo * getGreater() const
const ValueInfo * getEqualOrEquiv() const
const Expr * getInitializer() const
Definition Expr.h:3639
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3824
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1276
bool hasAttr() const
Definition DeclBase.h:585
InitListExpr * getUpdater() const
Definition Expr.h:5939
This represents one expression.
Definition Expr.h:112
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3095
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
Definition Expr.cpp:3697
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:283
QualType getType() const
Definition Expr.h:144
Represents a member of a struct/union/class.
Definition Decl.h:3182
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition Decl.h:3267
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition Decl.h:3418
const Expr * getSubExpr() const
Definition Expr.h:1068
Expr * getResultExpr()
Return the result expression of this controlling expression.
Definition Expr.h:6471
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6060
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic,...
Definition Expr.cpp:2471
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5432
bool hadArrayRangeDesignator() const
Definition Expr.h:5486
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5408
const Expr * getInit(unsigned Init) const
Definition Expr.h:5360
ArrayRef< Expr * > inits() const
Definition Expr.h:5358
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
Definition ExprCXX.h:2087
capture_range captures() const
Retrieve this lambda's captures.
Definition ExprCXX.cpp:1378
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition ExprCXX.cpp:1407
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4920
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition ExprCXX.h:4937
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3370
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
Represents a place-holder for an object not to be initialized by anything.
Definition Expr.h:5880
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1184
const Expr * getSubExpr() const
Definition Expr.h:2205
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6807
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition TypeBase.h:8531
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition TypeBase.h:1560
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
Definition Type.cpp:2788
@ PCK_Struct
The type is a struct containing a field whose type is neither PCK_Trivial nor PCK_VolatileTrivial.
Definition TypeBase.h:1532
Represents a struct/union/class.
Definition Decl.h:4347
field_range fields() const
Definition Decl.h:4550
specific_decl_iterator< FieldDecl > field_iterator
Definition Decl.h:4547
field_iterator field_begin() const
Definition Decl.cpp:5271
CompoundStmt * getSubStmt()
Definition Expr.h:4618
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
const char * getStmtClassName() const
Definition Stmt.cpp:86
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition Type.h:26
bool isConstantArrayType() const
Definition TypeBase.h:8787
bool isArrayType() const
Definition TypeBase.h:8783
bool isPointerType() const
Definition TypeBase.h:8684
bool isReferenceType() const
Definition TypeBase.h:8708
bool isVariableArrayType() const
Definition TypeBase.h:8795
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition TypeBase.h:9172
bool isAggregateType() const
Determines whether the type is a C++ aggregate type or C aggregate or union type.
Definition Type.cpp:2503
RecordDecl * castAsRecordDecl() const
Definition Type.h:48
bool isAnyComplexType() const
Definition TypeBase.h:8819
bool isMemberPointerType() const
Definition TypeBase.h:8765
bool isRealFloatingType() const
Floating point categories.
Definition Type.cpp:2405
bool isNullPtrType() const
Definition TypeBase.h:9087
bool isRecordType() const
Definition TypeBase.h:8811
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2250
Expr * getSubExpr() const
Definition Expr.h:2291
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4963
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:924
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
constexpr Variable var(Literal L)
Returns the variable of L.
Definition CNFFormula.h:64
@ Address
A pointer to a ValueDecl.
Definition Primitives.h:28
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ CPlusPlus
U cast(CodeGen::Address addr)
Definition Address.h:327
unsigned long uint64_t
static bool emitLifetimeMarkers()
static bool aggValueSlotDestructedFlag()
static bool aggValueSlotGC()
static bool aggValueSlotAlias()
static bool opLoadStoreAtomic()
static bool aggEmitFinalDestCopyRValue()
static bool cleanupDeactivationScope()
static bool aggValueSlotVolatile()
static bool atomicTypes()
static bool cudaSupport()
static bool incrementProfileCounter()
clang::CharUnits getPointerAlign() const
llvm::APSInt getIntValue() const
Get the constant integer value used by this variable to represent the comparison category result type...