From 211b51e4713d814d6fa894f4fc309a364c5642ce Mon Sep 17 00:00:00 2001 From: Timm Baeder Date: Fri, 25 Apr 2025 11:23:34 +0200 Subject: [clang][bytecode] Propagate IsVolatile bit to subobjects (#137293) For ```c++ struct S { constexpr S(int=0) : i(1) {} int i; }; constexpr volatile S vs; ``` reading from `vs.i` is not allowed, even though `i` is not volatile qualified. Propagate the IsVolatile bit down the hierarchy, so we know reading from `vs.i` is a volatile read. --- clang/lib/AST/ByteCode/Compiler.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'clang/lib/AST/ByteCode/Compiler.cpp') diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 65d87cd..3c774c1 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -364,8 +364,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) { Desc = P.createDescriptor(SubExpr, *T); else Desc = P.createDescriptor(SubExpr, PointeeType.getTypePtr(), - std::nullopt, true, false, - /*IsMutable=*/false, nullptr); + std::nullopt, /*IsConst=*/true); } uint64_t Val = Ctx.getASTContext().getTargetNullPointerValue(CE->getType()); @@ -417,8 +416,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) { Desc = nullptr; else Desc = P.createDescriptor(CE, PtrType->getPointeeType().getTypePtr(), - Descriptor::InlineDescMD, true, false, - /*IsMutable=*/false, nullptr); + Descriptor::InlineDescMD, /*IsConst=*/true); if (!this->emitGetIntPtr(T, Desc, CE)) return false; @@ -3400,14 +3398,13 @@ bool Compiler::VisitCXXNewExpr(const CXXNewExpr *E) { Desc = nullptr; // We're not going to use it in this case. else Desc = P.createDescriptor(E, *ElemT, /*SourceTy=*/nullptr, - Descriptor::InlineDescMD, - /*IsConst=*/false, /*IsTemporary=*/false, - /*IsMutable=*/false); + Descriptor::InlineDescMD); } else { Desc = P.createDescriptor( E, ElementType.getTypePtr(), E->isArray() ? std::nullopt : Descriptor::InlineDescMD, - /*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false, Init); + /*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false, + /*IsVolatile=*/false, Init); } } @@ -4355,7 +4352,7 @@ Compiler::allocateLocal(DeclTy &&Src, QualType Ty, Descriptor *D = P.createDescriptor( Src, Ty.getTypePtr(), Descriptor::InlineDescMD, Ty.isConstQualified(), - IsTemporary, /*IsMutable=*/false, Init); + IsTemporary, /*IsMutable=*/false, /*IsVolatile=*/false, Init); if (!D) return std::nullopt; D->IsConstexprUnknown = IsConstexprUnknown; @@ -4377,7 +4374,7 @@ std::optional Compiler::allocateTemporary(const Expr *E) { Descriptor *D = P.createDescriptor( E, Ty.getTypePtr(), Descriptor::InlineDescMD, Ty.isConstQualified(), - /*IsTemporary=*/true, /*IsMutable=*/false, /*Init=*/nullptr); + /*IsTemporary=*/true); if (!D) return std::nullopt; -- cgit v1.1