//
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
+ GlobalVariable *GV = cast<GlobalVariable>(VMap[&*I]);
+
+ SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
+ I->getAllMetadata(MDs);
+ for (auto MD : MDs)
+ GV->addMetadata(MD.first,
+ *MapMetadata(MD.second, VMap, RF_MoveDistinctMDs));
+
if (I->isDeclaration())
continue;
- GlobalVariable *GV = cast<GlobalVariable>(VMap[&*I]);
if (!ShouldCloneDefinition(&*I)) {
// Skip after setting the correct linkage for an external reference.
GV->setLinkage(GlobalValue::ExternalLinkage);
if (I->hasInitializer())
GV->setInitializer(MapValue(I->getInitializer(), VMap));
- SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
- I->getAllMetadata(MDs);
- for (auto MD : MDs)
- GV->addMetadata(MD.first,
- *MapMetadata(MD.second, VMap, RF_MoveDistinctMDs));
-
copyComdat(GV, &*I);
}
--- /dev/null
+; RUN: opt -run-twice -verify -S -o - %s | FileCheck %s
+
+; This test is used to check metadata attached to global variable declarations
+; are copied when CloneModule(). This is required by out-of-tree passes.
+
+; CHECK: @g = external addrspace(64) global i32, !spirv.InOut !0
+
+@g = external addrspace(64) global i32, !spirv.InOut !0
+
+!0 = !{i32 1}