@@ -152,10 +152,12 @@ std::optional<unsigned> Program::getOrCreateDummy(const DeclTy &D) {
152152 return It->second ;
153153
154154 QualType QT;
155+ bool IsWeak = false ;
155156 if (const auto *E = D.dyn_cast <const Expr *>()) {
156157 QT = E->getType ();
157158 } else {
158159 const ValueDecl *VD = cast<ValueDecl>(D.get <const Decl *>());
160+ IsWeak = VD->isWeak ();
159161 QT = VD->getType ();
160162 if (const auto *RT = QT->getAs <ReferenceType>())
161163 QT = RT->getPointeeType ();
@@ -182,7 +184,7 @@ std::optional<unsigned> Program::getOrCreateDummy(const DeclTy &D) {
182184
183185 auto *G = new (Allocator, Desc->getAllocSize ())
184186 Global (Ctx.getEvalID (), getCurrentDecl (), Desc, /* IsStatic=*/ true ,
185- /* IsExtern=*/ false );
187+ /* IsExtern=*/ false , IsWeak );
186188 G->block ()->invokeCtor ();
187189
188190 Globals.push_back (G);
@@ -193,6 +195,7 @@ std::optional<unsigned> Program::getOrCreateDummy(const DeclTy &D) {
193195std::optional<unsigned > Program::createGlobal (const ValueDecl *VD,
194196 const Expr *Init) {
195197 bool IsStatic, IsExtern;
198+ bool IsWeak = VD->isWeak ();
196199 if (const auto *Var = dyn_cast<VarDecl>(VD)) {
197200 IsStatic = Context::shouldBeGloballyIndexed (VD);
198201 IsExtern = Var->hasExternalStorage ();
@@ -207,7 +210,8 @@ std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
207210
208211 // Register all previous declarations as well. For extern blocks, just replace
209212 // the index with the new variable.
210- if (auto Idx = createGlobal (VD, VD->getType (), IsStatic, IsExtern, Init)) {
213+ if (auto Idx =
214+ createGlobal (VD, VD->getType (), IsStatic, IsExtern, IsWeak, Init)) {
211215 for (const Decl *P = VD; P; P = P->getPreviousDecl ()) {
212216 if (P != VD) {
213217 unsigned PIdx = GlobalIndices[P];
@@ -225,7 +229,7 @@ std::optional<unsigned> Program::createGlobal(const Expr *E) {
225229 if (auto Idx = getGlobal (E))
226230 return Idx;
227231 if (auto Idx = createGlobal (E, E->getType (), /* isStatic=*/ true ,
228- /* isExtern=*/ false )) {
232+ /* isExtern=*/ false , /* IsWeak= */ false )) {
229233 GlobalIndices[E] = *Idx;
230234 return *Idx;
231235 }
@@ -234,7 +238,7 @@ std::optional<unsigned> Program::createGlobal(const Expr *E) {
234238
235239std::optional<unsigned > Program::createGlobal (const DeclTy &D, QualType Ty,
236240 bool IsStatic, bool IsExtern,
237- const Expr *Init) {
241+ bool IsWeak, const Expr *Init) {
238242 // Create a descriptor for the global.
239243 Descriptor *Desc;
240244 const bool IsConst = Ty.isConstQualified ();
@@ -251,8 +255,8 @@ std::optional<unsigned> Program::createGlobal(const DeclTy &D, QualType Ty,
251255 // Allocate a block for storage.
252256 unsigned I = Globals.size ();
253257
254- auto *G = new (Allocator, Desc->getAllocSize ())
255- Global ( Ctx.getEvalID (), getCurrentDecl (), Desc, IsStatic, IsExtern);
258+ auto *G = new (Allocator, Desc->getAllocSize ()) Global (
259+ Ctx.getEvalID (), getCurrentDecl (), Desc, IsStatic, IsExtern, IsWeak );
256260 G->block ()->invokeCtor ();
257261
258262 // Initialize InlineDescriptor fields.
0 commit comments