aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/Interp/Program.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/AST/Interp/Program.cpp')
-rw-r--r--clang/lib/AST/Interp/Program.cpp31
1 files changed, 15 insertions, 16 deletions
diff --git a/clang/lib/AST/Interp/Program.cpp b/clang/lib/AST/Interp/Program.cpp
index 5305ddd8de18..c1697bb7fa6d 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -10,6 +10,7 @@
#include "ByteCodeStmtGen.h"
#include "Context.h"
#include "Function.h"
+#include "Integral.h"
#include "Opcode.h"
#include "PrimType.h"
#include "clang/AST/Decl.h"
@@ -119,7 +120,7 @@ std::optional<unsigned> Program::getGlobal(const ValueDecl *VD) {
// Map the decl to the existing index.
if (Index) {
GlobalIndices[VD] = *Index;
- return {};
+ return std::nullopt;
}
return Index;
@@ -134,26 +135,26 @@ std::optional<unsigned> Program::getOrCreateGlobal(const ValueDecl *VD,
GlobalIndices[VD] = *Idx;
return Idx;
}
- return {};
+ return std::nullopt;
}
std::optional<unsigned> Program::getOrCreateDummy(const ParmVarDecl *PD) {
- auto &ASTCtx = Ctx.getASTContext();
+ // Dedup blocks since they are immutable and pointers cannot be compared.
+ if (auto It = DummyParams.find(PD);
+ 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);
- // Dedup blocks since they are immutable and pointers cannot be compared.
- auto It = DummyParams.find(PD);
- if (It != DummyParams.end())
- return It->second;
-
if (auto Idx = createGlobal(PD, Ty, /*isStatic=*/true, /*isExtern=*/true)) {
DummyParams[PD] = *Idx;
return Idx;
}
- return {};
+ return std::nullopt;
}
std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
@@ -161,7 +162,7 @@ std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
assert(!getGlobal(VD));
bool IsStatic, IsExtern;
if (auto *Var = dyn_cast<VarDecl>(VD)) {
- IsStatic = !Var->hasLocalStorage();
+ IsStatic = Context::shouldBeGloballyIndexed(VD);
IsExtern = !Var->getAnyInitializer();
} else {
IsStatic = false;
@@ -172,7 +173,7 @@ std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
GlobalIndices[P] = *Idx;
return *Idx;
}
- return {};
+ return std::nullopt;
}
std::optional<unsigned> Program::createGlobal(const Expr *E) {
@@ -193,7 +194,7 @@ std::optional<unsigned> Program::createGlobal(const DeclTy &D, QualType Ty,
IsTemporary);
}
if (!Desc)
- return {};
+ return std::nullopt;
// Allocate a block for storage.
unsigned I = Globals.size();
@@ -221,10 +222,8 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
return nullptr;
// Deduplicate records.
- auto It = Records.find(RD);
- if (It != Records.end()) {
+ if (auto It = Records.find(RD); It != Records.end())
return It->second;
- }
// We insert nullptr now and replace that later, so recursive calls
// to this function with the same RecordDecl don't run into
@@ -340,7 +339,7 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
D, ElemTy.getTypePtr(), std::nullopt, IsConst, IsTemporary);
if (!ElemDesc)
return nullptr;
- InterpSize ElemSize =
+ unsigned ElemSize =
ElemDesc->getAllocSize() + sizeof(InlineDescriptor);
if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
return {};