clang 22.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"
14#include "CIRGenFunction.h"
15#include "CIRGenValue.h"
17
18#include "clang/AST/Expr.h"
21#include <cstdint>
22
23using namespace clang;
24using namespace clang::CIRGen;
25
26namespace {
27// FIXME(cir): This should be a common helper between CIRGen
28// and traditional CodeGen
29/// Is the value of the given expression possibly a reference to or
30/// into a __block variable?
31static bool isBlockVarRef(const Expr *e) {
32 // Make sure we look through parens.
33 e = e->IgnoreParens();
34
35 // Check for a direct reference to a __block variable.
36 if (const DeclRefExpr *dre = dyn_cast<DeclRefExpr>(e)) {
37 const VarDecl *var = dyn_cast<VarDecl>(dre->getDecl());
38 return (var && var->hasAttr<BlocksAttr>());
39 }
40
41 // More complicated stuff.
42
43 // Binary operators.
44 if (const BinaryOperator *op = dyn_cast<BinaryOperator>(e)) {
45 // For an assignment or pointer-to-member operation, just care
46 // about the LHS.
47 if (op->isAssignmentOp() || op->isPtrMemOp())
48 return isBlockVarRef(op->getLHS());
49
50 // For a comma, just care about the RHS.
51 if (op->getOpcode() == BO_Comma)
52 return isBlockVarRef(op->getRHS());
53
54 // FIXME: pointer arithmetic?
55 return false;
56
57 // Check both sides of a conditional operator.
58 } else if (const AbstractConditionalOperator *op =
59 dyn_cast<AbstractConditionalOperator>(e)) {
60 return isBlockVarRef(op->getTrueExpr()) ||
61 isBlockVarRef(op->getFalseExpr());
62
63 // OVEs are required to support BinaryConditionalOperators.
64 } else if (const OpaqueValueExpr *op = dyn_cast<OpaqueValueExpr>(e)) {
65 if (const Expr *src = op->getSourceExpr())
66 return isBlockVarRef(src);
67
68 // Casts are necessary to get things like (*(int*)&var) = foo().
69 // We don't really care about the kind of cast here, except
70 // we don't want to look through l2r casts, because it's okay
71 // to get the *value* in a __block variable.
72 } else if (const CastExpr *cast = dyn_cast<CastExpr>(e)) {
73 if (cast->getCastKind() == CK_LValueToRValue)
74 return false;
75 return isBlockVarRef(cast->getSubExpr());
76
77 // Handle unary operators. Again, just aggressively look through
78 // it, ignoring the operation.
79 } else if (const UnaryOperator *uop = dyn_cast<UnaryOperator>(e)) {
80 return isBlockVarRef(uop->getSubExpr());
81
82 // Look into the base of a field access.
83 } else if (const MemberExpr *mem = dyn_cast<MemberExpr>(e)) {
84 return isBlockVarRef(mem->getBase());
85
86 // Look into the base of a subscript.
87 } else if (const ArraySubscriptExpr *sub = dyn_cast<ArraySubscriptExpr>(e)) {
88 return isBlockVarRef(sub->getBase());
89 }
90
91 return false;
92}
93
94class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
95
96 CIRGenFunction &cgf;
97 AggValueSlot dest;
98
99 // Calls `fn` with a valid return value slot, potentially creating a temporary
100 // to do so. If a temporary is created, an appropriate copy into `Dest` will
101 // be emitted, as will lifetime markers.
102 //
103 // The given function should take a ReturnValueSlot, and return an RValue that
104 // points to said slot.
105 void withReturnValueSlot(const Expr *e,
106 llvm::function_ref<RValue(ReturnValueSlot)> fn);
107
108 AggValueSlot ensureSlot(mlir::Location loc, QualType t) {
109 if (!dest.isIgnored())
110 return dest;
111 return cgf.createAggTemp(t, loc, "agg.tmp.ensured");
112 }
113
114 void ensureDest(mlir::Location loc, QualType ty) {
115 if (!dest.isIgnored())
116 return;
117 dest = cgf.createAggTemp(ty, loc, "agg.tmp.ensured");
118 }
119
120public:
121 AggExprEmitter(CIRGenFunction &cgf, AggValueSlot dest)
122 : cgf(cgf), dest(dest) {}
123
124 /// Given an expression with aggregate type that represents a value lvalue,
125 /// this method emits the address of the lvalue, then loads the result into
126 /// DestPtr.
127 void emitAggLoadOfLValue(const Expr *e);
128
129 void emitArrayInit(Address destPtr, cir::ArrayType arrayTy, QualType arrayQTy,
130 Expr *exprToVisit, ArrayRef<Expr *> args,
131 Expr *arrayFiller);
132
133 /// Perform the final copy to DestPtr, if desired.
134 void emitFinalDestCopy(QualType type, const LValue &src);
135
136 void emitCopy(QualType type, const AggValueSlot &dest,
137 const AggValueSlot &src);
138
139 void emitInitializationToLValue(Expr *e, LValue lv);
140
141 void emitNullInitializationToLValue(mlir::Location loc, LValue lv);
142
143 void Visit(Expr *e) { StmtVisitor<AggExprEmitter>::Visit(e); }
144
145 void VisitArraySubscriptExpr(ArraySubscriptExpr *e) {
146 emitAggLoadOfLValue(e);
147 }
148
149 void VisitCallExpr(const CallExpr *e);
150 void VisitStmtExpr(const StmtExpr *e) {
151 CIRGenFunction::StmtExprEvaluation eval(cgf);
152 Address retAlloca =
153 cgf.createMemTemp(e->getType(), cgf.getLoc(e->getSourceRange()));
154 (void)cgf.emitCompoundStmt(*e->getSubStmt(), &retAlloca, dest);
155 }
156
157 void VisitBinAssign(const BinaryOperator *e) {
158 // For an assignment to work, the value on the right has
159 // to be compatible with the value on the left.
160 assert(cgf.getContext().hasSameUnqualifiedType(e->getLHS()->getType(),
161 e->getRHS()->getType()) &&
162 "Invalid assignment");
163
164 if (isBlockVarRef(e->getLHS()) &&
165 e->getRHS()->HasSideEffects(cgf.getContext())) {
166 cgf.cgm.errorNYI(e->getSourceRange(),
167 "block var reference with side effects");
168 return;
169 }
170
171 LValue lhs = cgf.emitLValue(e->getLHS());
172
173 // If we have an atomic type, evaluate into the destination and then
174 // do an atomic copy.
176
177 // Codegen the RHS so that it stores directly into the LHS.
179 AggValueSlot lhsSlot = AggValueSlot::forLValue(
182
183 // A non-volatile aggregate destination might have volatile member.
184 if (!lhsSlot.isVolatile() && cgf.hasVolatileMember(e->getLHS()->getType()))
185 lhsSlot.setVolatile(true);
186
187 cgf.emitAggExpr(e->getRHS(), lhsSlot);
188
189 // Copy into the destination if the assignment isn't ignored.
190 emitFinalDestCopy(e->getType(), lhs);
191
192 if (!dest.isIgnored() && !dest.isExternallyDestructed() &&
194 cgf.pushDestroy(QualType::DK_nontrivial_c_struct, dest.getAddress(),
195 e->getType());
196 }
197
198 void VisitDeclRefExpr(DeclRefExpr *e) { emitAggLoadOfLValue(e); }
199
200 void VisitInitListExpr(InitListExpr *e);
201 void VisitCXXConstructExpr(const CXXConstructExpr *e);
202
203 void visitCXXParenListOrInitListExpr(Expr *e, ArrayRef<Expr *> args,
204 FieldDecl *initializedFieldInUnion,
205 Expr *arrayFiller);
206 void VisitCXXDefaultInitExpr(CXXDefaultInitExpr *die) {
207 CIRGenFunction::CXXDefaultInitExprScope Scope(cgf, die);
208 Visit(die->getExpr());
209 }
210 void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *e) {
211 // Ensure that we have a slot, but if we already do, remember
212 // whether it was externally destructed.
213 bool wasExternallyDestructed = dest.isExternallyDestructed();
214 ensureDest(cgf.getLoc(e->getSourceRange()), e->getType());
215
216 // We're going to push a destructor if there isn't already one.
217 dest.setExternallyDestructed();
218
219 Visit(e->getSubExpr());
220
221 // Push that destructor we promised.
222 if (!wasExternallyDestructed)
223 cgf.emitCXXTemporary(e->getTemporary(), e->getType(), dest.getAddress());
224 }
225 void VisitLambdaExpr(LambdaExpr *e);
226 void VisitExprWithCleanups(ExprWithCleanups *e);
227
228 // Stubs -- These should be moved up when they are implemented.
229 void VisitCastExpr(CastExpr *e) {
230 switch (e->getCastKind()) {
231 case CK_LValueToRValue:
232 // If we're loading from a volatile type, force the destination
233 // into existence.
235 cgf.cgm.errorNYI(e->getSourceRange(),
236 "AggExprEmitter: volatile lvalue-to-rvalue cast");
237 [[fallthrough]];
238 case CK_NoOp:
239 case CK_UserDefinedConversion:
240 case CK_ConstructorConversion:
241 assert(cgf.getContext().hasSameUnqualifiedType(e->getSubExpr()->getType(),
242 e->getType()) &&
243 "Implicit cast types must be compatible");
244 Visit(e->getSubExpr());
245 break;
246 default:
247 cgf.cgm.errorNYI(e->getSourceRange(),
248 std::string("AggExprEmitter: VisitCastExpr: ") +
249 e->getCastKindName());
250 break;
251 }
252 }
253 void VisitStmt(Stmt *s) {
254 cgf.cgm.errorNYI(s->getSourceRange(),
255 std::string("AggExprEmitter::VisitStmt: ") +
256 s->getStmtClassName());
257 }
258 void VisitParenExpr(ParenExpr *pe) { Visit(pe->getSubExpr()); }
259 void VisitGenericSelectionExpr(GenericSelectionExpr *ge) {
260 Visit(ge->getResultExpr());
261 }
262 void VisitCoawaitExpr(CoawaitExpr *e) {
263 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCoawaitExpr");
264 }
265 void VisitCoyieldExpr(CoyieldExpr *e) {
266 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCoyieldExpr");
267 }
268 void VisitUnaryCoawait(UnaryOperator *e) {
269 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitUnaryCoawait");
270 }
271 void VisitUnaryExtension(UnaryOperator *e) { Visit(e->getSubExpr()); }
272 void VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *e) {
273 cgf.cgm.errorNYI(e->getSourceRange(),
274 "AggExprEmitter: VisitSubstNonTypeTemplateParmExpr");
275 }
276 void VisitConstantExpr(ConstantExpr *e) {
277 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitConstantExpr");
278 }
279 void VisitMemberExpr(MemberExpr *e) { emitAggLoadOfLValue(e); }
280 void VisitUnaryDeref(UnaryOperator *e) { emitAggLoadOfLValue(e); }
281 void VisitStringLiteral(StringLiteral *e) { emitAggLoadOfLValue(e); }
282 void VisitCompoundLiteralExpr(CompoundLiteralExpr *e);
283
284 void VisitPredefinedExpr(const PredefinedExpr *e) {
285 cgf.cgm.errorNYI(e->getSourceRange(),
286 "AggExprEmitter: VisitPredefinedExpr");
287 }
288 void VisitBinaryOperator(const BinaryOperator *e) {
289 cgf.cgm.errorNYI(e->getSourceRange(),
290 "AggExprEmitter: VisitBinaryOperator");
291 }
292 void VisitPointerToDataMemberBinaryOperator(const BinaryOperator *e) {
293 cgf.cgm.errorNYI(e->getSourceRange(),
294 "AggExprEmitter: VisitPointerToDataMemberBinaryOperator");
295 }
296 void VisitBinComma(const BinaryOperator *e) {
297 cgf.emitIgnoredExpr(e->getLHS());
298 Visit(e->getRHS());
299 }
300 void VisitBinCmp(const BinaryOperator *e) {
301 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitBinCmp");
302 }
303 void VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *e) {
304 cgf.cgm.errorNYI(e->getSourceRange(),
305 "AggExprEmitter: VisitCXXRewrittenBinaryOperator");
306 }
307 void VisitObjCMessageExpr(ObjCMessageExpr *e) {
308 cgf.cgm.errorNYI(e->getSourceRange(),
309 "AggExprEmitter: VisitObjCMessageExpr");
310 }
311 void VisitObjCIVarRefExpr(ObjCIvarRefExpr *e) {
312 cgf.cgm.errorNYI(e->getSourceRange(),
313 "AggExprEmitter: VisitObjCIVarRefExpr");
314 }
315
316 void VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *e) {
317 AggValueSlot dest = ensureSlot(cgf.getLoc(e->getExprLoc()), e->getType());
318 LValue destLV = cgf.makeAddrLValue(dest.getAddress(), e->getType());
319 emitInitializationToLValue(e->getBase(), destLV);
320 VisitInitListExpr(e->getUpdater());
321 }
322 void VisitAbstractConditionalOperator(const AbstractConditionalOperator *e) {
323 cgf.cgm.errorNYI(e->getSourceRange(),
324 "AggExprEmitter: VisitAbstractConditionalOperator");
325 }
326 void VisitChooseExpr(const ChooseExpr *e) { Visit(e->getChosenSubExpr()); }
327 void VisitCXXParenListInitExpr(CXXParenListInitExpr *e) {
328 visitCXXParenListOrInitListExpr(e, e->getInitExprs(),
330 e->getArrayFiller());
331 }
332
333 void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *e,
334 llvm::Value *outerBegin = nullptr) {
335 cgf.cgm.errorNYI(e->getSourceRange(),
336 "AggExprEmitter: VisitArrayInitLoopExpr");
337 }
338 void VisitImplicitValueInitExpr(ImplicitValueInitExpr *e) {
339 cgf.cgm.errorNYI(e->getSourceRange(),
340 "AggExprEmitter: VisitImplicitValueInitExpr");
341 }
342 void VisitNoInitExpr(NoInitExpr *e) {
343 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitNoInitExpr");
344 }
345 void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *dae) {
346 cgf.cgm.errorNYI(dae->getSourceRange(),
347 "AggExprEmitter: VisitCXXDefaultArgExpr");
348 }
349 void VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *e) {
350 cgf.cgm.errorNYI(e->getSourceRange(),
351 "AggExprEmitter: VisitCXXInheritedCtorInitExpr");
352 }
353 void VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *e) {
354 cgf.cgm.errorNYI(e->getSourceRange(),
355 "AggExprEmitter: VisitCXXStdInitializerListExpr");
356 }
357 void VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *e) {
358 cgf.cgm.errorNYI(e->getSourceRange(),
359 "AggExprEmitter: VisitCXXScalarValueInitExpr");
360 }
361 void VisitCXXTypeidExpr(CXXTypeidExpr *e) {
362 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCXXTypeidExpr");
363 }
364 void VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *e) {
365 Visit(e->getSubExpr());
366 }
367 void VisitOpaqueValueExpr(OpaqueValueExpr *e) {
368 cgf.cgm.errorNYI(e->getSourceRange(),
369 "AggExprEmitter: VisitOpaqueValueExpr");
370 }
371
372 void VisitPseudoObjectExpr(PseudoObjectExpr *e) {
373 cgf.cgm.errorNYI(e->getSourceRange(),
374 "AggExprEmitter: VisitPseudoObjectExpr");
375 }
376
377 void VisitVAArgExpr(VAArgExpr *e) {
378 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitVAArgExpr");
379 }
380
381 void VisitCXXThrowExpr(const CXXThrowExpr *e) {
382 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCXXThrowExpr");
383 }
384 void VisitAtomicExpr(AtomicExpr *e) {
385 cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitAtomicExpr");
386 }
387};
388
389} // namespace
390
391static bool isTrivialFiller(Expr *e) {
392 if (!e)
393 return true;
394
396 return true;
397
398 if (auto *ile = dyn_cast<InitListExpr>(e)) {
399 if (ile->getNumInits())
400 return false;
401 return isTrivialFiller(ile->getArrayFiller());
402 }
403
404 if (const auto *cons = dyn_cast_or_null<CXXConstructExpr>(e))
405 return cons->getConstructor()->isDefaultConstructor() &&
406 cons->getConstructor()->isTrivial();
407
408 return false;
409}
410
411/// Given an expression with aggregate type that represents a value lvalue, this
412/// method emits the address of the lvalue, then loads the result into DestPtr.
413void AggExprEmitter::emitAggLoadOfLValue(const Expr *e) {
414 LValue lv = cgf.emitLValue(e);
415
416 // If the type of the l-value is atomic, then do an atomic load.
418
419 emitFinalDestCopy(e->getType(), lv);
420}
421
422void AggExprEmitter::VisitCompoundLiteralExpr(CompoundLiteralExpr *e) {
423 if (dest.isPotentiallyAliased() && e->getType().isPODType(cgf.getContext())) {
424 // For a POD type, just emit a load of the lvalue + a copy, because our
425 // compound literal might alias the destination.
426 emitAggLoadOfLValue(e);
427 return;
428 }
429
430 AggValueSlot slot = ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
431
432 // Block-scope compound literals are destroyed at the end of the enclosing
433 // scope in C.
434 bool destruct =
435 !cgf.getLangOpts().CPlusPlus && !slot.isExternallyDestructed();
436 if (destruct)
438
439 cgf.emitAggExpr(e->getInitializer(), slot);
440
441 if (destruct)
442 if ([[maybe_unused]] QualType::DestructionKind dtorKind =
444 cgf.cgm.errorNYI(e->getSourceRange(), "compound literal with destructor");
445}
446
447void AggExprEmitter::emitArrayInit(Address destPtr, cir::ArrayType arrayTy,
448 QualType arrayQTy, Expr *e,
449 ArrayRef<Expr *> args, Expr *arrayFiller) {
450 CIRGenBuilderTy &builder = cgf.getBuilder();
451 const mlir::Location loc = cgf.getLoc(e->getSourceRange());
452
453 const uint64_t numInitElements = args.size();
454
455 const QualType elementType =
456 cgf.getContext().getAsArrayType(arrayQTy)->getElementType();
457
458 if (elementType.isDestructedType() && cgf.cgm.getLangOpts().Exceptions) {
459 cgf.cgm.errorNYI(loc, "initialized array requires destruction");
460 return;
461 }
462
463 const QualType elementPtrType = cgf.getContext().getPointerType(elementType);
464
465 const mlir::Type cirElementType = cgf.convertType(elementType);
466 const cir::PointerType cirElementPtrType =
467 builder.getPointerTo(cirElementType);
468
469 auto begin = cir::CastOp::create(builder, loc, cirElementPtrType,
470 cir::CastKind::array_to_ptrdecay,
471 destPtr.getPointer());
472
473 const CharUnits elementSize =
474 cgf.getContext().getTypeSizeInChars(elementType);
475 const CharUnits elementAlign =
476 destPtr.getAlignment().alignmentOfArrayElement(elementSize);
477
478 // The 'current element to initialize'. The invariants on this
479 // variable are complicated. Essentially, after each iteration of
480 // the loop, it points to the last initialized element, except
481 // that it points to the beginning of the array before any
482 // elements have been initialized.
483 mlir::Value element = begin;
484
485 // Don't build the 'one' before the cycle to avoid
486 // emmiting the redundant `cir.const 1` instrs.
487 mlir::Value one;
488
489 // Emit the explicit initializers.
490 for (uint64_t i = 0; i != numInitElements; ++i) {
491 // Advance to the next element.
492 if (i > 0) {
493 one = builder.getConstantInt(loc, cgf.ptrDiffTy, i);
494 element = builder.createPtrStride(loc, begin, one);
495 }
496
497 const Address address = Address(element, cirElementType, elementAlign);
498 const LValue elementLV = cgf.makeAddrLValue(address, elementType);
499 emitInitializationToLValue(args[i], elementLV);
500 }
501
502 const uint64_t numArrayElements = arrayTy.getSize();
503
504 // Check whether there's a non-trivial array-fill expression.
505 const bool hasTrivialFiller = isTrivialFiller(arrayFiller);
506
507 // Any remaining elements need to be zero-initialized, possibly
508 // using the filler expression. We can skip this if the we're
509 // emitting to zeroed memory.
510 if (numInitElements != numArrayElements &&
511 !(dest.isZeroed() && hasTrivialFiller &&
512 cgf.getTypes().isZeroInitializable(elementType))) {
513 // Advance to the start of the rest of the array.
514 if (numInitElements) {
515 one = builder.getConstantInt(loc, cgf.ptrDiffTy, 1);
516 element = cir::PtrStrideOp::create(builder, loc, cirElementPtrType,
517 element, one);
518 }
519
520 // Allocate the temporary variable
521 // to store the pointer to first unitialized element
522 const Address tmpAddr = cgf.createTempAlloca(
523 cirElementPtrType, cgf.getPointerAlign(), loc, "arrayinit.temp");
524 LValue tmpLV = cgf.makeAddrLValue(tmpAddr, elementPtrType);
525 cgf.emitStoreThroughLValue(RValue::get(element), tmpLV);
526
527 // Compute the end of array
528 cir::ConstantOp numArrayElementsConst = builder.getConstInt(
529 loc, mlir::cast<cir::IntType>(cgf.ptrDiffTy), numArrayElements);
530 mlir::Value end = cir::PtrStrideOp::create(builder, loc, cirElementPtrType,
531 begin, numArrayElementsConst);
532
533 builder.createDoWhile(
534 loc,
535 /*condBuilder=*/
536 [&](mlir::OpBuilder &b, mlir::Location loc) {
537 cir::LoadOp currentElement = builder.createLoad(loc, tmpAddr);
538 mlir::Type boolTy = cgf.convertType(cgf.getContext().BoolTy);
539 cir::CmpOp cmp = cir::CmpOp::create(
540 builder, loc, boolTy, cir::CmpOpKind::ne, currentElement, end);
541 builder.createCondition(cmp);
542 },
543 /*bodyBuilder=*/
544 [&](mlir::OpBuilder &b, mlir::Location loc) {
545 cir::LoadOp currentElement = builder.createLoad(loc, tmpAddr);
546
548
549 // Emit the actual filler expression.
550 LValue elementLV = cgf.makeAddrLValue(
551 Address(currentElement, cirElementType, elementAlign),
552 elementType);
553 if (arrayFiller)
554 emitInitializationToLValue(arrayFiller, elementLV);
555 else
556 emitNullInitializationToLValue(loc, elementLV);
557
558 // Tell the EH cleanup that we finished with the last element.
559 if (cgf.cgm.getLangOpts().Exceptions) {
560 cgf.cgm.errorNYI(loc, "update destructed array element for EH");
561 return;
562 }
563
564 // Advance pointer and store them to temporary variable
565 cir::ConstantOp one = builder.getConstInt(
566 loc, mlir::cast<cir::IntType>(cgf.ptrDiffTy), 1);
567 auto nextElement = cir::PtrStrideOp::create(
568 builder, loc, cirElementPtrType, currentElement, one);
569 cgf.emitStoreThroughLValue(RValue::get(nextElement), tmpLV);
570
571 builder.createYield(loc);
572 });
573 }
574}
575
576/// Perform the final copy to destPtr, if desired.
577void AggExprEmitter::emitFinalDestCopy(QualType type, const LValue &src) {
578 // If dest is ignored, then we're evaluating an aggregate expression
579 // in a context that doesn't care about the result. Note that loads
580 // from volatile l-values force the existence of a non-ignored
581 // destination.
582 if (dest.isIgnored())
583 return;
584
588
589 AggValueSlot srcAgg = AggValueSlot::forLValue(src, AggValueSlot::IsDestructed,
592 emitCopy(type, dest, srcAgg);
593}
594
595/// Perform a copy from the source into the destination.
596///
597/// \param type - the type of the aggregate being copied; qualifiers are
598/// ignored
599void AggExprEmitter::emitCopy(QualType type, const AggValueSlot &dest,
600 const AggValueSlot &src) {
602
603 // If the result of the assignment is used, copy the LHS there also.
604 // It's volatile if either side is. Use the minimum alignment of
605 // the two sides.
606 LValue destLV = cgf.makeAddrLValue(dest.getAddress(), type);
607 LValue srcLV = cgf.makeAddrLValue(src.getAddress(), type);
609 cgf.emitAggregateCopy(destLV, srcLV, type, dest.mayOverlap(),
610 dest.isVolatile() || src.isVolatile());
611}
612
613void AggExprEmitter::emitInitializationToLValue(Expr *e, LValue lv) {
614 const QualType type = lv.getType();
615
617 const mlir::Location loc = e->getSourceRange().isValid()
618 ? cgf.getLoc(e->getSourceRange())
619 : *cgf.currSrcLoc;
620 return emitNullInitializationToLValue(loc, lv);
621 }
622
623 if (isa<NoInitExpr>(e))
624 return;
625
626 if (type->isReferenceType()) {
627 RValue rv = cgf.emitReferenceBindingToExpr(e);
628 return cgf.emitStoreThroughLValue(rv, lv);
629 }
630
631 switch (cgf.getEvaluationKind(type)) {
632 case cir::TEK_Complex:
633 cgf.emitComplexExprIntoLValue(e, lv, /*isInit*/ true);
634 break;
639 dest.isZeroed()));
640
641 return;
642 case cir::TEK_Scalar:
643 if (lv.isSimple())
644 cgf.emitScalarInit(e, cgf.getLoc(e->getSourceRange()), lv);
645 else
647 return;
648 }
649}
650
651void AggExprEmitter::VisitCXXConstructExpr(const CXXConstructExpr *e) {
652 AggValueSlot slot = ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
653 cgf.emitCXXConstructExpr(e, slot);
654}
655
656void AggExprEmitter::emitNullInitializationToLValue(mlir::Location loc,
657 LValue lv) {
658 const QualType type = lv.getType();
659
660 // If the destination slot is already zeroed out before the aggregate is
661 // copied into it, we don't have to emit any zeros here.
662 if (dest.isZeroed() && cgf.getTypes().isZeroInitializable(type))
663 return;
664
665 if (cgf.hasScalarEvaluationKind(type)) {
666 // For non-aggregates, we can store the appropriate null constant.
667 mlir::Value null = cgf.cgm.emitNullConstant(type, loc);
668 if (lv.isSimple()) {
669 cgf.emitStoreOfScalar(null, lv, /* isInitialization */ true);
670 return;
671 }
672
674 return;
675 }
676
677 // There's a potential optimization opportunity in combining
678 // memsets; that would be easy for arrays, but relatively
679 // difficult for structures with the current code.
680 cgf.emitNullInitialization(loc, lv.getAddress(), lv.getType());
681}
682
683void AggExprEmitter::VisitLambdaExpr(LambdaExpr *e) {
684 CIRGenFunction::SourceLocRAIIObject loc{cgf, cgf.getLoc(e->getSourceRange())};
685 AggValueSlot slot = ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
686 [[maybe_unused]] LValue slotLV =
687 cgf.makeAddrLValue(slot.getAddress(), e->getType());
688
689 // We'll need to enter cleanup scopes in case any of the element
690 // initializers throws an exception or contains branch out of the expressions.
692
693 for (auto [curField, capture, captureInit] : llvm::zip(
694 e->getLambdaClass()->fields(), e->captures(), e->capture_inits())) {
695 // Pick a name for the field.
696 llvm::StringRef fieldName = curField->getName();
697 if (capture.capturesVariable()) {
698 assert(!curField->isBitField() && "lambdas don't have bitfield members!");
699 ValueDecl *v = capture.getCapturedVar();
700 fieldName = v->getName();
701 cgf.cgm.lambdaFieldToName[curField] = fieldName;
702 } else if (capture.capturesThis()) {
703 cgf.cgm.lambdaFieldToName[curField] = "this";
704 } else {
705 cgf.cgm.errorNYI(e->getSourceRange(), "Unhandled capture kind");
706 cgf.cgm.lambdaFieldToName[curField] = "unhandled-capture-kind";
707 }
708
709 // Emit initialization
710 LValue lv =
711 cgf.emitLValueForFieldInitialization(slotLV, curField, fieldName);
712 if (curField->hasCapturedVLAType())
713 cgf.cgm.errorNYI(e->getSourceRange(), "lambda captured VLA type");
714
715 emitInitializationToLValue(captureInit, lv);
716
717 // Push a destructor if necessary.
718 if ([[maybe_unused]] QualType::DestructionKind DtorKind =
719 curField->getType().isDestructedType())
720 cgf.cgm.errorNYI(e->getSourceRange(), "lambda with destructed field");
721 }
722}
723
724void AggExprEmitter::VisitExprWithCleanups(ExprWithCleanups *e) {
725 CIRGenFunction::RunCleanupsScope cleanups(cgf);
726 Visit(e->getSubExpr());
727}
728
729void AggExprEmitter::VisitCallExpr(const CallExpr *e) {
731 cgf.cgm.errorNYI(e->getSourceRange(), "reference return type");
732 return;
733 }
734
735 withReturnValueSlot(
736 e, [&](ReturnValueSlot slot) { return cgf.emitCallExpr(e, slot); });
737}
738
739void AggExprEmitter::withReturnValueSlot(
740 const Expr *e, llvm::function_ref<RValue(ReturnValueSlot)> fn) {
741 QualType retTy = e->getType();
742
744 bool requiresDestruction =
746 if (requiresDestruction)
747 cgf.cgm.errorNYI(
748 e->getSourceRange(),
749 "withReturnValueSlot: return value requiring destruction is NYI");
750
751 // If it makes no observable difference, save a memcpy + temporary.
752 //
753 // We need to always provide our own temporary if destruction is required.
754 // Otherwise, fn will emit its own, notice that it's "unused", and end its
755 // lifetime before we have the chance to emit a proper destructor call.
758
759 Address retAddr = dest.getAddress();
761
764 fn(ReturnValueSlot(retAddr));
765}
766
767void AggExprEmitter::VisitInitListExpr(InitListExpr *e) {
769 llvm_unreachable("GNU array range designator extension");
770
771 if (e->isTransparent())
772 return Visit(e->getInit(0));
773
774 visitCXXParenListOrInitListExpr(
776}
777
778void AggExprEmitter::visitCXXParenListOrInitListExpr(
779 Expr *e, ArrayRef<Expr *> args, FieldDecl *initializedFieldInUnion,
780 Expr *arrayFiller) {
781
782 const AggValueSlot dest =
783 ensureSlot(cgf.getLoc(e->getSourceRange()), e->getType());
784
785 if (e->getType()->isConstantArrayType()) {
786 cir::ArrayType arrayTy =
788 emitArrayInit(dest.getAddress(), arrayTy, e->getType(), e, args,
789 arrayFiller);
790 return;
791 } else if (e->getType()->isVariableArrayType()) {
792 cgf.cgm.errorNYI(e->getSourceRange(),
793 "visitCXXParenListOrInitListExpr variable array type");
794 return;
795 }
796
797 if (e->getType()->isArrayType()) {
798 cgf.cgm.errorNYI(e->getSourceRange(),
799 "visitCXXParenListOrInitListExpr array type");
800 return;
801 }
802
803 assert(e->getType()->isRecordType() && "Only support structs/unions here!");
804
805 // Do struct initialization; this code just sets each individual member
806 // to the approprate value. This makes bitfield support automatic;
807 // the disadvantage is that the generated code is more difficult for
808 // the optimizer, especially with bitfields.
809 unsigned numInitElements = args.size();
810 auto *record = e->getType()->castAsRecordDecl();
811
812 // We'll need to enter cleanup scopes in case any of the element
813 // initializers throws an exception.
815
816 unsigned curInitIndex = 0;
817
818 // Emit initialization of base classes.
819 if (auto *cxxrd = dyn_cast<CXXRecordDecl>(record)) {
820 assert(numInitElements >= cxxrd->getNumBases() &&
821 "missing initializer for base class");
822 if (cxxrd->getNumBases() > 0) {
823 cgf.cgm.errorNYI(e->getSourceRange(),
824 "visitCXXParenListOrInitListExpr base class init");
825 return;
826 }
827 }
828
829 LValue destLV = cgf.makeAddrLValue(dest.getAddress(), e->getType());
830
831 if (record->isUnion()) {
832 cgf.cgm.errorNYI(e->getSourceRange(),
833 "visitCXXParenListOrInitListExpr union type");
834 return;
835 }
836
837 // Here we iterate over the fields; this makes it simpler to both
838 // default-initialize fields and skip over unnamed fields.
839 for (const FieldDecl *field : record->fields()) {
840 // We're done once we hit the flexible array member.
841 if (field->getType()->isIncompleteArrayType())
842 break;
843
844 // Always skip anonymous bitfields.
845 if (field->isUnnamedBitField())
846 continue;
847
848 // We're done if we reach the end of the explicit initializers, we
849 // have a zeroed object, and the rest of the fields are
850 // zero-initializable.
851 if (curInitIndex == numInitElements && dest.isZeroed() &&
853 break;
854 LValue lv =
855 cgf.emitLValueForFieldInitialization(destLV, field, field->getName());
856 // We never generate write-barriers for initialized fields.
858
859 if (curInitIndex < numInitElements) {
860 // Store the initializer into the field.
861 CIRGenFunction::SourceLocRAIIObject loc{
862 cgf, cgf.getLoc(record->getSourceRange())};
863 emitInitializationToLValue(args[curInitIndex++], lv);
864 } else {
865 // We're out of initializers; default-initialize to null
866 emitNullInitializationToLValue(cgf.getLoc(e->getSourceRange()), lv);
867 }
868
869 // Push a destructor if necessary.
870 // FIXME: if we have an array of structures, all explicitly
871 // initialized, we can end up pushing a linear number of cleanups.
872 if (field->getType().isDestructedType()) {
873 cgf.cgm.errorNYI(e->getSourceRange(),
874 "visitCXXParenListOrInitListExpr destructor");
875 return;
876 }
877
878 // From classic codegen, maybe not useful for CIR:
879 // If the GEP didn't get used because of a dead zero init or something
880 // else, clean it up for -O0 builds and general tidiness.
881 }
882}
883
884// TODO(cir): This could be shared with classic codegen.
886 const CXXRecordDecl *rd, const CXXRecordDecl *baseRD, bool isVirtual) {
887 // If the most-derived object is a field declared with [[no_unique_address]],
888 // the tail padding of any virtual base could be reused for other subobjects
889 // of that field's class.
890 if (isVirtual)
892
893 // If the base class is laid out entirely within the nvsize of the derived
894 // class, its tail padding cannot yet be initialized, so we can issue
895 // stores at the full width of the base class.
896 const ASTRecordLayout &layout = getContext().getASTRecordLayout(rd);
897 if (layout.getBaseClassOffset(baseRD) +
898 getContext().getASTRecordLayout(baseRD).getSize() <=
899 layout.getNonVirtualSize())
901
902 // The tail padding may contain values we need to preserve.
904}
905
907 AggExprEmitter(*this, slot).Visit(const_cast<Expr *>(e));
908}
909
911 AggValueSlot::Overlap_t mayOverlap,
912 bool isVolatile) {
913 // TODO(cir): this function needs improvements, commented code for now since
914 // this will be touched again soon.
915 assert(!ty->isAnyComplexType() && "Unexpected copy of complex");
916
917 Address destPtr = dest.getAddress();
918 Address srcPtr = src.getAddress();
919
920 if (getLangOpts().CPlusPlus) {
921 if (auto *record = ty->getAsCXXRecordDecl()) {
922 assert((record->hasTrivialCopyConstructor() ||
923 record->hasTrivialCopyAssignment() ||
924 record->hasTrivialMoveConstructor() ||
925 record->hasTrivialMoveAssignment() ||
926 record->hasAttr<TrivialABIAttr>() || record->isUnion()) &&
927 "Trying to aggregate-copy a type without a trivial copy/move "
928 "constructor or assignment operator");
929 // Ignore empty classes in C++.
930 if (record->isEmpty())
931 return;
932 }
933 }
934
936
937 // Aggregate assignment turns into llvm.memcpy. This is almost valid per
938 // C99 6.5.16.1p3, which states "If the value being stored in an object is
939 // read from another object that overlaps in anyway the storage of the first
940 // object, then the overlap shall be exact and the two objects shall have
941 // qualified or unqualified versions of a compatible type."
942 //
943 // memcpy is not defined if the source and destination pointers are exactly
944 // equal, but other compilers do this optimization, and almost every memcpy
945 // implementation handles this case safely. If there is a libc that does not
946 // safely handle this, we can add a target hook.
947
948 // Get data size info for this aggregate. Don't copy the tail padding if this
949 // might be a potentially-overlapping subobject, since the tail padding might
950 // be occupied by a different object. Otherwise, copying it is fine.
951 TypeInfoChars typeInfo;
952 if (mayOverlap)
953 typeInfo = getContext().getTypeInfoDataSizeInChars(ty);
954 else
955 typeInfo = getContext().getTypeInfoInChars(ty);
956
958
959 // NOTE(cir): original codegen would normally convert destPtr and srcPtr to
960 // i8* since memcpy operates on bytes. We don't need that in CIR because
961 // cir.copy will operate on any CIR pointer that points to a sized type.
962
963 // Don't do any of the memmove_collectable tests if GC isn't set.
964 if (cgm.getLangOpts().getGC() != LangOptions::NonGC)
965 cgm.errorNYI("emitAggregateCopy: GC");
966
967 [[maybe_unused]] cir::CopyOp copyOp =
968 builder.createCopy(destPtr.getPointer(), srcPtr.getPointer(), isVolatile);
969
971}
972
973// TODO(cir): This could be shared with classic codegen.
976 if (!fd->hasAttr<NoUniqueAddressAttr>() || !fd->getType()->isRecordType())
978
979 // If the field lies entirely within the enclosing class's nvsize, its tail
980 // padding cannot overlap any already-initialized object. (The only subobjects
981 // with greater addresses that might already be initialized are vbases.)
982 const RecordDecl *classRD = fd->getParent();
983 const ASTRecordLayout &layout = getContext().getASTRecordLayout(classRD);
984 if (layout.getFieldOffset(fd->getFieldIndex()) +
985 getContext().getTypeSize(fd->getType()) <=
986 (uint64_t)getContext().toBits(layout.getNonVirtualSize()))
988
989 // The tail padding may contain values we need to preserve.
991}
992
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.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
CanQualType BoolTy
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.
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:4287
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2721
QualType getElementType() const
Definition TypeBase.h:3734
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:3972
Expr * getLHS() const
Definition Expr.h:4022
Expr * getRHS() const
Definition Expr.h:4024
mlir::Value getPointer() const
Definition Address.h:82
mlir::Type getElementType() const
Definition Address.h:109
clang::CharUnits getAlignment() const
Definition Address.h:117
An aggregate value slot.
IsZeroed_t isZeroed() const
Overlap_t mayOverlap() const
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)
IsAliased_t isPotentiallyAliased() const
void setVolatile(bool flag)
cir::ConstantOp getConstInt(mlir::Location loc, llvm::APSInt intVal)
cir::LoadOp createLoad(mlir::Location loc, Address addr, bool isVolatile=false)
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 emitStoreOfScalar(mlir::Value value, Address addr, bool isVolatile, clang::QualType ty, bool isInit=false, bool isNontemporal=false)
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
void emitNullInitialization(mlir::Location loc, Address destPtr, QualType ty)
RValue emitReferenceBindingToExpr(const Expr *e)
Emits a reference binding to the passed in expression.
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *fd)
void emitCXXConstructExpr(const clang::CXXConstructExpr *e, AggValueSlot dest)
LValue emitAggExprToLValue(const Expr *e)
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)
Emit the computation of the specified expression of scalar type.
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.
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 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)
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
const clang::LangOptions & getLangOpts() const
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
static RValue get(mlir::Value v)
Definition CIRGenValue.h:82
CXXTemporary * getTemporary()
Definition ExprCXX.h:1512
const Expr * getSubExpr() const
Definition ExprCXX.h:1516
Expr * getExpr()
Get the initialization expression that will be used.
Definition ExprCXX.cpp:1105
MutableArrayRef< Expr * > getInitExprs()
Definition ExprCXX.h:5183
FieldDecl * getInitializedFieldInUnion()
Definition ExprCXX.h:5221
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
SourceRange getSourceRange() const LLVM_READONLY
Definition ExprCXX.h:353
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range of the expression.
Definition ExprCXX.h:828
SourceRange getSourceRange() const LLVM_READONLY
Definition ExprCXX.h:902
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Definition Expr.cpp:1599
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3610
CastKind getCastKind() const
Definition Expr.h:3654
static const char * getCastKindName(CastKind CK)
Definition Expr.cpp:1946
Expr * getSubExpr()
Definition Expr.h:3660
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
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Definition Expr.h:4818
const Expr * getInitializer() const
Definition Expr.h:3567
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1270
bool hasAttr() const
Definition DeclBase.h:577
InitListExpr * getUpdater() const
Definition Expr.h:5870
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:3081
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:3665
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:273
QualType getType() const
Definition Expr.h:144
Represents a member of a struct/union/class.
Definition Decl.h:3160
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition Decl.h:3245
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition Decl.h:3396
const Expr * getSubExpr() const
Definition Expr.h:1062
Expr * getResultExpr()
Return the result expression of this controlling expression.
Definition Expr.h:6396
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic,...
Definition Expr.cpp:2457
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5359
bool hadArrayRangeDesignator() const
Definition Expr.h:5417
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5335
const Expr * getInit(unsigned Init) const
Definition Expr.h:5287
ArrayRef< Expr * > inits()
Definition Expr.h:5283
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
Definition ExprCXX.h:2085
capture_range captures() const
Retrieve this lambda's captures.
Definition ExprCXX.cpp:1371
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition ExprCXX.cpp:1400
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition ExprCXX.h:4939
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3298
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1178
const Expr * getSubExpr() const
Definition Expr.h:2199
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition TypeBase.h:8362
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition TypeBase.h:1545
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
Definition Type.cpp:2694
Represents a struct/union/class.
Definition Decl.h:4312
field_range fields() const
Definition Decl.h:4515
CompoundStmt * getSubStmt()
Definition Expr.h:4546
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:338
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:8618
bool isArrayType() const
Definition TypeBase.h:8614
bool isReferenceType() const
Definition TypeBase.h:8539
bool isVariableArrayType() const
Definition TypeBase.h:8626
RecordDecl * castAsRecordDecl() const
Definition Type.h:48
bool isAnyComplexType() const
Definition TypeBase.h:8650
bool isRecordType() const
Definition TypeBase.h:8642
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2244
Expr * getSubExpr() const
Definition Expr.h:2285
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:926
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
constexpr Variable var(Literal L)
Returns the variable of L.
Definition CNFFormula.h:64
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 aggValueSlotVolatile()
static bool opScopeCleanupRegion()
static bool atomicTypes()
static bool cudaSupport()
static bool requiresCleanups()
clang::CharUnits getPointerAlign() const