diff options
Diffstat (limited to 'clang/lib/AST/Interp/Program.cpp')
| -rw-r--r-- | clang/lib/AST/Interp/Program.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/clang/lib/AST/Interp/Program.cpp b/clang/lib/AST/Interp/Program.cpp index c1697bb7fa6d..52e13398163e 100644 --- a/clang/lib/AST/Interp/Program.cpp +++ b/clang/lib/AST/Interp/Program.cpp @@ -138,32 +138,35 @@ std::optional<unsigned> Program::getOrCreateGlobal(const ValueDecl *VD, return std::nullopt; } -std::optional<unsigned> Program::getOrCreateDummy(const ParmVarDecl *PD) { - +std::optional<unsigned> Program::getOrCreateDummy(const ValueDecl *VD) { // Dedup blocks since they are immutable and pointers cannot be compared. - if (auto It = DummyParams.find(PD); - It != DummyParams.end()) + if (auto It = DummyParams.find(VD); It != DummyParams.end()) return It->second; - auto &ASTCtx = Ctx.getASTContext(); - // Create a pointer to an incomplete array of the specified elements. - QualType ElemTy = PD->getType()->castAs<PointerType>()->getPointeeType(); - QualType Ty = ASTCtx.getIncompleteArrayType(ElemTy, ArrayType::Normal, 0); + // Create dummy descriptor. + Descriptor *Desc = allocateDescriptor(VD, std::nullopt); + // Allocate a block for storage. + unsigned I = Globals.size(); - if (auto Idx = createGlobal(PD, Ty, /*isStatic=*/true, /*isExtern=*/true)) { - DummyParams[PD] = *Idx; - return Idx; - } - return std::nullopt; + auto *G = new (Allocator, Desc->getAllocSize()) + Global(getCurrentDecl(), Desc, /*IsStatic=*/true, /*IsExtern=*/false); + G->block()->invokeCtor(); + + Globals.push_back(G); + DummyParams[VD] = I; + return I; } std::optional<unsigned> Program::createGlobal(const ValueDecl *VD, const Expr *Init) { assert(!getGlobal(VD)); bool IsStatic, IsExtern; - if (auto *Var = dyn_cast<VarDecl>(VD)) { + if (const auto *Var = dyn_cast<VarDecl>(VD)) { IsStatic = Context::shouldBeGloballyIndexed(VD); IsExtern = !Var->getAnyInitializer(); + } else if (isa<UnnamedGlobalConstantDecl>(VD)) { + IsStatic = true; + IsExtern = false; } else { IsStatic = false; IsExtern = true; |
