@@ -2934,8 +2934,9 @@ bool Compiler<Emitter>::VisitMaterializeTemporaryExpr(
29342934 // For everyhing else, use local variables.
29352935 if (SubExprT) {
29362936 bool IsConst = SubExpr->getType ().isConstQualified ();
2937- unsigned LocalIndex =
2938- allocateLocalPrimitive (E, *SubExprT, IsConst, E->getExtendingDecl ());
2937+ bool IsVolatile = SubExpr->getType ().isVolatileQualified ();
2938+ unsigned LocalIndex = allocateLocalPrimitive (
2939+ E, *SubExprT, IsConst, IsVolatile, E->getExtendingDecl ());
29392940 if (!this ->visit (SubExpr))
29402941 return false ;
29412942 if (!this ->emitSetLocal (*SubExprT, LocalIndex, E))
@@ -4452,6 +4453,9 @@ bool Compiler<Emitter>::visitAssignment(const Expr *LHS, const Expr *RHS,
44524453 if (!this ->visit (LHS))
44534454 return false ;
44544455
4456+ if (LHS->getType ().isVolatileQualified ())
4457+ return this ->emitInvalidStore (LHS->getType ().getTypePtr (), E);
4458+
44554459 // We don't support assignments in C.
44564460 if (!Ctx.getLangOpts ().CPlusPlus && !this ->emitInvalid (E))
44574461 return false ;
@@ -4560,13 +4564,14 @@ bool Compiler<Emitter>::emitConst(const APSInt &Value, const Expr *E) {
45604564
45614565template <class Emitter >
45624566unsigned Compiler<Emitter>::allocateLocalPrimitive(
4563- DeclTy &&Src, PrimType Ty, bool IsConst, const ValueDecl *ExtendingDecl ,
4564- ScopeKind SC, bool IsConstexprUnknown) {
4567+ DeclTy &&Src, PrimType Ty, bool IsConst, bool IsVolatile ,
4568+ const ValueDecl *ExtendingDecl, ScopeKind SC, bool IsConstexprUnknown) {
45654569 // FIXME: There are cases where Src.is<Expr*>() is wrong, e.g.
45664570 // (int){12} in C. Consider using Expr::isTemporaryObject() instead
45674571 // or isa<MaterializeTemporaryExpr>().
45684572 Descriptor *D = P.createDescriptor (Src, Ty, nullptr , Descriptor::InlineDescMD,
4569- IsConst, isa<const Expr *>(Src));
4573+ IsConst, isa<const Expr *>(Src),
4574+ /* IsMutable=*/ false , IsVolatile);
45704575 D->IsConstexprUnknown = IsConstexprUnknown;
45714576 Scope::Local Local = this ->createLocal (D);
45724577 if (auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast <const Decl *>()))
@@ -4874,7 +4879,8 @@ Compiler<Emitter>::visitVarDecl(const VarDecl *VD, const Expr *Init,
48744879
48754880 if (VarT) {
48764881 unsigned Offset = this ->allocateLocalPrimitive (
4877- VD, *VarT, VD->getType ().isConstQualified (), nullptr , ScopeKind::Block,
4882+ VD, *VarT, VD->getType ().isConstQualified (),
4883+ VD->getType ().isVolatileQualified (), nullptr , ScopeKind::Block,
48784884 IsConstexprUnknown);
48794885 if (Init) {
48804886 // If this is a toplevel declaration, create a scope for the
0 commit comments