CGValue.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. //===-- CGValue.h - LLVM CodeGen wrappers for llvm::Value* ------*- C++ -*-===//
  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. // These classes implement wrappers around llvm::Value in order to
  10. // fully represent the range of values for C L- and R- values.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CLANG_LIB_CODEGEN_CGVALUE_H
  14. #define LLVM_CLANG_LIB_CODEGEN_CGVALUE_H
  15. #include "clang/AST/ASTContext.h"
  16. #include "clang/AST/Type.h"
  17. #include "llvm/IR/Value.h"
  18. #include "llvm/IR/Type.h"
  19. #include "Address.h"
  20. #include "CodeGenTBAA.h"
  21. namespace llvm {
  22. class Constant;
  23. class MDNode;
  24. }
  25. namespace clang {
  26. namespace CodeGen {
  27. class AggValueSlot;
  28. struct CGBitFieldInfo;
  29. /// RValue - This trivial value class is used to represent the result of an
  30. /// expression that is evaluated. It can be one of three things: either a
  31. /// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
  32. /// address of an aggregate value in memory.
  33. class RValue {
  34. enum Flavor { Scalar, Complex, Aggregate };
  35. // The shift to make to an aggregate's alignment to make it look
  36. // like a pointer.
  37. enum { AggAlignShift = 4 };
  38. // Stores first value and flavor.
  39. llvm::PointerIntPair<llvm::Value *, 2, Flavor> V1;
  40. // Stores second value and volatility.
  41. llvm::PointerIntPair<llvm::Value *, 1, bool> V2;
  42. public:
  43. bool isScalar() const { return V1.getInt() == Scalar; }
  44. bool isComplex() const { return V1.getInt() == Complex; }
  45. bool isAggregate() const { return V1.getInt() == Aggregate; }
  46. bool isVolatileQualified() const { return V2.getInt(); }
  47. /// getScalarVal() - Return the Value* of this scalar value.
  48. llvm::Value *getScalarVal() const {
  49. assert(isScalar() && "Not a scalar!");
  50. return V1.getPointer();
  51. }
  52. /// getComplexVal - Return the real/imag components of this complex value.
  53. ///
  54. std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
  55. return std::make_pair(V1.getPointer(), V2.getPointer());
  56. }
  57. /// getAggregateAddr() - Return the Value* of the address of the aggregate.
  58. Address getAggregateAddress() const {
  59. assert(isAggregate() && "Not an aggregate!");
  60. auto align = reinterpret_cast<uintptr_t>(V2.getPointer()) >> AggAlignShift;
  61. return Address(V1.getPointer(), CharUnits::fromQuantity(align));
  62. }
  63. llvm::Value *getAggregatePointer() const {
  64. assert(isAggregate() && "Not an aggregate!");
  65. return V1.getPointer();
  66. }
  67. static RValue getIgnored() {
  68. // FIXME: should we make this a more explicit state?
  69. return get(nullptr);
  70. }
  71. static RValue get(llvm::Value *V) {
  72. RValue ER;
  73. ER.V1.setPointer(V);
  74. ER.V1.setInt(Scalar);
  75. ER.V2.setInt(false);
  76. return ER;
  77. }
  78. static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
  79. RValue ER;
  80. ER.V1.setPointer(V1);
  81. ER.V2.setPointer(V2);
  82. ER.V1.setInt(Complex);
  83. ER.V2.setInt(false);
  84. return ER;
  85. }
  86. static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
  87. return getComplex(C.first, C.second);
  88. }
  89. // FIXME: Aggregate rvalues need to retain information about whether they are
  90. // volatile or not. Remove default to find all places that probably get this
  91. // wrong.
  92. static RValue getAggregate(Address addr, bool isVolatile = false) {
  93. RValue ER;
  94. ER.V1.setPointer(addr.getPointer());
  95. ER.V1.setInt(Aggregate);
  96. auto align = static_cast<uintptr_t>(addr.getAlignment().getQuantity());
  97. ER.V2.setPointer(reinterpret_cast<llvm::Value*>(align << AggAlignShift));
  98. ER.V2.setInt(isVolatile);
  99. return ER;
  100. }
  101. };
  102. /// Does an ARC strong l-value have precise lifetime?
  103. enum ARCPreciseLifetime_t {
  104. ARCImpreciseLifetime, ARCPreciseLifetime
  105. };
  106. /// The source of the alignment of an l-value; an expression of
  107. /// confidence in the alignment actually matching the estimate.
  108. enum class AlignmentSource {
  109. /// The l-value was an access to a declared entity or something
  110. /// equivalently strong, like the address of an array allocated by a
  111. /// language runtime.
  112. Decl,
  113. /// The l-value was considered opaque, so the alignment was
  114. /// determined from a type, but that type was an explicitly-aligned
  115. /// typedef.
  116. AttributedType,
  117. /// The l-value was considered opaque, so the alignment was
  118. /// determined from a type.
  119. Type
  120. };
  121. /// Given that the base address has the given alignment source, what's
  122. /// our confidence in the alignment of the field?
  123. static inline AlignmentSource getFieldAlignmentSource(AlignmentSource Source) {
  124. // For now, we don't distinguish fields of opaque pointers from
  125. // top-level declarations, but maybe we should.
  126. return AlignmentSource::Decl;
  127. }
  128. class LValueBaseInfo {
  129. AlignmentSource AlignSource;
  130. public:
  131. explicit LValueBaseInfo(AlignmentSource Source = AlignmentSource::Type)
  132. : AlignSource(Source) {}
  133. AlignmentSource getAlignmentSource() const { return AlignSource; }
  134. void setAlignmentSource(AlignmentSource Source) { AlignSource = Source; }
  135. void mergeForCast(const LValueBaseInfo &Info) {
  136. setAlignmentSource(Info.getAlignmentSource());
  137. }
  138. };
  139. /// LValue - This represents an lvalue references. Because C/C++ allow
  140. /// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
  141. /// bitrange.
  142. class LValue {
  143. enum {
  144. Simple, // This is a normal l-value, use getAddress().
  145. VectorElt, // This is a vector element l-value (V[i]), use getVector*
  146. BitField, // This is a bitfield l-value, use getBitfield*.
  147. ExtVectorElt, // This is an extended vector subset, use getExtVectorComp
  148. GlobalReg // This is a register l-value, use getGlobalReg()
  149. } LVType;
  150. llvm::Value *V;
  151. union {
  152. // Index into a vector subscript: V[i]
  153. llvm::Value *VectorIdx;
  154. // ExtVector element subset: V.xyx
  155. llvm::Constant *VectorElts;
  156. // BitField start bit and size
  157. const CGBitFieldInfo *BitFieldInfo;
  158. };
  159. QualType Type;
  160. // 'const' is unused here
  161. Qualifiers Quals;
  162. // The alignment to use when accessing this lvalue. (For vector elements,
  163. // this is the alignment of the whole vector.)
  164. unsigned Alignment;
  165. // objective-c's ivar
  166. bool Ivar:1;
  167. // objective-c's ivar is an array
  168. bool ObjIsArray:1;
  169. // LValue is non-gc'able for any reason, including being a parameter or local
  170. // variable.
  171. bool NonGC: 1;
  172. // Lvalue is a global reference of an objective-c object
  173. bool GlobalObjCRef : 1;
  174. // Lvalue is a thread local reference
  175. bool ThreadLocalRef : 1;
  176. // Lvalue has ARC imprecise lifetime. We store this inverted to try
  177. // to make the default bitfield pattern all-zeroes.
  178. bool ImpreciseLifetime : 1;
  179. // This flag shows if a nontemporal load/stores should be used when accessing
  180. // this lvalue.
  181. bool Nontemporal : 1;
  182. LValueBaseInfo BaseInfo;
  183. TBAAAccessInfo TBAAInfo;
  184. Expr *BaseIvarExp;
  185. private:
  186. void Initialize(QualType Type, Qualifiers Quals, CharUnits Alignment,
  187. LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
  188. assert((!Alignment.isZero() || Type->isIncompleteType()) &&
  189. "initializing l-value with zero alignment!");
  190. this->Type = Type;
  191. this->Quals = Quals;
  192. const unsigned MaxAlign = 1U << 31;
  193. this->Alignment = Alignment.getQuantity() <= MaxAlign
  194. ? Alignment.getQuantity()
  195. : MaxAlign;
  196. assert(this->Alignment == Alignment.getQuantity() &&
  197. "Alignment exceeds allowed max!");
  198. this->BaseInfo = BaseInfo;
  199. this->TBAAInfo = TBAAInfo;
  200. // Initialize Objective-C flags.
  201. this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false;
  202. this->ImpreciseLifetime = false;
  203. this->Nontemporal = false;
  204. this->ThreadLocalRef = false;
  205. this->BaseIvarExp = nullptr;
  206. }
  207. public:
  208. bool isSimple() const { return LVType == Simple; }
  209. bool isVectorElt() const { return LVType == VectorElt; }
  210. bool isBitField() const { return LVType == BitField; }
  211. bool isExtVectorElt() const { return LVType == ExtVectorElt; }
  212. bool isGlobalReg() const { return LVType == GlobalReg; }
  213. bool isVolatileQualified() const { return Quals.hasVolatile(); }
  214. bool isRestrictQualified() const { return Quals.hasRestrict(); }
  215. unsigned getVRQualifiers() const {
  216. return Quals.getCVRQualifiers() & ~Qualifiers::Const;
  217. }
  218. QualType getType() const { return Type; }
  219. Qualifiers::ObjCLifetime getObjCLifetime() const {
  220. return Quals.getObjCLifetime();
  221. }
  222. bool isObjCIvar() const { return Ivar; }
  223. void setObjCIvar(bool Value) { Ivar = Value; }
  224. bool isObjCArray() const { return ObjIsArray; }
  225. void setObjCArray(bool Value) { ObjIsArray = Value; }
  226. bool isNonGC () const { return NonGC; }
  227. void setNonGC(bool Value) { NonGC = Value; }
  228. bool isGlobalObjCRef() const { return GlobalObjCRef; }
  229. void setGlobalObjCRef(bool Value) { GlobalObjCRef = Value; }
  230. bool isThreadLocalRef() const { return ThreadLocalRef; }
  231. void setThreadLocalRef(bool Value) { ThreadLocalRef = Value;}
  232. ARCPreciseLifetime_t isARCPreciseLifetime() const {
  233. return ARCPreciseLifetime_t(!ImpreciseLifetime);
  234. }
  235. void setARCPreciseLifetime(ARCPreciseLifetime_t value) {
  236. ImpreciseLifetime = (value == ARCImpreciseLifetime);
  237. }
  238. bool isNontemporal() const { return Nontemporal; }
  239. void setNontemporal(bool Value) { Nontemporal = Value; }
  240. bool isObjCWeak() const {
  241. return Quals.getObjCGCAttr() == Qualifiers::Weak;
  242. }
  243. bool isObjCStrong() const {
  244. return Quals.getObjCGCAttr() == Qualifiers::Strong;
  245. }
  246. bool isVolatile() const {
  247. return Quals.hasVolatile();
  248. }
  249. Expr *getBaseIvarExp() const { return BaseIvarExp; }
  250. void setBaseIvarExp(Expr *V) { BaseIvarExp = V; }
  251. TBAAAccessInfo getTBAAInfo() const { return TBAAInfo; }
  252. void setTBAAInfo(TBAAAccessInfo Info) { TBAAInfo = Info; }
  253. const Qualifiers &getQuals() const { return Quals; }
  254. Qualifiers &getQuals() { return Quals; }
  255. LangAS getAddressSpace() const { return Quals.getAddressSpace(); }
  256. CharUnits getAlignment() const { return CharUnits::fromQuantity(Alignment); }
  257. void setAlignment(CharUnits A) { Alignment = A.getQuantity(); }
  258. LValueBaseInfo getBaseInfo() const { return BaseInfo; }
  259. void setBaseInfo(LValueBaseInfo Info) { BaseInfo = Info; }
  260. // simple lvalue
  261. llvm::Value *getPointer() const {
  262. assert(isSimple());
  263. return V;
  264. }
  265. Address getAddress() const { return Address(getPointer(), getAlignment()); }
  266. void setAddress(Address address) {
  267. assert(isSimple());
  268. V = address.getPointer();
  269. Alignment = address.getAlignment().getQuantity();
  270. }
  271. // vector elt lvalue
  272. Address getVectorAddress() const {
  273. return Address(getVectorPointer(), getAlignment());
  274. }
  275. llvm::Value *getVectorPointer() const { assert(isVectorElt()); return V; }
  276. llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
  277. // extended vector elements.
  278. Address getExtVectorAddress() const {
  279. return Address(getExtVectorPointer(), getAlignment());
  280. }
  281. llvm::Value *getExtVectorPointer() const {
  282. assert(isExtVectorElt());
  283. return V;
  284. }
  285. llvm::Constant *getExtVectorElts() const {
  286. assert(isExtVectorElt());
  287. return VectorElts;
  288. }
  289. // bitfield lvalue
  290. Address getBitFieldAddress() const {
  291. return Address(getBitFieldPointer(), getAlignment());
  292. }
  293. llvm::Value *getBitFieldPointer() const { assert(isBitField()); return V; }
  294. const CGBitFieldInfo &getBitFieldInfo() const {
  295. assert(isBitField());
  296. return *BitFieldInfo;
  297. }
  298. // global register lvalue
  299. llvm::Value *getGlobalReg() const { assert(isGlobalReg()); return V; }
  300. static LValue MakeAddr(Address address, QualType type, ASTContext &Context,
  301. LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
  302. Qualifiers qs = type.getQualifiers();
  303. qs.setObjCGCAttr(Context.getObjCGCAttrKind(type));
  304. LValue R;
  305. R.LVType = Simple;
  306. assert(address.getPointer()->getType()->isPointerTy());
  307. R.V = address.getPointer();
  308. R.Initialize(type, qs, address.getAlignment(), BaseInfo, TBAAInfo);
  309. return R;
  310. }
  311. static LValue MakeVectorElt(Address vecAddress, llvm::Value *Idx,
  312. QualType type, LValueBaseInfo BaseInfo,
  313. TBAAAccessInfo TBAAInfo) {
  314. LValue R;
  315. R.LVType = VectorElt;
  316. R.V = vecAddress.getPointer();
  317. R.VectorIdx = Idx;
  318. R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(),
  319. BaseInfo, TBAAInfo);
  320. return R;
  321. }
  322. static LValue MakeExtVectorElt(Address vecAddress, llvm::Constant *Elts,
  323. QualType type, LValueBaseInfo BaseInfo,
  324. TBAAAccessInfo TBAAInfo) {
  325. LValue R;
  326. R.LVType = ExtVectorElt;
  327. R.V = vecAddress.getPointer();
  328. R.VectorElts = Elts;
  329. R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(),
  330. BaseInfo, TBAAInfo);
  331. return R;
  332. }
  333. /// Create a new object to represent a bit-field access.
  334. ///
  335. /// \param Addr - The base address of the bit-field sequence this
  336. /// bit-field refers to.
  337. /// \param Info - The information describing how to perform the bit-field
  338. /// access.
  339. static LValue MakeBitfield(Address Addr, const CGBitFieldInfo &Info,
  340. QualType type, LValueBaseInfo BaseInfo,
  341. TBAAAccessInfo TBAAInfo) {
  342. LValue R;
  343. R.LVType = BitField;
  344. R.V = Addr.getPointer();
  345. R.BitFieldInfo = &Info;
  346. R.Initialize(type, type.getQualifiers(), Addr.getAlignment(), BaseInfo,
  347. TBAAInfo);
  348. return R;
  349. }
  350. static LValue MakeGlobalReg(Address Reg, QualType type) {
  351. LValue R;
  352. R.LVType = GlobalReg;
  353. R.V = Reg.getPointer();
  354. R.Initialize(type, type.getQualifiers(), Reg.getAlignment(),
  355. LValueBaseInfo(AlignmentSource::Decl), TBAAAccessInfo());
  356. return R;
  357. }
  358. RValue asAggregateRValue() const {
  359. return RValue::getAggregate(getAddress(), isVolatileQualified());
  360. }
  361. };
  362. /// An aggregate value slot.
  363. class AggValueSlot {
  364. /// The address.
  365. llvm::Value *Addr;
  366. // Qualifiers
  367. Qualifiers Quals;
  368. unsigned Alignment;
  369. /// DestructedFlag - This is set to true if some external code is
  370. /// responsible for setting up a destructor for the slot. Otherwise
  371. /// the code which constructs it should push the appropriate cleanup.
  372. bool DestructedFlag : 1;
  373. /// ObjCGCFlag - This is set to true if writing to the memory in the
  374. /// slot might require calling an appropriate Objective-C GC
  375. /// barrier. The exact interaction here is unnecessarily mysterious.
  376. bool ObjCGCFlag : 1;
  377. /// ZeroedFlag - This is set to true if the memory in the slot is
  378. /// known to be zero before the assignment into it. This means that
  379. /// zero fields don't need to be set.
  380. bool ZeroedFlag : 1;
  381. /// AliasedFlag - This is set to true if the slot might be aliased
  382. /// and it's not undefined behavior to access it through such an
  383. /// alias. Note that it's always undefined behavior to access a C++
  384. /// object that's under construction through an alias derived from
  385. /// outside the construction process.
  386. ///
  387. /// This flag controls whether calls that produce the aggregate
  388. /// value may be evaluated directly into the slot, or whether they
  389. /// must be evaluated into an unaliased temporary and then memcpy'ed
  390. /// over. Since it's invalid in general to memcpy a non-POD C++
  391. /// object, it's important that this flag never be set when
  392. /// evaluating an expression which constructs such an object.
  393. bool AliasedFlag : 1;
  394. /// This is set to true if the tail padding of this slot might overlap
  395. /// another object that may have already been initialized (and whose
  396. /// value must be preserved by this initialization). If so, we may only
  397. /// store up to the dsize of the type. Otherwise we can widen stores to
  398. /// the size of the type.
  399. bool OverlapFlag : 1;
  400. /// If is set to true, sanitizer checks are already generated for this address
  401. /// or not required. For instance, if this address represents an object
  402. /// created in 'new' expression, sanitizer checks for memory is made as a part
  403. /// of 'operator new' emission and object constructor should not generate
  404. /// them.
  405. bool SanitizerCheckedFlag : 1;
  406. public:
  407. enum IsAliased_t { IsNotAliased, IsAliased };
  408. enum IsDestructed_t { IsNotDestructed, IsDestructed };
  409. enum IsZeroed_t { IsNotZeroed, IsZeroed };
  410. enum Overlap_t { DoesNotOverlap, MayOverlap };
  411. enum NeedsGCBarriers_t { DoesNotNeedGCBarriers, NeedsGCBarriers };
  412. enum IsSanitizerChecked_t { IsNotSanitizerChecked, IsSanitizerChecked };
  413. /// ignored - Returns an aggregate value slot indicating that the
  414. /// aggregate value is being ignored.
  415. static AggValueSlot ignored() {
  416. return forAddr(Address::invalid(), Qualifiers(), IsNotDestructed,
  417. DoesNotNeedGCBarriers, IsNotAliased, DoesNotOverlap);
  418. }
  419. /// forAddr - Make a slot for an aggregate value.
  420. ///
  421. /// \param quals - The qualifiers that dictate how the slot should
  422. /// be initialied. Only 'volatile' and the Objective-C lifetime
  423. /// qualifiers matter.
  424. ///
  425. /// \param isDestructed - true if something else is responsible
  426. /// for calling destructors on this object
  427. /// \param needsGC - true if the slot is potentially located
  428. /// somewhere that ObjC GC calls should be emitted for
  429. static AggValueSlot forAddr(Address addr,
  430. Qualifiers quals,
  431. IsDestructed_t isDestructed,
  432. NeedsGCBarriers_t needsGC,
  433. IsAliased_t isAliased,
  434. Overlap_t mayOverlap,
  435. IsZeroed_t isZeroed = IsNotZeroed,
  436. IsSanitizerChecked_t isChecked = IsNotSanitizerChecked) {
  437. AggValueSlot AV;
  438. if (addr.isValid()) {
  439. AV.Addr = addr.getPointer();
  440. AV.Alignment = addr.getAlignment().getQuantity();
  441. } else {
  442. AV.Addr = nullptr;
  443. AV.Alignment = 0;
  444. }
  445. AV.Quals = quals;
  446. AV.DestructedFlag = isDestructed;
  447. AV.ObjCGCFlag = needsGC;
  448. AV.ZeroedFlag = isZeroed;
  449. AV.AliasedFlag = isAliased;
  450. AV.OverlapFlag = mayOverlap;
  451. AV.SanitizerCheckedFlag = isChecked;
  452. return AV;
  453. }
  454. static AggValueSlot forLValue(const LValue &LV,
  455. IsDestructed_t isDestructed,
  456. NeedsGCBarriers_t needsGC,
  457. IsAliased_t isAliased,
  458. Overlap_t mayOverlap,
  459. IsZeroed_t isZeroed = IsNotZeroed,
  460. IsSanitizerChecked_t isChecked = IsNotSanitizerChecked) {
  461. return forAddr(LV.getAddress(), LV.getQuals(), isDestructed, needsGC,
  462. isAliased, mayOverlap, isZeroed, isChecked);
  463. }
  464. IsDestructed_t isExternallyDestructed() const {
  465. return IsDestructed_t(DestructedFlag);
  466. }
  467. void setExternallyDestructed(bool destructed = true) {
  468. DestructedFlag = destructed;
  469. }
  470. Qualifiers getQualifiers() const { return Quals; }
  471. bool isVolatile() const {
  472. return Quals.hasVolatile();
  473. }
  474. void setVolatile(bool flag) {
  475. if (flag)
  476. Quals.addVolatile();
  477. else
  478. Quals.removeVolatile();
  479. }
  480. Qualifiers::ObjCLifetime getObjCLifetime() const {
  481. return Quals.getObjCLifetime();
  482. }
  483. NeedsGCBarriers_t requiresGCollection() const {
  484. return NeedsGCBarriers_t(ObjCGCFlag);
  485. }
  486. llvm::Value *getPointer() const {
  487. return Addr;
  488. }
  489. Address getAddress() const {
  490. return Address(Addr, getAlignment());
  491. }
  492. bool isIgnored() const {
  493. return Addr == nullptr;
  494. }
  495. CharUnits getAlignment() const {
  496. return CharUnits::fromQuantity(Alignment);
  497. }
  498. IsAliased_t isPotentiallyAliased() const {
  499. return IsAliased_t(AliasedFlag);
  500. }
  501. Overlap_t mayOverlap() const {
  502. return Overlap_t(OverlapFlag);
  503. }
  504. bool isSanitizerChecked() const {
  505. return SanitizerCheckedFlag;
  506. }
  507. RValue asRValue() const {
  508. if (isIgnored()) {
  509. return RValue::getIgnored();
  510. } else {
  511. return RValue::getAggregate(getAddress(), isVolatile());
  512. }
  513. }
  514. void setZeroed(bool V = true) { ZeroedFlag = V; }
  515. IsZeroed_t isZeroed() const {
  516. return IsZeroed_t(ZeroedFlag);
  517. }
  518. /// Get the preferred size to use when storing a value to this slot. This
  519. /// is the type size unless that might overlap another object, in which
  520. /// case it's the dsize.
  521. CharUnits getPreferredSize(ASTContext &Ctx, QualType Type) const {
  522. return mayOverlap() ? Ctx.getTypeInfoDataSizeInChars(Type).first
  523. : Ctx.getTypeSizeInChars(Type);
  524. }
  525. };
  526. } // end namespace CodeGen
  527. } // end namespace clang
  528. #endif