summaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/Program.cpp
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2024-09-17 15:21:28 +0200
committerGitHub <noreply@github.com>2024-09-17 15:21:28 +0200
commit8e2dbab24276a8521d241463b4161c78bc4d39d2 (patch)
treef6c3e14cd429a6fb365c73bd9acf46bce9a7bf2c /clang/lib/AST/ByteCode/Program.cpp
parent5fdf07dda697a7752aad64ba93d4c38de21f8d3b (diff)
[clang][bytecode] Fix defining extern variables (#108940)
At the point of defintion of the variable, a function might already refert to the variable by its index. Replace the index with the new one.
Diffstat (limited to 'clang/lib/AST/ByteCode/Program.cpp')
-rw-r--r--clang/lib/AST/ByteCode/Program.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp
index bd5860beabae..79c645257306 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -204,9 +204,18 @@ std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
IsStatic = false;
IsExtern = true;
}
+
+ // Register all previous declarations as well. For extern blocks, just replace
+ // the index with the new variable.
if (auto Idx = createGlobal(VD, VD->getType(), IsStatic, IsExtern, Init)) {
- for (const Decl *P = VD; P; P = P->getPreviousDecl())
+ for (const Decl *P = VD; P; P = P->getPreviousDecl()) {
+ if (P != VD) {
+ unsigned PIdx = GlobalIndices[P];
+ if (Globals[PIdx]->block()->isExtern())
+ Globals[PIdx] = Globals[*Idx];
+ }
GlobalIndices[P] = *Idx;
+ }
return *Idx;
}
return std::nullopt;