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 cgf.cgm.errorNYI(e->getSourceRange(),
519 "AggExprEmitter: VisitImplicitValueInitExpr");
520 }
521 void VisitNoInitExpr(NoInitExpr *e) {
522 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitNoInitExpr");
523 }
524 void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *dae) {
526 Visit(dae->getExpr());
527 }
528 void VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *e) {
529 AggValueSlot slot =
530 ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
532 e->constructsVBase(), slot.getAddress(),
533 e->inheritedFromVBase(), e);
534 }
535
536 /// Emit the initializer for a std::initializer_list initialized with a
537 /// real initializer list.
538 void VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *e) {
539 ASTContext &ctx = cgf.getContext();
540 CIRGenBuilderTy builder = cgf.getBuilder();
541 mlir::Location loc = cgf.getLoc(e->getExprLoc());
542
543 LValue array = cgf.emitLValue(e->getSubExpr());
544 assert(array.isSimple() && "initializer_list array not a simple lvalue");
545 Address arrayPtr = array.getAddress();
546
549 assert(arrayType && "std::initializer_list constructed from non-array");
550
551 auto *record = e->getType()->castAsRecordDecl();
552 assert(record->getNumFields() == 2 &&
553 "Expected std::initializer_list to only have two fields");
554
555 RecordDecl::field_iterator field = record->field_begin();
556 assert(field != record->field_end() &&
557 ctx.hasSameType(field->getType()->getPointeeType(),
558 arrayType->getElementType()) &&
559 "Expected std::initializer_list first field to be const E *");
560
561 // Start pointer.
562 AggValueSlot dest = ensureSlot(loc, e->getType());
563 LValue destLV = cgf.makeAddrLValue(dest.getAddress(), e->getType());
564 LValue start =
565 cgf.emitLValueForFieldInitialization(destLV, *field, field->getName());
566
567 mlir::Value arrayStart = arrayPtr.emitRawPointer();
568 cgf.emitStoreThroughLValue(RValue::get(arrayStart), start);
569 ++field;
570 assert(field != record->field_end() &&
571 "Expected std::initializer_list to have two fields");
572
573 cir::ConstantOp size = builder.getConstInt(loc, arrayType->getSize());
574 LValue endOrLength =
575 cgf.emitLValueForFieldInitialization(destLV, *field, field->getName());
576 if (ctx.hasSameType(field->getType(), ctx.getSizeType())) {
577 // Length.
578 cgf.emitStoreThroughLValue(RValue::get(size), endOrLength);
579 } else {
580 // End pointer.
581 assert(field->getType()->isPointerType() &&
582 ctx.hasSameType(field->getType()->getPointeeType(),
583 arrayType->getElementType()) &&
584 "Expected std::initializer_list second field to be const E *");
585 mlir::Value arrayEnd = builder.createPtrStride(loc, arrayStart, size);
586 cgf.emitStoreThroughLValue(RValue::get(arrayEnd), endOrLength);
587 }
588 }
589
590 void VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *e) {
591 cgf.cgm.errorNYI(e->getSourceRange(),
592 "AggExprEmitter: VisitCXXScalarValueInitExpr");
593 }
594 void VisitCXXTypeidExpr(CXXTypeidExpr *e) { emitAggLoadOfLValue(e); }
595 void VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *e) {
596 Visit(e->getSubExpr());
597 }
598 void VisitOpaqueValueExpr(OpaqueValueExpr *e) {
599 cgf.cgm.errorNYI(e->getSourceRange(),
600 "AggExprEmitter: VisitOpaqueValueExpr");
601 }
602
603 void VisitPseudoObjectExpr(PseudoObjectExpr *e) {
604 cgf.cgm.errorNYI(e->getSourceRange(),
605 "AggExprEmitter: VisitPseudoObjectExpr");
606 }
607
608 void VisitVAArgExpr(VAArgExpr *e) {
609 // emitVAArg returns an aggregate value (not a pointer) at the CIR level.
610 // ABI-specific pointer handling will be done later in LoweringPrepare.
611 mlir::Value vaArgValue = cgf.emitVAArg(e);
612
613 // Create a temporary alloca to hold the aggregate value.
614 mlir::Location loc = cgf.getLoc(e->getSourceRange());
615 Address tmpAddr = cgf.createMemTemp(e->getType(), loc, "vaarg.tmp");
616
617 // Store the va_arg result into the temporary.
618 cgf.emitAggregateStore(vaArgValue, tmpAddr);
619
620 // Create an LValue from the temporary address.
621 LValue tmpLValue = cgf.makeAddrLValue(tmpAddr, e->getType());
622
623 // Copy the aggregate value from temporary to destination.
624 emitFinalDestCopy(e->getType(), tmpLValue);
625 }
626
627 void VisitCXXThrowExpr(const CXXThrowExpr *e) {
628 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCXXThrowExpr");
629 }
630 void VisitAtomicExpr(AtomicExpr *e) {
631 RValue result = cgf.emitAtomicExpr(e);
632 emitFinalDestCopy(e->getType(), result);
633 }
634};
635
636} // namespace
637
638static bool isTrivialFiller(Expr *e) {
639 if (!e)
640 return true;
641
643 return true;
644
645 if (auto *ile = dyn_cast<InitListExpr>(e)) {
646 if (ile->getNumInits())
647 return false;
648 return isTrivialFiller(ile->getArrayFiller());
649 }
650
651 if (const auto *cons = dyn_cast_or_null<CXXConstructExpr>(e))
652 return cons->getConstructor()->isDefaultConstructor() &&
653 cons->getConstructor()->isTrivial();
654
655 return false;
656}
657
658/// Given an expression with aggregate type that represents a value lvalue, this
659/// method emits the address of the lvalue, then loads the result into DestPtr.
660void AggExprEmitter::emitAggLoadOfLValue(const Expr *e) {
661 LValue lv = cgf.emitLValue(e);
662
663 // If the type of the l-value is atomic, then do an atomic load.
665
666 emitFinalDestCopy(e->getType(), lv);
667}
668
669void AggExprEmitter::VisitCompoundLiteralExpr(CompoundLiteralExpr *e) {
670 if (dest.isPotentiallyAliased() && e->getType().isPODType(cgf.getContext())) {
671 // For a POD type, just emit a load of the lvalue + a copy, because our
672 // compound literal might alias the destination.
673 emitAggLoadOfLValue(e);
674 return;
675 }
676
677 AggValueSlot slot = ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
678
679 // Block-scope compound literals are destroyed at the end of the enclosing
680 // scope in C.
681 bool destruct =
682 !cgf.getLangOpts().CPlusPlus && !slot.isExternallyDestructed();
683 if (destruct)
685
686 cgf.emitAggExpr(e->getInitializer(), slot);
687
688 if (destruct)
689 if ([[maybe_unused]] QualType::DestructionKind dtorKind =
691 cgf.cgm.errorNYI(e->getSourceRange(), "compound literal with destructor");
692}
693
694void AggExprEmitter::emitArrayInit(Address destPtr, cir::ArrayType arrayTy,
695 QualType arrayQTy, Expr *e,
696 ArrayRef<Expr *> args, Expr *arrayFiller) {
697 CIRGenBuilderTy &builder = cgf.getBuilder();
698 const mlir::Location loc = cgf.getLoc(e->getSourceRange());
699
700 const uint64_t numInitElements = args.size();
701
702 bool setArrayInitLoopExprScope = isa<ArrayInitLoopExpr>(e);
703
704 const QualType elementType =
705 cgf.getContext().getAsArrayType(arrayQTy)->getElementType();
706
707 const QualType elementPtrType = cgf.getContext().getPointerType(elementType);
708
709 const mlir::Type cirElementType = cgf.convertType(elementType);
710 const cir::PointerType cirElementPtrType =
711 builder.getPointerTo(cirElementType);
712
713 auto begin = cir::CastOp::create(builder, loc, cirElementPtrType,
714 cir::CastKind::array_to_ptrdecay,
715 destPtr.getPointer());
716
717 const CharUnits elementSize =
718 cgf.getContext().getTypeSizeInChars(elementType);
719 const CharUnits elementAlign =
720 destPtr.getAlignment().alignmentOfArrayElement(elementSize);
721
722 // Exception safety requires us to destroy all the already-constructed
723 // members if an initializer throws. For that, we'll need an EH cleanup.
724 QualType::DestructionKind dtorKind = elementType.isDestructedType();
725 Address endOfInit = Address::invalid();
727
728 if (dtorKind && cgf.getLangOpts().Exceptions) {
729 endOfInit = cgf.createTempAlloca(cirElementPtrType, cgf.getPointerAlign(),
730 loc, "arrayinit.endOfInit");
731 builder.createStore(loc, begin, endOfInit);
732
733 cgf.pushIrregularPartialArrayCleanup(begin, endOfInit, elementType,
734 elementAlign,
735 cgf.getDestroyer(dtorKind));
736 }
737
738 // The 'current element to initialize'. The invariants on this
739 // variable are complicated. Essentially, after each iteration of
740 // the loop, it points to the last initialized element, except
741 // that it points to the beginning of the array before any
742 // elements have been initialized.
743 mlir::Value element = begin;
744
745 // Don't build the 'one' before the cycle to avoid
746 // emmiting the redundant `cir.const 1` instrs.
747 mlir::Value one;
748
749 // Emit the explicit initializers.
750 for (uint64_t i = 0; i != numInitElements; ++i) {
751 // Advance to the next element.
752 if (i > 0) {
753 one = builder.getConstantInt(loc, cgf.ptrDiffTy, i);
754 element = builder.createPtrStride(loc, begin, one);
755
756 // Tell the cleanup that it needs to destroy up to this element.
757 if (endOfInit.isValid())
758 builder.createStore(loc, element, endOfInit);
759 }
760
761 const Address address = Address(element, cirElementType, elementAlign);
762 const LValue elementLV = cgf.makeAddrLValue(address, elementType);
763 emitInitializationToLValue(args[i], elementLV);
764 }
765
766 const uint64_t numArrayElements = arrayTy.getSize();
767
768 // Check whether there's a non-trivial array-fill expression.
769 const bool hasTrivialFiller = isTrivialFiller(arrayFiller);
770
771 // Any remaining elements need to be zero-initialized, possibly
772 // using the filler expression. We can skip this if the we're
773 // emitting to zeroed memory.
774 if (numInitElements != numArrayElements &&
775 !(dest.isZeroed() && hasTrivialFiller &&
776 cgf.getTypes().isZeroInitializable(elementType))) {
777 // Advance to the start of the rest of the array.
778 if (numInitElements) {
779 one = builder.getConstantInt(loc, cgf.ptrDiffTy, 1);
780 element = cir::PtrStrideOp::create(builder, loc, cirElementPtrType,
781 element, one);
782
783 if (endOfInit.isValid())
784 builder.createStore(loc, element, endOfInit);
785 }
786
787 // Allocate the temporary variable
788 // to store the pointer to first unitialized element
789 const Address tmpAddr = cgf.createTempAlloca(
790 cirElementPtrType, cgf.getPointerAlign(), loc, "arrayinit.temp");
791 LValue tmpLV = cgf.makeAddrLValue(tmpAddr, elementPtrType);
792 cgf.emitStoreThroughLValue(RValue::get(element), tmpLV);
793
794 // Compute the end of array
795 cir::ConstantOp numArrayElementsConst = builder.getConstInt(
796 loc, mlir::cast<cir::IntType>(cgf.ptrDiffTy), numArrayElements);
797 mlir::Value end = cir::PtrStrideOp::create(builder, loc, cirElementPtrType,
798 begin, numArrayElementsConst);
799
800 builder.createDoWhile(
801 loc,
802 /*condBuilder=*/
803 [&](mlir::OpBuilder &b, mlir::Location loc) {
804 cir::LoadOp currentElement = builder.createLoad(loc, tmpAddr);
805 cir::CmpOp cmp = cir::CmpOp::create(builder, loc, cir::CmpOpKind::ne,
806 currentElement, end);
807 builder.createCondition(cmp);
808 },
809 /*bodyBuilder=*/
810 [&](mlir::OpBuilder &b, mlir::Location loc) {
811 cir::LoadOp currentElement = builder.createLoad(loc, tmpAddr);
812
813 // Emit the actual filler expression.
814 LValue elementLV = cgf.makeAddrLValue(
815 Address(currentElement, cirElementType, elementAlign),
816 elementType);
817
818 mlir::Value idx;
819 if (setArrayInitLoopExprScope)
820 idx = cir::PtrDiffOp::create(b, loc, cgf.ptrDiffTy, currentElement,
821 begin);
822
823 CIRGenFunction::ArrayInitLoopExprScope loopExprScope(
824 cgf, setArrayInitLoopExprScope, idx);
825
826 if (arrayFiller)
827 emitInitializationToLValue(arrayFiller, elementLV);
828 else
829 emitNullInitializationToLValue(loc, elementLV);
830
831 // Advance pointer and store them to temporary variable
832 cir::ConstantOp one = builder.getConstInt(
833 loc, mlir::cast<cir::IntType>(cgf.ptrDiffTy), 1);
834 auto nextElement = cir::PtrStrideOp::create(
835 builder, loc, cirElementPtrType, currentElement, one);
836
837 // Tell the EH cleanup that we finished with the last element.
838 if (endOfInit.isValid())
839 builder.createStore(loc, nextElement, endOfInit);
840
841 cgf.emitStoreThroughLValue(RValue::get(nextElement), tmpLV);
842
843 builder.createYield(loc);
844 });
845 }
846}
847
848/// EmitFinalDestCopy - Perform the final copy to DestPtr, if desired.
849void AggExprEmitter::emitFinalDestCopy(QualType type, RValue src) {
850 assert(src.isAggregate() && "value must be aggregate value!");
851 LValue srcLV = cgf.makeAddrLValue(src.getAggregateAddress(), type);
852 emitFinalDestCopy(type, srcLV, CIRGenFunction::EVK_RValue);
853}
854
855/// Perform the final copy to destPtr, if desired.
856void AggExprEmitter::emitFinalDestCopy(
857 QualType type, const LValue &src,
858 CIRGenFunction::ExprValueKind srcValueKind) {
859 // If dest is ignored, then we're evaluating an aggregate expression
860 // in a context that doesn't care about the result. Note that loads
861 // from volatile l-values force the existence of a non-ignored
862 // destination.
863 if (dest.isIgnored())
864 return;
865
866 if (srcValueKind == CIRGenFunction::EVK_RValue) {
867 if (type.isNonTrivialToPrimitiveDestructiveMove() == QualType::PCK_Struct) {
868 cgf.cgm.errorNYI("emitFinalDestCopy: EVK_RValue & PCK_Struct");
869 }
870 } else {
871 if (type.isNonTrivialToPrimitiveCopy() == QualType::PCK_Struct) {
872 cgf.cgm.errorNYI("emitFinalDestCopy: !EVK_RValue & PCK_Struct");
873 }
874 }
875
879
880 AggValueSlot srcAgg = AggValueSlot::forLValue(src, AggValueSlot::IsDestructed,
883 emitCopy(type, dest, srcAgg);
884}
885
886/// Perform a copy from the source into the destination.
887///
888/// \param type - the type of the aggregate being copied; qualifiers are
889/// ignored
890void AggExprEmitter::emitCopy(QualType type, const AggValueSlot &dest,
891 const AggValueSlot &src) {
893
894 // If the result of the assignment is used, copy the LHS there also.
895 // It's volatile if either side is. Use the minimum alignment of
896 // the two sides.
897 LValue destLV = cgf.makeAddrLValue(dest.getAddress(), type);
898 LValue srcLV = cgf.makeAddrLValue(src.getAddress(), type);
900 cgf.emitAggregateCopy(destLV, srcLV, type, dest.mayOverlap(),
901 dest.isVolatile() || src.isVolatile());
902}
903
904void AggExprEmitter::emitInitializationToLValue(Expr *e, LValue lv) {
905 const QualType type = lv.getType();
906
908 const mlir::Location loc = e->getSourceRange().isValid()
909 ? cgf.getLoc(e->getSourceRange())
910 : *cgf.currSrcLoc;
911 return emitNullInitializationToLValue(loc, lv);
912 }
913
914 if (isa<NoInitExpr>(e))
915 return;
916
917 if (type->isReferenceType()) {
918 RValue rv = cgf.emitReferenceBindingToExpr(e);
919 return cgf.emitStoreThroughLValue(rv, lv);
920 }
921
922 switch (cgf.getEvaluationKind(type)) {
923 case cir::TEK_Complex:
924 cgf.emitComplexExprIntoLValue(e, lv, /*isInit*/ true);
925 break;
930 dest.isZeroed()));
931
932 return;
933 case cir::TEK_Scalar:
934 if (lv.isSimple())
935 cgf.emitScalarInit(e, cgf.getLoc(e->getSourceRange()), lv);
936 else
938 return;
939 }
940}
941
942void AggExprEmitter::VisitCXXConstructExpr(const CXXConstructExpr *e) {
943 AggValueSlot slot = ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
944 cgf.emitCXXConstructExpr(e, slot);
945}
946
947void AggExprEmitter::emitNullInitializationToLValue(mlir::Location loc,
948 LValue lv) {
949 const QualType type = lv.getType();
950
951 // If the destination slot is already zeroed out before the aggregate is
952 // copied into it, we don't have to emit any zeros here.
953 if (dest.isZeroed() && cgf.getTypes().isZeroInitializable(type))
954 return;
955
956 if (cgf.hasScalarEvaluationKind(type)) {
957 // For non-aggregates, we can store the appropriate null constant.
958 mlir::Value null = cgf.cgm.emitNullConstant(type, loc);
959 if (lv.isSimple()) {
960 cgf.emitStoreOfScalar(null, lv, /* isInitialization */ true);
961 return;
962 }
963
965 return;
966 }
967
968 // There's a potential optimization opportunity in combining
969 // memsets; that would be easy for arrays, but relatively
970 // difficult for structures with the current code.
971 cgf.emitNullInitialization(loc, lv.getAddress(), lv.getType());
972}
973
974void AggExprEmitter::VisitLambdaExpr(LambdaExpr *e) {
975 CIRGenFunction::SourceLocRAIIObject loc{cgf, cgf.getLoc(e->getSourceRange())};
976 AggValueSlot slot = ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
977 LValue slotLV = cgf.makeAddrLValue(slot.getAddress(), e->getType());
978
979 // We'll need to enter cleanup scopes in case any of the element
980 // initializers throws an exception or contains branch out of the expressions.
981 CIRGenFunction::CleanupDeactivationScope deactivationScope(cgf);
982
983 for (auto [curField, capture, captureInit] : llvm::zip(
984 e->getLambdaClass()->fields(), e->captures(), e->capture_inits())) {
985 // Pick a name for the field.
986 llvm::StringRef fieldName = curField->getName();
987 if (capture.capturesVariable()) {
988 assert(!curField->isBitField() && "lambdas don't have bitfield members!");
989 ValueDecl *v = capture.getCapturedVar();
990 fieldName = v->getName();
991 cgf.cgm.lambdaFieldToName[curField] = fieldName;
992 } else if (capture.capturesThis()) {
993 cgf.cgm.lambdaFieldToName[curField] = "this";
994 } else {
995 cgf.cgm.errorNYI(e->getSourceRange(), "Unhandled capture kind");
996 cgf.cgm.lambdaFieldToName[curField] = "unhandled-capture-kind";
997 }
998
999 // Emit initialization
1000 LValue lv =
1001 cgf.emitLValueForFieldInitialization(slotLV, curField, fieldName);
1002 if (curField->hasCapturedVLAType())
1003 cgf.cgm.errorNYI(e->getSourceRange(), "lambda captured VLA type");
1004
1005 emitInitializationToLValue(captureInit, lv);
1006
1007 // Push a destructor if necessary.
1008 if (QualType::DestructionKind dtorKind =
1009 curField->getType().isDestructedType()) {
1010 assert(lv.isSimple());
1012 curField->getType(),
1013 cgf.getDestroyer(dtorKind), false);
1014 }
1015 }
1016}
1017
1018void AggExprEmitter::VisitExprWithCleanups(ExprWithCleanups *e) {
1019 CIRGenFunction::FullExprCleanupScope fullExprScope(cgf, e->getSubExpr());
1020 Visit(e->getSubExpr());
1021}
1022
1023void AggExprEmitter::VisitCallExpr(const CallExpr *e) {
1024 if (e->getCallReturnType(cgf.getContext())->isReferenceType()) {
1025 cgf.cgm.errorNYI(e->getSourceRange(), "reference return type");
1026 return;
1027 }
1028
1029 withReturnValueSlot(
1030 e, [&](ReturnValueSlot slot) { return cgf.emitCallExpr(e, slot); });
1031}
1032
1033void AggExprEmitter::withReturnValueSlot(
1034 const Expr *e, llvm::function_ref<RValue(ReturnValueSlot)> fn) {
1035 QualType retTy = e->getType();
1036
1038 bool requiresDestruction =
1040 if (requiresDestruction)
1041 cgf.cgm.errorNYI(
1042 e->getSourceRange(),
1043 "withReturnValueSlot: return value requiring destruction is NYI");
1044
1045 // If it makes no observable difference, save a memcpy + temporary.
1046 //
1047 // We need to always provide our own temporary if destruction is required.
1048 // Otherwise, fn will emit its own, notice that it's "unused", and end its
1049 // lifetime before we have the chance to emit a proper destructor call.
1052
1053 Address retAddr = dest.getAddress();
1055
1058 fn(ReturnValueSlot(retAddr));
1059}
1060
1061void AggExprEmitter::VisitInitListExpr(InitListExpr *e) {
1062 if (e->hadArrayRangeDesignator())
1063 llvm_unreachable("GNU array range designator extension");
1064
1065 if (e->isTransparent())
1066 return Visit(e->getInit(0));
1067
1068 visitCXXParenListOrInitListExpr(
1069 e, e->inits(), e->getInitializedFieldInUnion(), e->getArrayFiller());
1070}
1071
1072void AggExprEmitter::visitCXXParenListOrInitListExpr(
1073 Expr *e, ArrayRef<Expr *> args, FieldDecl *initializedFieldInUnion,
1074 Expr *arrayFiller) {
1075
1076 const mlir::Location loc = cgf.getLoc(e->getSourceRange());
1077 const AggValueSlot dest = ensureSlot(loc, e->getType());
1078
1079 if (e->getType()->isConstantArrayType()) {
1080 cir::ArrayType arrayTy =
1082 emitArrayInit(dest.getAddress(), arrayTy, e->getType(), e, args,
1083 arrayFiller);
1084 return;
1085 } else if (e->getType()->isVariableArrayType()) {
1086 cgf.cgm.errorNYI(e->getSourceRange(),
1087 "visitCXXParenListOrInitListExpr variable array type");
1088 return;
1089 }
1090
1091 if (e->getType()->isArrayType()) {
1092 cgf.cgm.errorNYI(e->getSourceRange(),
1093 "visitCXXParenListOrInitListExpr array type");
1094 return;
1095 }
1096
1097 assert(e->getType()->isRecordType() && "Only support structs/unions here!");
1098
1099 // Do struct initialization; this code just sets each individual member
1100 // to the approprate value. This makes bitfield support automatic;
1101 // the disadvantage is that the generated code is more difficult for
1102 // the optimizer, especially with bitfields.
1103 unsigned numInitElements = args.size();
1104 auto *record = e->getType()->castAsRecordDecl();
1105
1106 // We'll need to enter cleanup scopes in case any of the element
1107 // initializers throws an exception.
1108 CIRGenFunction::CleanupDeactivationScope deactivateCleanups(cgf);
1109
1110 unsigned curInitIndex = 0;
1111
1112 // Emit initialization of base classes.
1113 if (auto *cxxrd = dyn_cast<CXXRecordDecl>(record)) {
1114 assert(numInitElements >= cxxrd->getNumBases() &&
1115 "missing initializer for base class");
1116 for (auto &base : cxxrd->bases()) {
1117 assert(!base.isVirtual() && "should not see vbases here");
1118 CXXRecordDecl *baseRD = base.getType()->getAsCXXRecordDecl();
1120 loc, dest.getAddress(), cxxrd, baseRD,
1121 /*baseIsVirtual=*/false);
1123 AggValueSlot aggSlot = AggValueSlot::forAddr(
1124 address, Qualifiers(), AggValueSlot::IsDestructed,
1126 cgf.getOverlapForBaseInit(cxxrd, baseRD, false));
1127 cgf.emitAggExpr(args[curInitIndex++], aggSlot);
1128 if (base.getType().isDestructedType()) {
1129 cgf.cgm.errorNYI(e->getSourceRange(),
1130 "push deferred deactivation cleanup");
1131 return;
1132 }
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)
__device__ __2f16 b
__device__ __2f16 float __ockl_bool s
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:227
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:4356
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4534
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
Definition Expr.h:4546
Represents a loop initializing the elements of an array.
Definition Expr.h:5969
llvm::APInt getArraySize() const
Definition Expr.h:5991
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:5984
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:5989
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2724
QualType getElementType() const
Definition TypeBase.h:3789
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6929
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4041
Expr * getLHS() const
Definition Expr.h:4091
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4096
Expr * getRHS() const
Definition Expr.h:4093
mlir::Value getPointer() const
Definition Address.h:96
mlir::Type getElementType() const
Definition Address.h:123
static Address invalid()
Definition Address.h:74
clang::CharUnits getAlignment() const
Definition Address.h:136
bool isValid() const
Definition Address.h:75
mlir::Value emitRawPointer() const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
Definition Address.h:110
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)
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:1107
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:610
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:1603
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3679
CastKind getCastKind() const
Definition Expr.h:3723
static const char * getCastKindName(CastKind CK)
Definition Expr.cpp:1951
Expr * getSubExpr()
Definition Expr.h:3729
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:4851
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Definition Expr.h:4887
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:3636
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3815
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1273
bool hasAttr() const
Definition DeclBase.h:585
InitListExpr * getUpdater() const
Definition Expr.h:5937
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:3086
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:3688
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:277
QualType getType() const
Definition Expr.h:144
Represents a member of a struct/union/class.
Definition Decl.h:3178
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition Decl.h:3263
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition Decl.h:3414
const Expr * getSubExpr() const
Definition Expr.h:1065
Expr * getResultExpr()
Return the result expression of this controlling expression.
Definition Expr.h:6469
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6058
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic,...
Definition Expr.cpp:2462
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5426
bool hadArrayRangeDesignator() const
Definition Expr.h:5484
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5402
const Expr * getInit(unsigned Init) const
Definition Expr.h:5354
ArrayRef< Expr * > inits() const
Definition Expr.h:5352
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:1373
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition ExprCXX.cpp:1402
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:3367
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:5878
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1181
const Expr * getSubExpr() const
Definition Expr.h:2202
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6805
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition TypeBase.h:8520
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition TypeBase.h:1556
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:1528
Represents a struct/union/class.
Definition Decl.h:4343
field_range fields() const
Definition Decl.h:4546
specific_decl_iterator< FieldDecl > field_iterator
Definition Decl.h:4543
field_iterator field_begin() const
Definition Decl.cpp:5270
CompoundStmt * getSubStmt()
Definition Expr.h:4615
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
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:8776
bool isArrayType() const
Definition TypeBase.h:8772
bool isPointerType() const
Definition TypeBase.h:8673
bool isReferenceType() const
Definition TypeBase.h:8697
bool isVariableArrayType() const
Definition TypeBase.h:8784
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition TypeBase.h:9161
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:8808
bool isMemberPointerType() const
Definition TypeBase.h:8754
bool isRealFloatingType() const
Floating point categories.
Definition Type.cpp:2405
bool isNullPtrType() const
Definition TypeBase.h:9076
bool isRecordType() const
Definition TypeBase.h:8800
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2247
Expr * getSubExpr() const
Definition Expr.h:2288
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4960
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...